為了在保證支付安全的前提下,帶給商戶簡(jiǎn)單、一致且易用的開發(fā)體驗(yàn),我們推出了全新的微信支付APIv3接口。該版本API的具體規(guī)則請(qǐng)參考“APIv3接口規(guī)則”
為了幫助開發(fā)者調(diào)用開放接口,我們提供了Java、PHP、GO語言版本的開發(fā)庫(kù),封裝了簽名生成、簽名驗(yàn)證、敏感信息加/解密、媒體文件上傳等基礎(chǔ)功能
文檔展示了如何使用微信支付服務(wù)端 SDK 快速接入掃碼支付產(chǎn)品,完成與微信支付對(duì)接的部分。
? 文檔中的代碼示例是用來闡述 API 基本使用方法,代碼中的示例參數(shù)需替換成商戶自己賬號(hào)及請(qǐng)求參數(shù)才能跑通。
? 以下接入步驟僅提供參考,請(qǐng)商戶結(jié)合自身業(yè)務(wù)需求進(jìn)行評(píng)估、修改。
步驟說明:該接口允許商戶請(qǐng)求微信支付對(duì)用戶支付用戶的實(shí)名信息與入?yún)⒅械纳矸菪畔⑦M(jìn)行一致性校驗(yàn),商戶可以根據(jù)校驗(yàn)結(jié)果使用正確的信息進(jìn)行報(bào)關(guān)。
敏感信息字段:certificate_id 和 certificate_name 為用戶敏感信息,為避免被中間人截獲,保護(hù)用戶隱私,需要按照 微信支付APIv3 加密后傳輸。
? 下載微信支付平臺(tái)證書,獲取證書序列號(hào)與證書公鑰。
? 在 HTTP header 中添加微信支付平臺(tái)證書序列號(hào),Wechatpay-Serial :${微信支付平臺(tái)證書序列號(hào)}。
? 使用微信支付平臺(tái)證書公鑰對(duì)敏感字段進(jìn)行RSA加密,填充方案選擇 RSAES-PKCS1-v1_5。
? 對(duì)密文進(jìn)行 base64 編碼后即可得到最終內(nèi)容。
代碼示例
//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
}
其他重要參數(shù)請(qǐng)前往身份信息校驗(yàn)API文檔頁面參考。
步驟說明:商戶通過該接口請(qǐng)求微信支付向海關(guān)推送支付單的報(bào)關(guān)信息。微信支付在收到報(bào)關(guān)附加信息后,會(huì)異步向海關(guān)進(jìn)行支付單申報(bào)信息推送。
代碼示例
//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
}
其他重要參數(shù)請(qǐng)前往報(bào)關(guān)API文檔頁面參考。
步驟說明:當(dāng)商戶錯(cuò)誤傳了報(bào)關(guān)信息的部分字段時(shí),可調(diào)用該接口對(duì)報(bào)關(guān)信息進(jìn)行修改。該接口只能修改如下5個(gè)字段: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
}
其他重要參數(shù)請(qǐng)前往報(bào)關(guān)信息修改API文檔頁面參考。
步驟說明:商戶可通過該接口查詢之前提交的報(bào)關(guān)附加信息,以及海關(guān)報(bào)關(guān)狀態(tài)。
代碼示例
//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
}
其他重要參數(shù)請(qǐng)前往報(bào)關(guān)查詢API文檔頁面參考。
步驟說明:當(dāng)訂單已申報(bào)且海關(guān)要求商戶重新推送報(bào)關(guān)信息時(shí),商戶可通過該接口將報(bào)關(guān)信息再次發(fā)往海關(guān)。
代碼示例
//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
}
其他重要參數(shù)請(qǐng)前往報(bào)關(guān)查詢API文檔頁面參考。
Customer Service Tel
Business Development
9:00-18:00
Monday-Friday GMT+8
Technical Support
WeChat Pay Global
ICP證