为了在保证支付安全的前提下,带给商户简单、一致且易用的开发体验,我们推出了全新的微信支付APIv3接口。该版本API的具体规则请参考“APIv3接口规则”
文档展示了如何使用微信支付服务端 SDK 快速接入扫码支付产品,完成与微信支付对接的部分。
• 文档中的代码示例是用来阐述 API 基本使用方法,代码中的示例参数需替换成商户自己账号及请求参数才能跑通。
• 以下接入步骤仅提供参考,请商户结合自身业务需求进行评估、修改。
步骤说明:该接口允许商户请求微信支付对用户支付用户的实名信息与入参中的身份信息进行一致性校验,商户可以根据校验结果使用正确的信息进行报关。
敏感信息字段:certificate_id 和 certificate_name 为用户敏感信息,为避免被中间人截获,保护用户隐私,需要按照 微信支付APIv3 加密后传输。
• 下载微信支付平台证书,获取证书序列号与证书公钥。
• 在 HTTP header 中添加微信支付平台证书序列号,Wechatpay-Serial :${微信支付平台证书序列号}。
• 使用微信支付平台证书公钥对敏感字段进行RSA加密,填充方案选择 RSAES-PKCS1-v1_5。
• 对密文进行 base64 编码后即可得到最终内容。
代码示例
//Id info verification API
public void idVerification() throws IOException {
String verifyIdInfoBody = """{
"appid": "wxd678efh567hg6787",
"mchid": "1230000109",
"out_trade_no": "20150806125346",
"transaction_id": "1000320306201511078440737890",
"sub_order_no": "20150806125346",
"customs": "SHANGHAI_ZS",
"merchant_customs_no": "123456",
"certificate_type": "IDCARD",
"certificate_id": "HHp24MagiQ6i7c5yIow5cJP5x2cGsAA8hi5yIow5cJP5x", // sensitive field, encryption content
"certificate_name": "HHp24MagiQ6i7c5yIow/9ZTk5Zt5cJP5x2cGsAA8hif07fRdb2" //sensitive field,encryption content
}""";
HttpPost httpPost = new HttpPost("https://apihk.mch.weixin.qq.com/v3/global/customs/verify-certificate");
httpPost.addHeader("Accept", "application/json");
httpPost.addHeader("Content-type", "application/json; charset=utf-8");
httpPost.addHeader("Wechatpay-Serial", "0798ABFDCBXXXXXXXXXXXXXXXXXXXXXXX054A761");
httpPost.setEntity(new StringEntity(verifyIdInfoBody));
CloseableHttpResponse response = httpClient.execute(httpPost);
//Process the response
}
其他重要参数请前往身份信息校验API文档页面参考。
步骤说明:商户通过该接口请求微信支付向海关推送支付单的报关信息。微信支付在收到报关附加信息后,会异步向海关进行支付单申报信息推送。
代码示例
//Customs Declaration API
public void customsDeclaration() throws IOException {
String customsDeclarationBody= """{
"appid": "wxd678efh567hg6787",
"mchid": "1230000109",
"out_trade_no": "20150806125346",
"transaction_id": "1000320306201511078440737890",
"customs": "SHANGHAI_ZS",
"merchant_customs_no": "123456",
"duty": 888,
"sub_order_no": "20150806125346",
"fee_type": "CNY",
"order_fee": 888,
"transport_fee": 888,
"product_fee": 888
}""";
HttpPost httpPost = new HttpPost("https://apihk.mch.weixin.qq.com/v3/global/customs/orders");
httpPost.addHeader("Accept", "application/json");
httpPost.addHeader("Content-type", "application/json; charset=utf-8");
httpPost.setEntity(new StringEntity(customsDeclarationBody));
CloseableHttpResponse response = httpClient.execute(httpPost);
//Process the response
}
其他重要参数请前往报关API文档页面参考。
步骤说明:当商户错误传了报关信息的部分字段时,可调用该接口对报关信息进行修改。该接口只能修改如下5个字段:merchant_customs_no、duty、order_fee、transport_fee、product_fee
代码示例
//Modify Customs Declaration API
public void modifyCustomsDeclarartionTest() throws IOException {
String modifyCustomsDeclarationBody = """
{
"appid": "wxd678efh567hg6787",
"mchid": "1230000109",
"out_trade_no": "20150806125346",
"transaction_id": "1000320306201511078440737890",
"sub_order_no": "20150806125346",
"customs": "SHANGHAI_ZS",
"merchant_customs_no": "123456",
"duty": 888,
"order_fee": 888,
"transport_fee": 888,
"product_fee": 888
}
""";
HttpPatch httpPatch = new HttpPatch("https://apihk.mch.weixin.qq.com/v3/global/customs/orders");
httpPatch.addHeader("Accept", "application/json");
httpPatch.addHeader("Content-type", "application/json; charset=utf-8");
httpPatch.setEntity(new StringEntity(modifyCustomsDeclarationBody));
CloseableHttpResponse response = httpClient.execute(httpPatch);
//Process the response
}
其他重要参数请前往报关信息修改API文档页面参考。
步骤说明:商户可通过该接口查询之前提交的报关附加信息,以及海关报关状态。
代码示例
//Query Customs Declaration API
public void queryCustomsDeclarationTest() throws IOException {
HttpGet httpGet = new HttpGet("https://apihk.mch.weixin.qq.com/v3/global/customs/orders?appid=wxd678efh567hg6787&mchid=mchid&order_type=transaction_id&order_no=1000320306201511078440737890&customs=SHANGHAI_ZS&offset=1&limit=20");
httpGet.addHeader("Accept", "application/json");
httpGet.addHeader("Content-type", "application/json; charset=utf-8");
CloseableHttpResponse response = httpClient.execute(httpGet);
//Process the response
}
其他重要参数请前往报关查询API文档页面参考。
步骤说明:当订单已申报且海关要求商户重新推送报关信息时,商户可通过该接口将报关信息再次发往海关。
代码示例
//Repush Customs Declaration API
public void repushCustomsDeclarartionTest() throws IOException {
String repushBody = """
{
"appid": "wxd678efh567hg6787",
"mchid": "1230000109",
"out_trade_no": "20150806125346",
"transaction_id": "1000320306201511078440737890",
"sub_order_no": "20150806125346",
"sub_order_id": "1000320306201511078440737891",
"customs": "SHANGHAI_ZS",
"merchant_customs_no": "123456"
}
""";
HttpPost httpPost = new HttpPost("https://apihk.mch.weixin.qq.com/v3/global/customs/redeclare");
httpPost.addHeader("Accept", "application/json");
httpPost.addHeader("Content-type", "application/json; charset=utf-8");
httpPost.setEntity(new StringEntity(repushBody));
CloseableHttpResponse response = httpClient.execute(httpPost);
//Process the response
}
其他重要参数请前往报关查询API文档页面参考。
Customer Service Tel
Business Development
9:00-18:00
Monday-Friday GMT+8
Technical Support
WeChat Pay Global
ICP证