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 快速接入JSAPI支付产品,完成与微信支付对接的部分。

注意:
文档中的代码示例是用来阐述 API 基本使用方法,代码中的示例参数需替换成商户自己账号及请求参数才能跑通。
以下接入步骤仅提供参考,请商户结合自身业务需求进行评估、修改。

3.2.1 小程序预签约

步骤说明:如 时序图2.2步骤 描述,当用户在商户小程序中选择同意使用代扣产品时,商户应请求小程序-预签约API 以获得预签约ID session_id,供下一步调起签约小程序使用。

代码示例 - JAVA:


//Obtaining Signing Session ID API for mini-program signing
    public void miniProgramSignTest() throws IOException {
		String miniprogramSignBody = """{
"expired_time": "2021-11-20T13:29:35+08:00",
"openid": "of8YZ6A_ySrPYzjX7joXo_0000",
"out_contract_code": "20220614out_contract_code",
"plan_id": 10001,
"sp_appid": "wx7bc9000000000000",
"sub_mchid": "90325355",
"success_notify_url": "https://yoursite.com",
"user_display_name": "mike"
}""";
        HttpPost httpPost = new HttpPost("https://apihk.mch.weixin.qq.com/v3/global/papay/contracts/miniprogram-pre-entrust-sign");
        httpPost.addHeader("Accept", "application/json");
        httpPost.addHeader("Content-type", "application/json; charset=utf-8");
        httpPost.setEntity(new StringEntity(miniprogramSignBody));
        CloseableHttpResponse response = httpClient.execute(httpPost);
        //Process the response
    }

示例代码 - PHP:


 //Mini Program Signing API
  public function miniProgramSigning($instance)
  {
    try {
      $resp = $instance
        ->chain('v3/global/papay/contracts/miniprogram-pre-entrust-sign')
        ->post([
          'json' => [
            "sp_appid" => "wx7bc9000000000000",
			"sub_mchid" => "90325355",
            "openid" => "of8YZ6A_ySrPYzjX7joXo_0000",
            "out_contract_code" => "20220614out_contract_code",
            "plan_id" => 10001,
            "success_notify_url" => "https://www.yoursite.com",
            "user_display_name" => "mike",
			"expired_time" => "2021-11-20T13:29:35+08:00",
          ]
        ]);

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

示例代码 - GO:


//Mini program signing API
func miniProgramSigning() {
	signBody := `{
"expired_time": "2021-11-20T13:29:35+08:00",
"openid": "of8YZ6A_ySrPYzjX7joXo_0000",
"out_contract_code": "20220614out_contract_code",
"plan_id": 10001,
"sp_appid": "wx7bc9000000000000",
"sub_mchid": "90325355",
"success_notify_url": "https://yoursite.com",
"user_display_name": "mike"
}`
	
	result, err := client.Post(ctx, "https://apihk.mch.weixin.qq.com/v3/global/papay/contracts/miniprogram-pre-entrust-sign", signBody)
	if err != nil {
		// Process error
	}
	log.Printf("%s", result.Response.Body)

3.2.2 小程序调起签约

步骤说明:
解析 3.1小程序预签约 接口返回的 Body json字符串,获取其中的 session_id,返回示例: { "session_id": "201710180325670965" }
使用上一步得到的 session_id 参数拉起签约小程序

示例代码:


 var session_id = "201710180325670965"; // obtained from miniprogram-pre-entrust-sign
// start signing process
wx.navigateToMiniProgram({
	appId: wxbd687630cd02ce1d,
	path: 'pages/Oversea/walletSelect?sessionId=' + session_id,
	extraData: {},
	success(res) {
		// Jumped to the signing mini program successfully
	},
	fail(res) {
		// Failed to jump to the signing mini program 
	}
})


// After signing process, user will return back to merchant's miniprogram
App({
	onShow(res)  {
		if  (res.scene  ===  1038)  {  //Scenario value 1038: return from the opened min program
			const { appId, extraData } = res.referrerInfo
			if  (appId  ==  'wxbd687630cd02ce1d')  {  // appId is wxbd687630cd02ce1d: jump back from the signing min program
				if  (typeof  extraData  ==  'undefined') {
					// TODO
					// The client min program is not sure of the signing result and needs to request the merchant-side background to confirm the signing result
					return;
				}
				if (extraData.return_code  ==  'SUCCESS') {
					// TODO
					// The client min program signs successfully and needs to request the merchant-side background to confirm the signing result
					var  contract_id  =  extraData.contract_id
					return;
				} 
				else  {
					// TODO
					// Signing failed
					return;
				}
			}
		}
	}
})

3.2.3 签约结果通知

步骤说明:用户完成签约后,微信支付会向发起签约时传入的success_notify_url推送签约结果通知,商户需要在接收到通知后返回对应的信息。

签约通知示例


 // 签约成功回调 http body 数据示例
{
    "id":"EV-2018022511223320873",
    "create_time":"2022-06-14T14:01:35+08:00",
    "resource_type":"encrypt-resource",
    "event_type":"PAPAY.SIGN",
	"summary": "签约成功",
    "resource" : {
        "algorithm":"AEAD_AES_256_GCM",
        "ciphertext": "...",
        "nonce": "dAvnRJWFOfdL",
        "associated_data": "papay"
    }
}
// 对 resource.ciphertext 解密后得到的数据示例如下:
{
   "sp_mchid":"10000091",
   "sub_mchid":"10000097",
   "out_contract_code":"100001256",
   "plan_id":123,
   "contract_id":"Wx15463511252015071056489715",
   "sp_appid":"wxcbda96de0b165486",
   "openid":"ouFhd5X9s9WteC3eWRjXV3lea123",
   "operate_time":"2015-09-01T10:00:00+08:00"
}

// 解约成功回调 http body 数据示例
{
   "id":"2646bee0-aef8-5804-9752-ef1a56170fdf",
   "create_time":"2022-06-14T16:31:53+08:00",
   "resource_type":"encrypt-resource",
   "event_type":"PAPAY.TERMINATE",
   "summary":"解约成功",
   "resource":{
      "original_type":"papay",
      "algorithm":"AEAD_AES_256_GCM",
      "ciphertext": "...",
      "associated_data":"papay",
      "nonce":"SExJ2Xxx7sr1"
   }
}
// 对 resource.ciphertext 解密后得到的数据示例如下:
{
	"sp_mchid": "10000091",
	"sub_mchid": "10000097",
	"out_contract_code": "100001256",
	"plan_id": 123,
	"contract_id": "Wx15463511252015071056489715",
	"sp_appid": "wxcbda96de0b165486",
	"openid": "ouFhd5X9s9WteC3eWRjXV3lea123",
	"contract_termination_mode": "USER",
	"operate_time": "2015-10-01T10:00:00+08:00"
}

当商户接收到微信支付回调通知时,应更新本地存储的用户签约状态,更新完成后返回如下 http body给微信支付,http状态应设置为200。

{
	"code": "SUCCESS",
	"message": "OK"
}

注意:

  • 支付结果通知是以POST 方法访问商户设置的通知url,通知的数据以JSON 格式通过请求主体(BODY)传输。通知的数据包括了加密的支付结果详情。
  • 加密不能保证通知请求来自微信。微信会对发送给商户的通知进行签名,并将签名值放在通知的HTTP头Wechatpay-Signature。商户应当验证签名,以确认请求来自微信,而不是其他的第三方。签名验证的算法请参考《微信支付API V3签名验证》
  • 支付通知http应答码为200或204才会当作正常接收,当回调处理异常时,应答的HTTP状态码应为500,或者4xx。
  • 商户成功接收到回调通知后应返回成功的http应答码为200或204。
  • 同样的通知可能会多次发送给商户系统。商户系统必须能够正确处理重复的通知。 推荐的做法是,当商户系统收到通知进行处理时,先检查对应业务数据的状态,并判断该通知是否已经处理。如果未处理,则再进行处理;如果已处理,则直接返回结果成功。在对业务数据进行状态检查和处理之前,要采用数据锁进行并发控制,以避免函数重入造成的数据混乱。
  • 对后台通知交互时,如果微信收到商户的应答不符合规范或超时,微信认为通知失败,微信会通过一定的策略定期重新发起通知,尽可能提高通知的成功率,但微信不保证通知最终能成功。(通知频率为15s/15s/30s/3m/10m/20m/30m/30m/30m/60m/3h/3h/3h/6h/6h - 总计 24h4m)
  • 3.2.4 查询签约结果

    步骤说明:当商户后台、网络、服务器等出现异常,商户系统最终未接收到签约结果通知时商户可通过查询签约结果API核实签约状态。微信支付提供了两种查询签约状态的方式,一种是通过商户签约号即out_contract_code,另一种是通过微信支付返回的微信签约号contract_id。

    JAVA - 示例代码:
    通过商户签约号out_contract_code查询签约状态

    
    //Querying Signing Status (By out_contract_code)
        public void querySignStatusByContractCodeTest() throws IOException {
            HttpGet httpGet = new HttpGet("https://apihk.mch.weixin.qq.com/v3/global/papay/contracts/out-contract-code/100001261?sp_appid=wxcbda96de0b165486&sub_appid=wxcbda96de0b165484&plan_id=123");
            httpGet.addHeader("Accept", "application/json");
            httpGet.addHeader("Content-type", "application/json; charset=utf-8");
            CloseableHttpResponse response = httpClient.execute(httpGet);
            //Process the response
        }

    通过微信签约号contract_id查询签约状态

    
    //Querying Signing Status (By contract_id) API
        public void querySignStatusTest() throws IOException {
            HttpGet httpGet = new HttpGet("https://apihk.mch.weixin.qq.com/v3/global/papay/contracts/202203242337333903387184301572?sub_mchid=10000097&sp_appid=wxcbda96de0b165486&sub_appid=wxcbda96de0b165484");
            httpGet.addHeader("Accept", "application/json");
            httpGet.addHeader("Content-type", "application/json; charset=utf-8");
            CloseableHttpResponse response = httpClient.execute(httpGet);
            //Process the response
        }

    PHP - 示例代码:
    通过商户签约号out_contract_code查询签约状态

    
      //Querying Signing Status (By out_contract_code) API
      public function querySignStatusByContractCode($instance)
      {
        try {
          $resp = $instance
            ->v3->global->papay->contracts->outContractCode->_out_contract_code_
            ->get([
              'query' => [
                'sp_appid' => 'wxcbda96de0000006',
                'sub_appid' => 'wxcbda96de0000004',
                'sub_mchid' => '110000000'
              ],
              '_out_contract_code_' => '100005698'
            ]);
    
          echo $resp->getStatusCode(), PHP_EOL;
          echo $resp->getBody(), PHP_EOL;
        } catch (\Exception $e) {
          // Exception handling
        }
      }

    通过微信签约号contract_id查询签约状态

    				
      //Querying Signing Status (By contract_id) API
      public function querySignStatus($instance)
      {
        try {
          $resp = $instance
            ->v3->global->papay->contracts->_contract_id_
            ->get([
              'query' => [
                'sp_appid' => 'wxcbda96de0000006',
                'sub_appid' => 'wxcbda96de0000004',
                'sub_mchid' => '110000000'
              ],
              'contract_id' => '202203242337333903387184301572'
            ]);
    
          echo $resp->getStatusCode(), PHP_EOL;
          echo $resp->getBody(), PHP_EOL;
        } catch (\Exception $e) {
          // Exception handling
        }
      }

    GO - 示例代码:
    通过商户签约号out_contract_code查询签约状态

    				
    //Querying signing status by out_contract_code API
    func querySigningStatusByContractCode() {
    	result, err := client.Get(ctx, "https://apihk.mch.weixin.qq.com/v3/global/papay/contracts/out-contract-code/100001261?sp_appid=wxcbda96de0b165486&sub_appid=wxcbda96de0b165484&plan_id=123")
    	if err != nil {
    		// Process error
    	}
    	log.Printf("status=%d resp=%s", result.Response.StatusCode, result.Response.Body)
    }

    通过微信签约号contract_id查询签约状态

    				
    //Querying signing status API
    func querySigningStatus() {
    	result, err := client.Get(ctx, "https://apihk.mch.weixin.qq.com/v3/global/papay/contracts/202203242337333903387184301572?sub_mchid=10000097&sp_appid=wxcbda96de0b165486&sub_appid=wxcbda96de0b165484")
    	if err != nil {
    		// Process error
    	}
    	log.Printf("status=%d resp=%s", result.Response.StatusCode, result.Response.Body)
    }

    重要参数:

  • contract_id - 微信测返回的签约协议号,唯一标识一条签约协议,示例值:202203242337333903387184301572
  • out_contract_code - 商户侧生成的签约协议号,示例值:100001261
  • sp_appid - 服务商公众号的appid
  • sub_appid - 发起签约的子商户小程序appid
  • 3.2.5 扣款

    步骤说明:在完成签约后,商户可使用对应的协议ID发起扣款
    代码示例 - JAVA:

    
    //Applying for Termination API
    public void deductionTest() throws IOException {
    		String deductionBody = """
    {
    	"sp_appid": "wxcbda96de0b165486",
    	"sub_mchid": "10000097",
    	"sub_appid": "wxcbda96de0b165484",
    	"description": "PAPAuto-debit支付测试",
    	"attach": "支付测试",
    	"notify_url": "https://wxpay.wxutil.com/pub_v2/pay/notify.v2.php",
    	"out_trade_no": "1217752501201407033233368018",
    	"goods_tag": "WXG",
    	"merchant_category_code": "1011",
    	"contract_id": "Wx15463511252015071056489715",
    	"amount": {
    		"total": 10000,
    		"currency": "HKD"
    	},
    	"scene_info": {
    		"device_ip": "59.37.125.32",
    		"device_id": "013467007045764"
    	}
    }
    """;
            HttpPost httpPost = new HttpPost("https://apihk.mch.weixin.qq.com/v3/global/papay/transactions");
            httpPost.addHeader("Accept", "application/json");
            httpPost.addHeader("Content-type", "application/json; charset=utf-8");
            httpPost.setEntity(new StringEntity(deductionBody));
            CloseableHttpResponse response = httpClient.execute(httpPost);
            //Process the response
    }

    示例代码 - PHP:

    
      //Deduction API
      public function deduction($instance)
      {
        try {
          $resp = $instance
            ->v3->global->papay->transactions
            ->post([
              'json' => [
                "sp_appid" => "wxcbda96de0b165486",
                "sub_mchid" => "10000097",
                "sub_appid" => "wxcbda96de0b165484",
                "description" => "PAPAuto-debit支付测试",
                "attach" => "支付测试",
                "notify_url" => "https://wxpay.wxutil.com/pub_v2/pay/notify.v2.php",
                "out_trade_no" => "1217752501201407033233368018",
                "goods_tag" => "WXG",
                "merchant_category_code" => "1011",
                "contract_id" => "Wx15463511252015071056489715",
                "amount" => array(
                  "total" => 10000,
                  "currency" => "HKD"
                ),
                "scene_info" => array(
                  "device_ip" => "59.37.125.32",
                  "device_id" => "013467007045764"
                )
              ]
            ]);
          echo $resp->getStatusCode(), PHP_EOL;
          echo $resp->getBody(), PHP_EOL;
        } catch (\Exception $e) {
          // Exception handling
        }
      }

    示例代码 - GO:

    
    //Deduction API
    func deduction() {
    	body := `
    {
    	"sp_appid": "wxcbda96de0b165486",
    	"sub_mchid": "10000097",
    	"sub_appid": "wxcbda96de0b165484",
    	"description": "PAPAuto-debit支付测试",
    	"attach": "支付测试",
    	"notify_url": "https://wxpay.wxutil.com/pub_v2/pay/notify.v2.php",
    	"out_trade_no": "1217752501201407033233368018",
    	"goods_tag": "WXG",
    	"merchant_category_code": "1011",
    	"contract_id": "Wx15463511252015071056489715",
    	"amount": {
    		"total": 10000,
    		"currency": "HKD"
    	},
    	"scene_info": {
    		"device_ip": "59.37.125.32",
    		"device_id": "013467007045764"
    	}
    }
    `
    	result, err := client.Post(ctx, "https://apihk.mch.weixin.qq.com/v3/global/papay/transactions", body)
    	if err != nil {
    		// Process error
    	}
    	log.Printf("%s", result.Response.Body)
    }

    重要参数:

  • contract_id:用户签约协议号,微信支付根据该字段校验用户和商户的签约关系,如果未签约或者用户已解约则返回 NO_AUTH - 签约协议不存在

  • 3.2.6 扣款结果通知

    步骤说明:扣款成功后,微信支付会以异步通知的方式通过扣款请求中的 notify_url 参数告知商户扣款已成功。

    
    // 扣款结果通知 http body 数据示例
    {
        "id":"EV-2018022511223320873",
        "create_time":"20180225112233",
        "resource_type":"encrypt-resource",
        "event_type":"TRANSACTION.SUCCESS",
        "resource" : {
            "algorithm":"AEAD_AES_256_GCM",
            "ciphertext": "...",
            "nonce": "...",
            "associated_data": ""
        }
    }
    // 对 resource.ciphertext 解密后得到的数据示例如下:
    {
    	"sp_mchid": "10000100",
    	"sp_appid": "wx2421b1c4370ec43b",
    	"sub_mchid": "20000100",
    	"out_trade_no": "20150806125346",
    	"transaction_id": "1008450740201411110005820873",
    	"attach": "支付测试",
    	"trade_type": "AUTH",
    	"bank_type": "CCB_DEBIT",
    	"success_time": "2018-06-08T10:34:56+08:00",
    	"trade_state": "SUCCESS",
    	"trade_state_desc": "支付成功",
    	"merchant_category_code": "1011",
    	"contract_id": "Wx15463511252015071056489715",
    	"payer": {
    		"sp_openid": "oUpF8uN95-Ptaags6E_roPHg7AG0"
    	},
    	"amount": {
    		"total": 528800,
    		"currency": "HKD",
    		"payer_total": 518799,
    		"payer_currency": "CNY",
    		"exchange_rate": {
    			"type": "SETTLEMENT_RATE",
    			"rate": 8000000
    		}
    	},
    	"promotion_detail": [{
    		"promotion_id": "109519",
    		"name": "单品惠-6",
    		"scope": "SINGLE",
    		"type": "DISCOUNT",
    		"amount": 1,
    		"currency": "HKD",
    		"activity_id": "931386",
    		"wechatpay_contribute_amount": 1,
    		"merchant_contribute_amount": 0,
    		"other_contribute_amount": 0,
    		"goods_detail": [{
    			"goods_id": "iphone6s_16G",
    			"goods_remark": "商品备注",
    			"quantity": 1,
    			"price": 528800
    		}]
    	}]
    }

    3.2.7 订单查询API

    步骤说明:当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知时商户可通过查询订单接口核实订单支付状态。

    代码示例 - JAVA:

    
    	//Query transaction details by transaction_id   
    	public void queryOrderByIdTest() throws IOException {
            HttpGet httpGet = new HttpGet("https://apihk.mch.weixin.qq.com/v3/global/papay/transactions/4015463511252015071056489715?sub_mchid=10000097");
            httpGet.addHeader("Accept", "application/json");
            httpGet.addHeader("Content-type", "application/json; charset=utf-8");
            CloseableHttpResponse response = httpClient.execute(httpGet);
            //Process the response
        }
    
    	//Query transaction details by out_trade_no
    	public void queryOrderByNoTest() throws IOException {
            HttpGet httpGet = new HttpGet("https://apihk.mch.weixin.qq.com/v3/global/papay/transactions/out_trade_no/1217752501201407033233368018?sub_mchid=10000097");
            httpGet.addHeader("Accept", "application/json");
            httpGet.addHeader("Content-type", "application/json; charset=utf-8");
            CloseableHttpResponse response = httpClient.execute(httpGet);
            //Process the response
        }

    示例代码 - PHP:

    
    // Query transaction details by transaction_id 
    public function queryOrderById($instance)
    {
        try {
            $resp = $instance
                ->v3->global->papay->transactions->_transaction_id_
                ->get([
                        'query' => [
                    		'sub_mchid'    => '10000097',
                        ],
                        'transaction_id' => '4015463511252015071056489715'
                    ]
                );
    
            echo $resp->getStatusCode(), PHP_EOL;
            echo $resp->getBody(), PHP_EOL;
        } catch (Exception $e) {
            // Exception handling
    	}
    }
    
    // Query transaction details by out_trade_no
    public function queryOrderByNo($instance)
    {
        try {
            $resp = $instance
                ->v3->global->papay->transactions->outTradeNo->_out_trade_no_
                ->get([
                        'query' => [
                    		'sub_mchid'    => '10000097',
                        ],
                        'out_trade_no' => '1217752501201407033233368018'
                    ]
                );
    
            echo $resp->getStatusCode(), PHP_EOL;
            echo $resp->getBody(), PHP_EOL;
        } catch (Exception $e) {
            // Exception handling
    	}
    }

    示例代码 - GO:

    
    //Query transaction details by transaction_id 
    func queryOrderById() {
    	result, err := client.Get(ctx, "https://apihk.mch.weixin.qq.com/v3/global/papay/transactions/4015463511252015071056489715?sub_mchid=10000097")
    	if err != nil {
    		// Process error
    	}
    	log.Printf("%s", result.Response.Body)
    }
    
    
    //Query transaction details by out_trade_no
    func queryOrderByNo() {
    	result, err := client.Get(ctx, "https://apihk.mch.weixin.qq.com/v3/global/papay/transactions/out_trade_no/1217752501201407033233368018?sub_mchid=10000097")
    	if err != nil {
    		// Process error
    	}
    	log.Printf("%s", result.Response.Body)
    }

    重要参数:

  • out_trade_no:商户侧扣费订单号
  • transaction_id:微信订单号
  • 3.2.8 【服务端】关闭订单

    步骤说明:当商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付;系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口

    代码示例 - JAVA:

    
    //Applying for close order
    public void closeOrderTest() throws IOException {
    		String closeOrderBody = """
    {
      "sub_mchid": "20000100"
    }
    """;
            HttpPost httpPost = new HttpPost("https://apihk.mch.weixin.qq.com/v3/global/papay/transactions/out-trade-no/1217752501201407033233368018/reverse");
            httpPost.addHeader("Accept", "application/json");
            httpPost.addHeader("Content-type", "application/json; charset=utf-8");
            httpPost.setEntity(new StringEntity(closeOrderBody ));
            CloseableHttpResponse response = httpClient.execute(httpPost);
            //Process the response
    }

    示例代码 - PHP:

    
      // Call close order API
      public function closeOrder($instance)
      {
        try {
          $resp = $instance
    		->v3->global->papay->transactions->outTradeNo->_out_trade_no_->reverse
            ->post([
              'json' => [
                'sub_mchid'    => '20000100'
              ],
              'out_trade_no' => '1217752501201407033233368018'
            ]);
          echo $resp->getStatusCode(), PHP_EOL;
          echo $resp->getBody(), PHP_EOL;
        } catch (Exception $e) {
          // Exception handling
        }
      }

    示例代码 - GO:

    
    //Deduction API
    func closeOrder() {
    	body := `
    {
      "sub_mchid": "20000100"
    }
    `
    	result, err := client.Post(ctx, "https://apihk.mch.weixin.qq.com/v3/global/papay/transactions/out-trade-no/1217752501201407033233368018/reverse", body)
    	if err != nil {
    		// Process error
    	}
    	log.Printf("%s", result.Response.Body)
    }

    重要参数:

  • out_trade_no:商户侧扣费订单号

  • 3.2.9 【服务端】解约

    步骤说明:当用户希望在商户侧发起解约时,商户需调用解约API来完成解约。

    代码示例 - JAVA:

    
    //Applying for Termination API    
    public void deductionTest() throws IOException {
    		String terminateBody = """
    {
    "sp_appid": "wxcbda96de0b165486",
    "sub_mchid": "10000097",
    "sub_appid": "wxcbda96de0b165484", 
    "termination_note": "Cause of termination" 
    }
    """;
            HttpPost httpPost = new HttpPost("https://apihk.mch.weixin.qq.com/v3/global/papay/contracts/100005698/terminate");
            httpPost.addHeader("Accept", "application/json");
            httpPost.addHeader("Content-type", "application/json; charset=utf-8");
            httpPost.setEntity(new StringEntity(terminateBody));
            CloseableHttpResponse response = httpClient.execute(httpPost);
            //Process the response
        }

    示例代码 - PHP:

    
      //Applying for Termination API
      public function termination($instance)
      {
        try {
          $resp = $instance
            ->v3->global->papay->contracts->_contract_id_->terminate
            ->post([
              'json' => [
                'sp_appid' => 'wxcbda96de0b165486',
    			'sub_mchid' => '10000097',
    			'sub_appid' => 'wxcbda96de0b165484',
    			'termination_note' => 'Cause of termination'
              ],
              '_contract_id_' => '100005698'
            ]);
          echo $resp->getStatusCode(), PHP_EOL;
          echo $resp->getBody(), PHP_EOL;
        } catch (\Exception $e) {
          // Exception handling
        }
      }

    示例代码 - GO:

    
    //Applying for Termination API
    func terminate() {
    	body := `
    {
    "sp_appid": "wxcbda96de0b165486",
    "sub_mchid": "10000097",
    "sub_appid": "wxcbda96de0b165484", 
    "termination_note": "Cause of termination" 
    }
    `
    	result, err := client.Post(ctx, "https://apihk.mch.weixin.qq.com/v3/global/papay/contracts/100005698/terminate", body)
    	if err != nil {
    		// Process error
    	}
    	log.Printf("%s", result.Response.Body)
    }

    重要参数:

  • contract_id:微信侧代扣协议ID
    • 页面导航

    About  WeChat  Pay

    Powered By Tencent & Tenpay Copyright©

    2005-2024 Tenpay All Rights Reserved.

    Contact Us
    Wechat Pay Global

    WeChat Pay Global

    置顶