查询二级商户余额
这里的特殊情况下商家可以在微信支付平台直接申请提现,我自己测试的小微商户并没有发现可以提现的地方,不过可以修改结算银行卡信息。
测试类代码:
/**
* 查询账户实时余额
*/
@Test
public void queryBalance() {
String param = WxPayConfig.testMerchantId;
Map<String, String> headersMap = WxPayUtils.getHeaderMap("GET", WxPayConfig.fund_balance_ecommerce_query_url + param, "");
ResponseAndStatusAndHeaders response = ClientUtil.getAndPostJson("GET", WxPayConfig.fund_balance_ecommerce_query_url + param, null, headersMap);
if (response.getStatus() != Status.SUCCESS || response.getResponseData() == null) {
LogUtil.printErrorLog(LogUtil.log_front_wxpay + "查询账户实时余额请求错误,返回信息为:\n" + response.toString() + "\n请求的参数为:\n" + param + "\n\n");
return;
}
LogUtil.printInfoLog(LogUtil.log_front_wxpay + "查询账户实时余额请求成功,返回信息为:\n" + response.toString() + "\n请求的参数为:\n" + param + "\n\n");
/*{
"available_amount": 119,
"pending_amount": 10,
"sub_mchid": "1595728911"
}*/
}
二级商户余额提现
提现流程图:
- 提现微信不收取手续费,全额到账。
- 提现会在第二天到账银行卡中。
测试类代码:
/**
* 商户余额提现
*/
@Test
public void mchWithdraw() {
JSONObject reqJsonObject = new JSONObject();
//二级商户号
reqJsonObject.put("sub_mchid", WxPayConfig.testMerchantIdHht);
//平台提现订单号(字母数字)
reqJsonObject.put("out_request_no", "20200527584262");
//提现金额
reqJsonObject.put("amount", 10);
Map<String, String> headersMap = WxPayUtils.getHeaderMap("POST", WxPayConfig.fund_withdraw_ecommerce_url, reqJsonObject.toJSONString());
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqJsonObject.toJSONString());
ResponseAndStatusAndHeaders response = ClientUtil.getAndPostJson("POST", WxPayConfig.fund_withdraw_ecommerce_url, requestBody, headersMap);
if (response.getStatus() != Status.SUCCESS || response.getResponseData() == null) {
LogUtil.printErrorLog(LogUtil.log_front_wxpay + "请求二级商户提现接口错误,返回信息为:\n" + response.toString() + "\n请求的参数为:\n" + reqJsonObject + "\n\n");
return;
}
LogUtil.printInfoLog(LogUtil.log_front_wxpay + "请求二级商户提现接口成功,返回信息为:\n" + response.toString() + "\n请求的参数为:\n" + reqJsonObject + "\n\n");
JSONObject jsonObject = JSON.parseObject(response.getResponseData().toString());
/*{
"out_request_no": "20200527584262",
"sub_mchid": "1595728911",
"withdraw_id": "209000120887412202005281822192220"
}*/
String withdraw_id = jsonObject.getString("withdraw_id");
System.out.println("提现成功,微信支付提现订单号为:" + withdraw_id);
}
查询二级商户提现单
- 只支持查询90天内的提现订单
- 两种查询方式(微信支付提现单号和商户提现单号查询),两种查询方式返回结果一致。
测试类代码:
/**
* 查询提现状态接口(仅支持90天内)
*/
@Test
public void queryWithdraw() {
String param = "2005282315530253" + "?sub_mchid=" + WxPayConfig.testMerchantId;
Map<String, String> headersMap = WxPayUtils.getHeaderMap("GET", WxPayConfig.fund_withdraw_ecommerce_query_url + param, "");
ResponseAndStatusAndHeaders response = ClientUtil.getAndPostJson("GET", WxPayConfig.fund_withdraw_ecommerce_query_url + param, null, headersMap);
if (response.getStatus() != Status.SUCCESS || response.getResponseData() == null) {
LogUtil.printErrorLog(LogUtil.log_front_wxpay + "查询提现状态接口请求错误,返回信息为:\n" + response.toString() + "\n请求的参数为:\n" + param + "\n\n");
return;
}
LogUtil.printInfoLog(LogUtil.log_front_wxpay + "查询提现状态接口请求成功,返回信息为:\n" + response.toString() + "\n请求的参数为:\n" + param + "\n\n");
JSONObject jsonObject = JSON.parseObject(response.getResponseData().toString());
/*{
"amount": 10,
"bank_memo": "",
"create_time": "2020-05-28T16:19:55+08:00",
"out_request_no": "20200527584262",
"reason": "",
"remark": "",
"sp_mchid": "1586786671",
"status": "CREATE_SUCCESS",
"sub_mchid": "1595728911",
"update_time": "2020-05-28T16:19:55+08:00",
"withdraw_id": "209000120887412202005281822192220"
}*/
/*提现状态,枚举值:
CREATE_SUCCESS:受理成功
SUCCESS:提现成功
FAIL:提现失败
REFUND:提现退票
CLOSE:关单*/
String status = jsonObject.get("status").toString();
//更新时间
Timestamp timestamp = DateUtil.stringToTimestampByFormatStr(jsonObject.get("update_time").toString(), DateUtil.dateFormat18);
//失败原因
String reason = jsonObject.get("reason").toString();
System.out.println("提现单状态为:" + status);
}
参考链接
微信电商收付通-余额提现API文档:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/fund/chapter3_2.shtml
微信电商收付通-余额查询API文档:
https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/amount/chapter3_1.shtml