1、微信文档
https://pay.weixin.qq.com/doc/v3/merchant/4012716437
2、接口说明
- 支持商户:
【普通商户】 - 请求方式:
【GET】/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/{out_bill_no} - 请求域名:
【主域名】https://api.mch.weixin.qq.com
3、接口注意
- API只支持查询最近30天内的转账单,超过30天可以通过资金账单对账确认。
- 转账单中涉及金额的字段单位为“分”。
- 如果遇到新的错误码,请务必不要换单重试,请联系客服确认转账情况。如果有新的错误码,会更新到此API文档中。
- 错误码描述字段message只供人工定位问题时做参考,系统实现时请不要依赖这个字段来做自动化处理。
- 接口限频: 单个商户 100 QPS,如果超过频率限制,会报错 FREQUENCY_LIMITED,请降低频率请求。
4、代码实现
import com.alibaba.fastjson.JSONObject;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.exception.ServiceException;
import com.wechat.pay.java.core.http.*;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
@Slf4j
public class WxPayUtils {
/**
* 商户单号查询转账单
*
* @param outBillNo 商户单号
*/
public void queryTransferBills(String outBillNo) {
OkHttpClient okHttpClient = new OkHttpClient();
HttpClient httpClient = new DefaultHttpClientBuilder()
.config(rsaAutoCertificateConfig())
.okHttpClient(okHttpClient)
.build();
HttpHeaders headers = new HttpHeaders();
headers.addHeader("Accept", MediaType.APPLICATION_JSON.getValue());
HttpRequest executeSendGetHttpRequest = new HttpRequest.Builder()
.httpMethod(HttpMethod.GET)
.url("https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/" + outBillNo)
.headers(headers)
.build();
try {
HttpResponse<JSONObject> execute = httpClient.execute(executeSendGetHttpRequest, JSONObject.class);
JSONObject responseBody = execute.getServiceResponse();
log.info("商户单号查询转账单返回::{}", responseBody.toJSONString());
} catch (ServiceException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* API安全加密配置
*/
private RSAAutoCertificateConfig rsaAutoCertificateConfig() {
return new RSAAutoCertificateConfig.Builder()
// 商户号
.merchantId("xxxxxxxxxxx")
// 商户API证书私钥的存放路径
.privateKeyFromPath("v3/apiclient_key.pem")
// 商户API证书序列号
.merchantSerialNumber("xxxxxxxxxxx")
// APIv3密钥
.apiV3Key("xxxxxxxxxxx")
.build();
}
}
请求响应得到:
{
"body": {
"mch_id": "1900001109",
"out_bill_no": "plfk2020042013",
"transfer_bill_no": "1330000071100999991182020050700019480001",
"appid": "wxf636efh567hg4356",
"state": "ACCEPTED",
"transfer_amount": 400000,
"transfer_remark": "2020年4月报销",
"fail_reason": "PAYEE_ACCOUNT_ABNORMAL",
"openid": "o-MYE42l80oelYMDE34nYD456Xoy",
"user_name": "757b340b45ebef5467rter35gf464344v3542sdf4t6re4tb4f54ty45t4yyry45",
"create_time": "2015-05-20T13:29:35.120+08:00",
"update_time": "2015-05-20T13:29:35.120+08:00"
}
}
如您在阅读中发现不足,欢迎留言!!!