开发指引

更新时间:2024.11.15

1. 接口规则

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

2. 开发准备

2.1. 搭建和配置开发环境

开发者应当依据自身的编程语言来构建并配置相应的开发环境。

3. 快速接入

3.1. 业务流程图

业务流程时序图

重点步骤说明:

步骤5 商户创建商家券后,可通过《创建全场满额送活动》接口创建支付有礼活动,微信支付生成支付有礼活动并返回活动ID给到商户。

步骤20 支付有礼活动创建后,商户可通过《获取活动详情接口》查询管理活动。

步骤22 活动创建后,如需结束活动,可通过《终止活动》接口,结束活动。

3.2. API接入(含示例代码)

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

注意

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

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

3.2.1. 【服务端】创建全场满额送活动

步骤说明:商户可以创建满额送活动,用户支付后送全场券,提升交易额。

background_color取值



Java

1示例代码
2public void CreateActivity() throws Exception{
3    //请求URL
4    HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/unique-threshold-activity");
5    // 请求body参数
6    String reqdata = "{"
7            + "\"activity_base_info\": {"
8            + "\"activity_name\":\"良品铺子回馈活动\","
9            + "\"activity_second_title\":\"海飞丝的券\","
10            + "\"merchant_logo_url\":\"https://tool.oschina.net/regex.jpg\","
11            + "\"background_color\":\"COLOR010\","
12            + "\"begin_time\":\"2015-05-20T13:29:35+08:00\","
13            + "\"end_time\":\"2015-05-20T13:29:35+08:00\","
14            + "\"available_periods\": {"
15            + "\"available_time\": ["
16            + "{"
17            + "\"begin_time\":\"2015-05-20T00:00:00+08:00\","
18            + "\"end_time\":\"2015-05-20T23:59:59+08:00\""
19            + "}"
20            + "],"
21            + "\"available_day_time\": ["
22            + "{"
23            + "\"begin_day_time\":\"110000\","
24            + "\"end_day_time\":\"135959\""
25            + "}"
26            + "]"
27            + "},"
28            + "\"out_request_no\":\"100002322019090134234sfdf\","
29            + "\"delivery_purpose\":\"OFF_LINE_PAY\","
30            + "\"mini_programs_appid\":\"wx23232232323\","
31            + "\"mini_programs_path\":\"/path/index/index\""
32            + "},"
33            + "\"award_send_rule\": {"
34            + "\"transaction_amount_minimum\":100,"
35            + "\"send_content\":\"SINGLE_COUPON\","
36            + "\"award_type\":\"BUSIFAVOR\","
37            + "\"award_list\": ["
38            + "{"
39            + "\"stock_id\":\"98065001\","
40            + "\"original_image_url\":\"https://tool.oschina.net/regex.jpg\","
41            + "\"thumbnail_url\":\"https://tool.oschina.net/regex.jpg\""
42            + "}"
43            + "],"
44            + "\"merchant_option\":\"MANUAL_INPUT_MERCHANT\","
45            + "\"merchant_id_list\": ["
46            + "\"0\":\"10000022\","
47            + "\"1\":\"10000023\""
48            + "]"
49            + "},"
50            + "\"advanced_setting\": {"
51            + "\"delivery_user_category\":\"DELIVERY_MEMBER_PERSON\","
52            + "\"merchant_member_appid\":\"34567890\","
53            + "\"goods_tags\": ["
54            + "\"0\":\"xxx\","
55            + "\"1\":\"yyy\""
56            + "]"
57            + "}"
58            + "}";
59    StringEntity entity = new StringEntity(reqdata,"utf-8");
60    entity.setContentType("application/json");
61    httpPost.setEntity(entity);
62    httpPost.setHeader("Accept", "application/json");
63    //完成签名并执行请求
64    CloseableHttpResponse response = httpClient.execute(httpPost);
65    try {
66        int statusCode = response.getStatusLine().getStatusCode();
67        if (statusCode == 200) { //处理成功
68            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
69        } else if (statusCode == 204) { //处理成功,无返回Body
70            System.out.println("success");
71        } else {
72            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
73            throw new IOException("request failed");
74        }
75    } finally {
76        response.close();
77    }
78}

PHP

1示例代码
2try {
3    $resp = $client->request(
4        'POST',
5        'https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/unique-threshold-activity', //请求URL
6        [
7            // JSON请求体
8            'json' => [
9                "activity_base_info" => [
10                    "activity_name" => "良品铺子回馈活动", 
11                    "activity_second_title" => "海飞丝的券", 
12                    "merchant_logo_url" => "https://tool.oschina.net/regex.jpg", 
13                    "background_color" => "COLOR010", 
14                    "begin_time" => "2015-05-20T13:29:35+08:00", 
15                    "end_time" => "2015-05-20T13:29:35+08:00", 
16                    "available_periods" => [
17                        "available_time" => [
18                            [
19                                "begin_time" => "2015-05-20T00:00:00+08:00", 
20                                "end_time" => "2015-05-20T23:59:59+08:00", 
21                            ],
22                        ],
23                        "available_day_time" => [
24                            [
25                                "begin_day_time" => "110000", 
26                                "end_day_time" => "135959", 
27                            ],
28                        ],
29                    ],
30                    "out_request_no" => "100002322019090134234sfdf", 
31                    "delivery_purpose" => "OFF_LINE_PAY", 
32                    "mini_programs_appid" => "wx23232232323", 
33                    "mini_programs_path" => "/path/index/index", 
34                ],
35                "award_send_rule" => [
36                    "transaction_amount_minimum" => 100, 
37                    "send_content" => "SINGLE_COUPON", 
38                    "award_type" => "BUSIFAVOR", 
39                    "award_list" => [
40                        [
41                            "stock_id" => "98065001", 
42                            "original_image_url" => "https://tool.oschina.net/regex.jpg", 
43                            "thumbnail_url" => "https://tool.oschina.net/regex.jpg", 
44                        ],
45                    ],
46                    "merchant_option" => "MANUAL_INPUT_MERCHANT", 
47                    "merchant_id_list" => [
48                        "0" => "10000022", 
49                        "1" => "10000023", 
50                    ],
51                ],
52                "advanced_setting" => [
53                    "delivery_user_category" => "DELIVERY_MEMBER_PERSON", 
54                    "merchant_member_appid" => "34567890", 
55                    "goods_tags" => [
56                        "0" => "xxx", 
57                        "1" => "yyy", 
58                    ],
59                ]
60            ],
61            'headers' => [ 'Accept' => 'application/json' ]
62        ]
63    );
64    $statusCode = $resp->getStatusCode();
65    if ($statusCode == 200) { //处理成功
66        echo "success,return body = " . $resp->getBody()->getContents()."\n";
67    } else if ($statusCode == 204) { //处理成功,无返回Body
68        echo "success";
69    }
70} catch (RequestException $e) {
71    // 进行错误处理
72    echo $e->getMessage()."\n";
73    if ($e->hasResponse()) {
74        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
75    }
76    return;
77}

重要入参说明

  • activity_name:活动名称

  • activity_second_title:活动副标题

  • merchant_logo_url:商户logo,送出优惠券时展示, 仅支持通过《图片上传API》接口获取的图片URL地址。

  • out_request_no:商户请求单号,商户创建批次凭据号(格式:商户ID+日期+流水号),商户侧需保持唯一性,可包含英文字母,数字,|,_,*,-等内容,不允许出现其他不合法符号。

  • delivery_purpose:投放目的。枚举值:
    OFF_LINE_PAY:拉用户回店消费
    JUMP_MINI_APP:引导用户前往小程序消费

  • send_content:发放内容,可选单张券或礼包,选礼包时奖品限定3-5个。枚举值:
    SINGLE_COUPON:单张券
    GIFT_PACKAGE:礼包

更多参数、响应详情及错误码请参见创建全场满额送活动接口文档

3.2.2. 【服务端】查询活动详情接口

步骤说明:商户创建活动后,可以通过该接口查询支付有礼的活动详情,用于管理活动。

Java

1示例代码
2public void QueryActivity() throws Exception{
3    //请求URL
4    HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/activities/10028001");
5    httpGet.setHeader("Accept", "application/json");
6    //完成签名并执行请求
7    CloseableHttpResponse response = httpClient.execute(httpGet);
8    try {
9        int statusCode = response.getStatusLine().getStatusCode();
10        if (statusCode == 200) { //处理成功
11            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
12        } else if (statusCode == 204) { //处理成功,无返回Body
13            System.out.println("success");
14        } else {
15            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
16            throw new IOException("request failed");
17        }
18    } finally {
19        response.close();
20    }
21}

PHP

1示例代码
2  try {
3    $resp = $client->request(
4        'GET',
5        'https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/activities/10028001', //请求URL
6        [
7            'headers' => [ 'Accept' => 'application/json']
8        ]
9    );
10    $statusCode = $resp->getStatusCode();
11    if ($statusCode == 200) { //处理成功
12        echo "success,return body = " . $resp->getBody()->getContents()."\n";
13    } else if ($statusCode == 204) { //处理成功,无返回Body
14        echo "success";
15    }
16} catch (RequestException $e) {
17    // 进行错误处理
18    echo $e->getMessage()."\n";
19    if ($e->hasResponse()) {
20        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
21    }
22    return;
23}

重要入参说明

  • activity_id:活动ID

更多参数、响应详情及错误码请参见获取活动详情接口接口文档。

3.2.3. 【服务端】获取活动发券商户号

步骤说明:商户创建活动后,可以通过该接口查询支付有礼的发券商户号,用于管理活动。

Java

1示例代码
2public void QueryActivityMch() throws Exception{
3    //请求URL
4    HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/activities/10028001/merchants");
5    httpGet.setHeader("Accept", "application/json");
6    //完成签名并执行请求
7    CloseableHttpResponse response = httpClient.execute(httpGet);
8    try {
9        int statusCode = response.getStatusLine().getStatusCode();
10        if (statusCode == 200) { //处理成功
11            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
12        } else if (statusCode == 204) { //处理成功,无返回Body
13            System.out.println("success");
14        } else {
15            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
16            throw new IOException("request failed");
17        }
18    } finally {
19        response.close();
20    }
21}

PHP

1示例代码
2  try {
3    $resp = $client->request(
4        'GET',
5        'https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/activities/10028001/merchants', //请求URL
6        [
7            'headers' => [ 'Accept' => 'application/json']
8        ]
9    );
10    $statusCode = $resp->getStatusCode();
11    if ($statusCode == 200) { //处理成功
12        echo "success,return body = " . $resp->getBody()->getContents()."\n";
13    } else if ($statusCode == 204) { //处理成功,无返回Body
14        echo "success";
15    }
16} catch (RequestException $e) {
17    // 进行错误处理
18    echo $e->getMessage()."\n";
19    if ($e->hasResponse()) {
20        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
21    }
22    return;
23}

重要入参说明

  • activity_id:活动ID

更多参数、响应详情及错误码请参见获取活动发券商户号接口文档。

3.2.4. 【服务端】获取活动指定商品列表

步骤说明:商户创建活动后,可以通过该接口查询支付有礼的活动指定商品,用于管理活动。

Java

1示例代码
2public void QueryActivityGoods() throws Exception{
3    //请求URL
4    HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/activities/10028001/goods");
5    httpGet.setHeader("Accept", "application/json");
6    //完成签名并执行请求
7    CloseableHttpResponse response = httpClient.execute(httpGet);
8    try {
9        int statusCode = response.getStatusLine().getStatusCode();
10        if (statusCode == 200) { //处理成功
11            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
12        } else if (statusCode == 204) { //处理成功,无返回Body
13            System.out.println("success");
14        } else {
15            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
16            throw new IOException("request failed");
17        }
18    } finally {
19        response.close();
20    }
21}

PHP

1示例代码
2  try {
3    $resp = $client->request(
4        'GET',
5        'https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/activities/10028001/goods', //请求URL
6        [
7            'headers' => [ 'Accept' => 'application/json']
8        ]
9    );
10    $statusCode = $resp->getStatusCode();
11    if ($statusCode == 200) { //处理成功
12        echo "success,return body = " . $resp->getBody()->getContents()."\n";
13    } else if ($statusCode == 204) { //处理成功,无返回Body
14        echo "success";
15    }
16} catch (RequestException $e) {
17    // 进行错误处理
18    echo $e->getMessage()."\n";
19    if ($e->hasResponse()) {
20        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
21    }
22    return;
23}

重要入参说明

  • activity_id:活动ID

更多参数、响应详情及错误码请参见获取活动指定商品列表接口文档。

3.2.5. 【服务端】终止活动

步骤说明:商户可通过该接口停止支付有礼活动。

Java

1示例代码
2public void TerminateActivity() throws Exception{
3    //请求URL
4    HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/activities/10028001/terminate");
5    // 请求body参数
6    String reqdata ="";
7    StringEntity entity = new StringEntity(reqdata,"utf-8");
8    entity.setContentType("application/json");
9    httpPost.setEntity(entity);
10    httpPost.setHeader("Accept", "application/json");
11    //完成签名并执行请求
12    CloseableHttpResponse response = httpClient.execute(httpPost);
13    try {
14        int statusCode = response.getStatusLine().getStatusCode();
15        if (statusCode == 200) { //处理成功
16            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
17        } else if (statusCode == 204) { //处理成功,无返回Body
18            System.out.println("success");
19        } else {
20            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
21            throw new IOException("request failed");
22        }
23    } finally {
24        response.close();
25    }
26}

PHP

1示例代码
2  try {
3    $resp = $client->request(
4        'POST',
5        'https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/activities/10028001/terminate', //请求URL
6         [
7            'headers' => [ 
8                'Accept' => 'application/json',
9                'Content-Type'=>'application/json'
10            ]
11        ]
12    );
13    $statusCode = $resp->getStatusCode();
14    if ($statusCode == 200) { //处理成功
15        echo "success,return body = " . $resp->getBody()->getContents()."\n";
16    } else if ($statusCode == 204) { //处理成功,无返回Body
17        echo "success";
18    }
19} catch (RequestException $e) {
20    // 进行错误处理
21    echo $e->getMessage()."\n";
22    if ($e->hasResponse()) {
23        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
24    }
25    return;
26}

重要入参说明

  • activity_id:活动ID

更多参数、响应详情及错误码请参见终止活动接口文档。

3.2.6. 【服务端】新增活动发券商户号

步骤说明:商户创建活动后,可以通过该接口增加支付有礼的发券商户号,用于管理活动。

Java

1示例代码
2public void GetActivityList() throws Exception{
3  // 加载商户私钥(privateKey:私钥字符串)
4  PrivateKey merchantPrivateKey = PemUtil
5          .loadPrivateKey(new ByteArrayInputStream(privateKey.getBytes("utf-8")));
6  // 加载平台证书(mchId:商户号,mchSerialNo:商户证书序列号,apiV3Key:V3秘钥)
7  AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
8          new WechatPay2Credentials(mchId, new PrivateKeySigner(mchSerialNo, merchantPrivateKey)),apiV3Key.getBytes("utf-8"));
9  CloseableHttpClient httpClient = HttpClients.createDefault();
10  // 初始化httpClient
11  httpClient = WechatPayHttpClientBuilder.create()
12          .withMerchant(mchId, mchSerialNo, merchantPrivateKey)
13          .withValidator(new WechatPay2Validator(verifier)).build();
14  //请求URL
15  HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/activities/10028001/merchants/add");
16  // 请求body参数
17  String reqdata = "{"
18          + "\"merchant_id_list\": ["
19          + "\"100123456\","
20          + "\"100123457\""
21          + "],"
22          + "\"add_request_no\":\"100002322019090134234sfdf\""
23          + "}";
24  StringEntity entity = new StringEntity(reqdata,"utf-8");
25  entity.setContentType("application/json");
26  httpPost.setEntity(entity);
27  httpPost.setHeader("Accept", "application/json");
28  //完成签名并执行请求
29  CloseableHttpResponse response = httpClient.execute(httpPost);
30  try {
31      int statusCode = response.getStatusLine().getStatusCode();
32      if (statusCode == 200) { //处理成功
33          System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
34      } else if (statusCode == 204) { //处理成功,无返回Body
35          System.out.println("success");
36      } else {
37          System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
38          throw new IOException("request failed");
39      }
40  } finally {
41      response.close();
42  }
43}

PHP

1示例代码
2  try {
3    $resp = $client->request(
4        'POST',
5        'https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/activities/10028001/merchants/add', //请求URL
6        [
7            // JSON请求体
8            'json' => [
9                "merchant_id_list" => [
10                    "0" => "100123456", 
11                    "1" => "100123457", 
12                ],
13                "add_request_no" => "100002322019090134234sfdf",
14            ],
15            'headers' => [ 'Accept' => 'application/json' ]
16        ]
17    );
18    $statusCode = $resp->getStatusCode();
19    if ($statusCode == 200) { //处理成功
20        echo "success,return body = " . $resp->getBody()->getContents()."\n";
21    } else if ($statusCode == 204) { //处理成功,无返回Body
22        echo "success";
23    }
24} catch (RequestException $e) {
25    // 进行错误处理
26    echo $e->getMessage()."\n";
27    if ($e->hasResponse()) {
28        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
29    }
30    return;
31}

重要入参说明

  • activity_id:活动ID

  • add_request_no:请求业务单据号,商户添加发券商户号的凭据号,商户侧需保持唯一性

更多参数、响应详情及错误码请参见新增活动发券商户号接口文档。

3.2.7. 【服务端】获取支付有礼活动列表

步骤说明:商户根据一定过滤条件,查询已创建的支付有礼活动。

Java

1示例代码
2public void GetActivityList() throws Exception{
3  // 加载商户私钥(privateKey:私钥字符串)
4  PrivateKey merchantPrivateKey = PemUtil
5          .loadPrivateKey(new ByteArrayInputStream(privateKey.getBytes("utf-8")));
6  // 加载平台证书(mchId:商户号,mchSerialNo:商户证书序列号,apiV3Key:V3秘钥)
7  AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
8          new WechatPay2Credentials(mchId, new PrivateKeySigner(mchSerialNo, merchantPrivateKey)),apiV3Key.getBytes("utf-8"));
9  CloseableHttpClient httpClient = HttpClients.createDefault();
10  // 初始化httpClient
11  httpClient = WechatPayHttpClientBuilder.create()
12          .withMerchant(mchId, mchSerialNo, merchantPrivateKey)
13          .withValidator(new WechatPay2Validator(verifier)).build();
14  //请求URL
15  HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/activities?offset=0&limit=10&activity_status=ONGOING_ACT_STATUS");
16  httpGet.setHeader("Accept", "application/json");
17  //完成签名并执行请求
18  CloseableHttpResponse response = httpClient.execute(httpGet);
19  try {
20      int statusCode = response.getStatusLine().getStatusCode();
21      if (statusCode == 200) { //处理成功
22          System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
23      } else if (statusCode == 204) { //处理成功,无返回Body
24          System.out.println("success");
25      } else {
26          System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
27          throw new IOException("request failed");
28      }
29  } finally {
30      response.close();
31  }
32}

PHP

1示例代码
2  try {
3    $resp = $client->request(
4        'GET',
5        'https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/activities?offset=0&limit=10&activity_status=ONGOING_ACT_STATUS', //请求URL
6        [
7            'headers' => [ 'Accept' => 'application/json']
8        ]
9    );
10    $statusCode = $resp->getStatusCode();
11    if ($statusCode == 200) { //处理成功
12        echo "success,return body = " . $resp->getBody()->getContents()."\n";
13    } else if ($statusCode == 204) { //处理成功,无返回Body
14        echo "success";
15    }
16} catch (RequestException $e) {
17    // 进行错误处理
18    echo $e->getMessage()."\n";
19    if ($e->hasResponse()) {
20        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
21    }
22    return;
23}

重要入参说明

  • offset:分页页码,页面从0开始

  • limit:分页大小。特殊规则:最大取值为100,最小为1

更多参数、响应详情及错误码请参见获取支付有礼活动列表接口文档。

3.2.8. 【服务端】删除活动发券商户号

步骤说明:商户创建活动后,可以通过该接口删除支付有礼的发券商户号,用于管理活动。

Java

1示例代码
2public void DelActivityMch() throws Exception{
3  // 加载商户私钥(privateKey:私钥字符串)
4  PrivateKey merchantPrivateKey = PemUtil
5          .loadPrivateKey(new ByteArrayInputStream(privateKey.getBytes("utf-8")));
6  // 加载平台证书(mchId:商户号,mchSerialNo:商户证书序列号,apiV3Key:V3秘钥)
7  AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
8          new WechatPay2Credentials(mchId, new PrivateKeySigner(mchSerialNo, merchantPrivateKey)),apiV3Key.getBytes("utf-8"));
9  CloseableHttpClient httpClient = HttpClients.createDefault();
10  // 初始化httpClient
11  httpClient = WechatPayHttpClientBuilder.create()
12          .withMerchant(mchId, mchSerialNo, merchantPrivateKey)
13          .withValidator(new WechatPay2Validator(verifier)).build();
14  //请求URL
15  HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/activities/126002309/merchants/delete");
16  // 请求body参数
17  String reqdata = "{"
18          + "\"merchant_id_list\": ["
19          + "\"100123456\","
20          + "\"100123457\""
21          + "],"
22          + "\"delete_request_no\":\"100002322019090134234sfdf\""
23          + "}";
24  StringEntity entity = new StringEntity(reqdata,"utf-8");
25  entity.setContentType("application/json");
26  httpPost.setEntity(entity);
27  httpPost.setHeader("Accept", "application/json");
28  //完成签名并执行请求
29  CloseableHttpResponse response = httpClient.execute(httpPost);
30  try {
31      int statusCode = response.getStatusLine().getStatusCode();
32      if (statusCode == 200) { //处理成功
33          System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
34      } else if (statusCode == 204) { //处理成功,无返回Body
35          System.out.println("success");
36      } else {
37          System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
38          throw new IOException("request failed");
39      }
40  } finally {
41      response.close();
42  }
43}

PHP

1示例代码
2  try {
3    $resp = $client->request(
4        'POST',
5        'https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/activities/126002309/merchants/delete', //请求URL
6        [
7            // JSON请求体
8            'json' => [
9                "merchant_id_list" => [
10                    "0" => "100123456", 
11                    "1" => "100123457", 
12                ],
13                "delete_request_no" => "100002322019090134234sfdf",
14            ],
15            'headers' => [ 'Accept' => 'application/json' ]
16        ]
17    );
18    $statusCode = $resp->getStatusCode();
19    if ($statusCode == 200) { //处理成功
20        echo "success,return body = " . $resp->getBody()->getContents()."\n";
21    } else if ($statusCode == 204) { //处理成功,无返回Body
22        echo "success";
23    }
24} catch (RequestException $e) {
25    // 进行错误处理
26    echo $e->getMessage()."\n";
27    if ($e->hasResponse()) {
28        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
29    }
30    return;
31}

重要入参说明

  • activity_id:活动ID

更多参数、响应详情及错误码请参见删除活动发券商户号接口文档。

4. 常见问题

Q:支付有礼创建全场满额送活动API返回“发券商户号校验失败,请核实是否满足同品牌等规则”

A:支付有礼活动的曝光商户号必须是商家券归属商户号的同品牌。同品牌商户号是指同一企业/集团/品牌/公司旗下,如果存在多个微信支付商户号,该企业/集团/品牌/公司可以授权财付通支付科技有限公司将其旗下的多个商户号创建为同品牌商户号组合。主要用于更便利使用免充值营销产品功能,包括开通产品权限、配置组合内商户号为可用商户、配置活动后可用商户免审核等。

Q:支付有礼创建全场满额送活动API返回“商家券信息不满足活动规则,请核实券有效期或code”

A:支付有礼中投放批次的校验,请按照以下几点排查。

  1. 单张券/券包中所有的券开始时间需早于支付有礼活动的开始时间,结束时间需晚于支付有礼的结束时间;

  2. 如果批次为上传code模式,需先上传code再投放到支付有礼 ;

  3. 添加券包时,库存、限领和归属商户号需要保持一致;

  4. 曝光商户号、批次的归属商户号需要全部为同品牌。

Q:支付有礼创建全场满额送活动API,开始时间和结束时间描述的“最长可以配置1年内的活动”中的“1年”如何计算?

A:间隔需要小于31536000s,即需要小于365天。

Q:支付有礼创建全场满额送活动API上传了merchant_id_list字段,接着调用了获取支付有礼活动列表API,并没有merchant_id_list返回,该字段在什么情况下才返回?

A:查询活动发券商户号API才会有这个字段返回,接口文档地址。

Q:支付有礼发放商家券,用户领券没有收到领券事件通知OpenID

A:请检查对应的批次,调用创建商家券接口时是否有设置事件通知AppID参数(notify_appid)。

Q:配置使用「立即使用」跳转商家小程序的能力时,有什么需要注意的地方?

A:在小程序支付场景下,当用户从支付有礼活动落地页点击「立即使用」跳转至商家小程序时,建议不处理小程序调起支付的回调结果。