Login expired. Please log in again.

Feedback

0/300

Feedback

Submitted successfully

ok

Feedback

Network exception, please try again later

ok

开发指引

1. 接口规则

为了在保证支付安全的前提下,带给商户简单、一致且易用的开发体验,我们推出了全新的微信支付APIv3接口。该版本API的具体规则请参考“APIv3接口规则

2. 开发环境搭建

为了帮助开发者调用开放接口,我们提供了JavaPHPGO语言版本的开发库,封装了签名生成、签名验证、敏感信息加/解密、媒体文件上传等基础功能


3. 业务时序图

3.1. 业务时序图

3.2. API接入示例

文档展示了如何使用微信支付服务端 SDK 快速接入扫码支付产品,完成与微信支付对接的部分。

注意

• 文档中的代码示例是用来阐述 API 基本使用方法,代码中的示例参数需替换成商户自己账号及请求参数才能跑通。

• 以下接入步骤仅提供参考,请商户结合自身业务需求进行评估、修改。

3.2.1 身份信息校验

步骤说明:该接口允许商户请求微信支付对用户支付用户的实名信息与入参中的身份信息进行一致性校验,商户可以根据校验结果使用正确的信息进行报关。

敏感信息字段: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
    }

//Call id verification API
func idVerification() {
   idVerificationBody := `{
  "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",
  "certificate_name": "HHp24MagiQ6i7c5yIow/9ZTk5Zt5cJP5x2cGsAA8hif07fRdb2"
}`
   header.Add("Wechatpay-Serial", "")
   header.Add("Idempotency-Key", "20220518-001")
   result, err := client.Post(ctx, "https://apihk.mch.weixin.qq.com/v3/global/customs/verify-certificate", header, nil, idVerificationBody, "application/json")
   if err != nil {
      // Process error
   }
   log.Printf("%s", result.Response.Body)
}

//Id info verification API
public function idInfoVerification($instance, $platformPublicKeyInstance, $platformCertificateSerial){
    $encryptor = static function(string $msg) use ($platformPublicKeyInstance): string {
        return Rsa::encrypt($msg, $platformPublicKeyInstance, OPENSSL_PKCS1_PADDING);
    };
    try {
        $resp = $instance
            ->chain('/v3/global/customs/verify-certificate')
            ->post([
                'json' => [
                    'appid' => 'wxdace12300000000',
                    'mchid' => '1900000000',
                    'out_trade_no' => 'YX001',
                    'transaction_id' => '420000000001500000089',
                    'customs' => 'SHANGHAI_ZS',
                    'merchant_customs_no' => '123456',
                    'sub_order_no' => '20150806125346',
                    'certificate_type' => 'IDCARD',
                    'certificate_id' => 'HHp24MagiQ6i7c5yIow5cJP5x2cGsAA8hi5yIow5cJP5x',
                    'certificate_name' => 'HHp24MagiQ6i7c5yIow/9ZTk5Zt5cJP5x2cGsAA8hif07fRdb2'
                ],
                'headers' => [
                    'Wechatpay-Serial' => $platformCertificateSerial
                ]
            ]);
        echo $resp->getStatusCode(), PHP_EOL;
        echo $resp->getBody(), PHP_EOL;
    } catch (\Exception $e) {
        // Exception handling
    }
}

									{
										"stock_id": "Python",
										"stock_creator_mchid": "123456",
										"limit": 10,
									}

其他重要参数请前往身份信息校验API文档页面参考。

3.2.2 订单附加信息提交接口

步骤说明:商户通过该接口请求微信支付向海关推送支付单的报关信息。微信支付在收到报关附加信息后,会异步向海关进行支付单申报信息推送。

代码示例


    //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 
    }


//Call customs declaration API
func customsDeclaration() {
   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
}
`
   result, err := client.Post(ctx, "https://apihk.mch.weixin.qq.com/v3/global/customs/orders", customsDeclarationBody)
   if err != nil {
      // Process error
   }
   log.Printf("%s", result.Response.Body)
}

//Customs Declaration API
public function customsDeclaration($instance){
    try {
        $resp = $instance
            ->chain('/v3/global/customs/orders')
            ->post([
                'json' => [
                    '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
                ]
            ]);

        echo $resp->getStatusCode(), PHP_EOL;
        echo $resp->getBody(), PHP_EOL;
    } catch (\Exception $e) {
        // Exception handling
    }
}

									{
										"stock_id": "Python",
										"stock_creator_mchid": "123456",
										"limit": 10,
									}

其他重要参数请前往报关API文档页面参考。

3.2.3 报关信息修改接口

步骤说明:当商户错误传了报关信息的部分字段时,可调用该接口对报关信息进行修改。该接口只能修改如下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 
    }

//Modify customs declaration API
func modifyCustomsDeclarartion() {
   modifyCustomsDeclarartionBody := `
{
   "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
}
`
   result, err := client.Patch(ctx, "https://apihk.mch.weixin.qq.com/v3/global/customs/orders", modifyCustomsDeclarartionBody)
   if err != nil {
      // Process error
   }
   log.Printf("%s", result.Response.Body)
}

//Modify Customs Declaration API
public function modifyCustomsDeclarartion($instance){
    try {
        $resp = $instance
            ->chain('/v3/global/customs/orders')
            ->patch([
                'json' => [
                    'appid' => 'wxd678efh567hg6787',
                    'mchid' => '1230000109',
                    'out_trade_no' => '20150806125346',
                    'transaction_id' => '1000320306201511078440737890',
                    'customs' => 'SHANGHAI_ZS',
                    'merchant_customs_no' => '123456',
                    'duty' => 888,
                    'sub_order_no' => '20150806125346',
                    'order_fee' => 888,
                    'transport_fee' => 888,
                    'product_fee' => 888
                ]
            ]);

        echo $resp->getStatusCode(), PHP_EOL;
        echo $resp->getBody(), PHP_EOL;
    } catch (\Exception $e) {
        // Exception handling
    }
}

									{
										"stock_id": "Python",
										"stock_creator_mchid": "123456",
										"limit": 10,
									}

其他重要参数请前往报关信息修改API文档页面参考。

3.2.4 订单附加信息查询接口

步骤说明:商户可通过该接口查询之前提交的报关附加信息,以及海关报关状态。

代码示例


    //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 
    }

//Call query customs declaration API
func queryCustomsDeclaration() {
   result, err := client.Get(ctx, "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")
   if err != nil {
      // Process error
   }
   log.Printf("%s", result.Response.Body)
}

//Query Customs Declaration API
public function queryCustomsDeclaration($instance){
    try {
        $resp = $instance
            ->chain('/v3/global/customs/orders')
            ->get([
                'query' => [
                    'mchid' => '1900000000',
                    'appid' => 'wxd678efh567hg6787',
                    'order_type' => 'transaction_id',
                    'order_no' => '1000320306201511078440737890',
                    'customs' => 'SHANGHAI_ZS',
                    'offset' => 1,
					'limit' => 20
                ]
            ]);
        echo $resp->getStatusCode(), PHP_EOL;
        echo $resp->getBody(), PHP_EOL;
    } catch (\Exception $e) {
        // Exception handling
    }
}

									{
										"stock_id": "Python",
										"stock_creator_mchid": "123456",
										"limit": 10,
									}

其他重要参数请前往报关查询API文档页面参考。

3.2.5 订单附加信息重推接口

步骤说明:当订单已申报且海关要求商户重新推送报关信息时,商户可通过该接口将报关信息再次发往海关。

代码示例


    //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 
    }

//Repush customs declaration API
func repushCustomsDeclarartion() {
   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"
}
`
   result, err := client.Post(ctx, "https://apihk.mch.weixin.qq.com/v3/global/customs/redeclare", repushBody)
   if err != nil {
      // Process error
   }
   log.Printf("%s", result.Response.Body)
}

//Repush Customs Declaration API
public function repushCustomsDeclarartion($instance){
    try {
        $resp = $instance
            ->chain('v3/global/customs/redeclare')
            ->post([
                'json' => [
                    'mchid' => '1230000109',
                    'appid' => 'wxd678efh567hg6787',
                    'out_trade_no' => '20150806125346',
                    'transaction_id' => '1000320306201511078440737890',
                    'sub_order_no' => '20150806125346',
                    'sub_order_id' => '1000320306201511078440737891',
                    'customs' => 'SHANGHAI_ZS',
                    'merchant_customs_no' => '123456'
                ]
            ]);
        echo $resp->getStatusCode(), PHP_EOL;
        echo $resp->getBody(), PHP_EOL;
    } catch (\Exception $e) {
        // Exception handling
    }
}

									{
										"stock_id": "Python",
										"stock_creator_mchid": "123456",
										"limit": 10,
									}

其他重要参数请前往报关查询API文档页面参考。

    页面导航

About  WeChat  Pay

Powered By Tencent & Tenpay Copyright©

2005-2024 Tenpay All Rights Reserved.

Contact Us
Wechat Pay Global

WeChat Pay Global

置顶