视频一区二区三区自拍_千金肉奴隷1985未删减版在线观看_国产成人黄色视频在线播放_少女免费播放片高清在线观看_国产精品v欧美精品v

商戶進件
特約商戶進件
基礎(chǔ)支付
JSAPI支付
APP支付
H5支付
Native支付
小程序支付
合單支付
付款碼支付
經(jīng)營能力
支付即服務(wù)
點金計劃
行業(yè)方案
平臺收付通
智慧商圈
微信支付分停車服務(wù)
電子發(fā)票
營銷工具
代金券
商家券
委托營銷
支付有禮
小程序發(fā)券插件
H5發(fā)券
圖片上傳(營銷專用)
現(xiàn)金紅包
資金應(yīng)用
分賬
連鎖品牌分賬
風(fēng)險合規(guī)
商戶開戶意愿確認
消費者投訴2.0
商戶平臺處置通知
其他能力
圖片上傳
視頻上傳
微信支付平臺證書

商家券開發(fā)指引

1. 接口規(guī)則

為了在保證支付安全的前提下,帶給商戶簡單、一致且易用的開發(fā)體驗,我們推出了全新的微信支付APIv3接口。該版本API的具體規(guī)則請參考“APIv3接口規(guī)則

2. 開發(fā)準備

2.1. 搭建和配置開發(fā)環(huán)境

為了幫助開發(fā)者調(diào)用開放接口,我們提供了JAVA、PHP、GO三種語言版本的開發(fā)庫,封裝了簽名生成、簽名驗證、敏感信息加/解密、媒體文件上傳等基礎(chǔ)功能(更多語言版本的開發(fā)庫將在近期陸續(xù)提供

測試步驟

1、根據(jù)自身開發(fā)語言,選擇對應(yīng)的開發(fā)庫并構(gòu)建項目,具體配置請參考下面鏈接的詳細說明:

    ? wechatpay-java(推薦)wechatpay-apache-httpclient,適用于Java開發(fā)者。

    ? wechatpay-php(推薦)、wechatpay-guzzle-middleware,適用于PHP開發(fā)者

    注:當前開發(fā)指引接口PHP示例代碼采用wechatpay-guzzle-middleware版本

    ? wechatpay-go,適用于Go開發(fā)者

更多資源可前往微信支付開發(fā)者社區(qū)搜索查看

2、創(chuàng)建加載商戶私鑰、加載平臺證書、初始化httpClient的通用方法


@Before
public void setup() throws IOException {
    // 加載商戶私鑰(privateKey:私鑰字符串)
    PrivateKey merchantPrivateKey = PemUtil
            .loadPrivateKey(new ByteArrayInputStream(privateKey.getBytes("utf-8")));
 
    // 加載平臺證書(mchId:商戶號,mchSerialNo:商戶證書序列號,apiV3Key:V3密鑰)
    AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
            new WechatPay2Credentials(mchId, new PrivateKeySigner(mchSerialNo, merchantPrivateKey)),apiV3Key.getBytes("utf-8"));
 
    // 初始化httpClient
    httpClient = WechatPayHttpClientBuilder.create()
            .withMerchant(mchId, mchSerialNo, merchantPrivateKey)
            .withValidator(new WechatPay2Validator(verifier)).build();
}
 
@After
public void after() throws IOException {
    httpClient.close();
}

use GuzzleHttp\Exception\RequestException;
use WechatPay\GuzzleMiddleware\WechatPayMiddleware;
use WechatPay\GuzzleMiddleware\Util\PemUtil;
use GuzzleHttp\HandlerStack;
 
// 商戶相關(guān)配置,
$merchantId = '1000100'; // 商戶號
$merchantSerialNumber = 'XXXXXXXXXX'; // 商戶API證書序列號
$merchantPrivateKey = PemUtil::loadPrivateKey('./path/to/mch/private/key.pem'); // 商戶私鑰文件路徑
 
// 微信支付平臺配置
$wechatpayCertificate = PemUtil::loadCertificate('./path/to/wechatpay/cert.pem'); // 微信支付平臺證書文件路徑
 
// 構(gòu)造一個WechatPayMiddleware
$wechatpayMiddleware = WechatPayMiddleware::builder()
    ->withMerchant($merchantId, $merchantSerialNumber, $merchantPrivateKey) // 傳入商戶相關(guān)配置
    ->withWechatPay([ $wechatpayCertificate ]) // 可傳入多個微信支付平臺證書,參數(shù)類型為array
    ->build();
 
// 將WechatPayMiddleware添加到Guzzle的HandlerStack中
$stack = GuzzleHttp\HandlerStack::create();
$stack->push($wechatpayMiddleware, 'wechatpay');
 
// 創(chuàng)建Guzzle HTTP Client時,將HandlerStack傳入,接下來,正常使用Guzzle發(fā)起API請求,WechatPayMiddleware會自動地處理簽名和驗簽
$client = new GuzzleHttp\Client(['handler' => $stack]);

/*
    Package core 微信支付api v3 go http-client 基礎(chǔ)庫,你可以使用它來創(chuàng)建一個client,并向微信支付發(fā)送http請求
    只需要你在初始化客戶端的時候,傳遞credential以及validator
    credential用來生成http header中的authorization信息
    validator則用來校驗回包是否被篡改
    如果http請求返回的err為nil,一般response.Body 都不為空,你可以嘗試對其進行序列化
    請注意及時關(guān)閉response.Body
    注意:使用微信支付apiv3 go庫需要引入相關(guān)的包,該示例代碼必須引入的包名有以下信息

    "context"
    "crypto/x509"
    "fmt"
    "io/ioutil"
    "log"
    "github.com/wechatpay-apiv3/wechatpay-go/core"
    "github.com/wechatpay-apiv3/wechatpay-go/core/option"
    "github.com/wechatpay-apiv3/wechatpay-go/utils"

    */
func SetUp() (opt []option.ClientOption, err error) {
    //商戶號
    mchID := ""
    //商戶證書序列號
    mchCertSerialNumber := ""
    //商戶私鑰文件路徑
    privateKeyPath := ""
    //平臺證書文件路徑
    wechatCertificatePath := ""

    // 加載商戶私鑰
    privateKey, err := utils.LoadPrivateKeyWithPath(privateKeyPath)
    if err != nil {
        log.Printf("load private err:%s", err.Error())
        return nil, err
    }
    // 加載微信支付平臺證書
    wechatPayCertificate, err := utils.LoadCertificateWithPath(wechatCertificatePath)
    if err != nil {
        log.Printf("load certificate err:%s",err)
        return nil, err
    }
    //設(shè)置header頭中authorization信息
    opts := []option.ClientOption{
        option.WithMerchant(mchID, mchCertSerialNumber, privateKey), // 設(shè)置商戶相關(guān)配置
        option.WithWechatPay([]*x509.Certificate{wechatPayCertificate}), // 設(shè)置微信支付平臺證書,用于校驗回包信息用
    }
    return opts, nil
}

3、基于接口的示例代碼,替換請求參數(shù)后可發(fā)起測試

說明:

? 上面的開發(fā)庫為微信支付官方開發(fā)庫,其它沒有審核或者控制下的第三方工具和庫,微信支付不保證它們的安全性和可靠性

通過包管理工具引入SDK后,可根據(jù)下面每個接口的示例代碼替換相關(guān)參數(shù)后進行快速測試

? 開發(fā)者如果想詳細了解簽名生成、簽名驗證、敏感信息加/解密、媒體文件上傳等常用方法的具體代碼實現(xiàn),可閱讀下面的詳細說明:

    1.簽名生成

    2.簽名驗證

    3.敏感信息加解密

    4.merchantPrivateKey(私鑰)

    5.wechatpayCertificates(平臺證書)

    6.APIV3Key(V3 key)

? 如想更詳細的了解我們的接口規(guī)則,可查看我們的接口規(guī)則指引文檔

2.2. 業(yè)務(wù)開發(fā)配置

2.2.1. 開通營銷事件推送能力

? 開通營銷事件推送能力說明

a. 用于設(shè)置接收商家券相關(guān)事件通知的URL,可接收商家券相關(guān)的事件通知、包括發(fā)放通知等。需要設(shè)置接收通知的URL,并在服務(wù)商平臺開通營銷事件推送的能力,即可接收到相關(guān)通知。

b. 營銷事件推送:點擊開通產(chǎn)品權(quán)限。 由商家券批次創(chuàng)建方登錄Pay平臺,操作開通

3. 快速接入

3.1. 業(yè)務(wù)流程圖

業(yè)務(wù)流程時序圖:


重點步驟說明:

步驟1 商戶發(fā)起創(chuàng)建商家券請求,可通過《創(chuàng)建商家券》接口創(chuàng)建商家券,微信支付生成商家券批次后并返回商家券批次號給到商戶。
請求參數(shù)商戶logo(merchant_url)的內(nèi)容要求使用圖片上傳(營銷專用)接口上傳后獲取

步驟4.2 商戶獲取到商家券批次號,需要調(diào)用《小程序發(fā)券插件》來發(fā)放商戶券,并獲取微信支付返回商家券發(fā)放結(jié)果。

步驟7.2 商戶發(fā)券成功后,商戶可通過《查詢商家券詳情》、《根據(jù)過濾條件查詢用戶券》、《查詢用戶券詳情》等商家券管理接口進行券管理,商戶需核銷用戶券時,可通過調(diào)用《核銷用戶券》來核銷用戶微信卡包中具體某一張商家券。

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

文檔展示了如何使用微信支付服務(wù)端 SDK 快速接入商家券產(chǎn)品,完成與微信支付對接的部分。

注意

  • 文檔中的代碼示例是用來闡述 API 基本使用方法,代碼中的示例參數(shù)需替換成商戶自己賬號及請求參數(shù)才能跑通
  • 以下接入步驟僅提供參考,請商戶結(jié)合自身業(yè)務(wù)需求進行評估、修改。
3.2.1. 【服務(wù)端】創(chuàng)建商家券

步驟說明:通過此接口可為有需求的商戶創(chuàng)建商家券。當前支持創(chuàng)建的商家券類型包含滿減券、換購券和折扣券三種。

示例代碼


public void CreateBusiStocks() throws Exception{
    //請求URL
    HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks");
    // 請求body參數(shù)
    String reqdata = "{"
                + "\"stock_name\":\"8月1日活動券\","
                + "\"belong_merchant\":\"1900008361\","
                + "\"comment\":\"活動使用\","
                + "\"goods_name\":\"填寫代金券可適用的商品或服務(wù)\","
                + "\"stock_type\":\"NORMAL\","
                + "\"coupon_use_rule\": {"
                + "\"coupon_available_time\": {"
                + "\"available_begin_time\":\"2021-04-20T13:29:35+08:00\","
                + "\"available_end_time\":\"2021-04-25T13:29:35+08:00\","
                + "\"available_day_after_receive\":3,"
                + "\"wait_days_after_receive\":7"
                + "},"
                + "\"fixed_normal_coupon\": {"
                + "\"discount_amount\":5,"
                + "\"transaction_minimum\":100"
                + "},"
                + "\"use_method\":\"OFF_LINE\""
                + "},"
                + "\"stock_send_rule\": {"
                + "\"max_coupons\":100,"
                + "\"max_coupons_per_user\":5,"
                + "\"max_coupons_by_day\":100,"
                + "\"natural_person_limit\":false,"
                + "\"prevent_api_abuse\":false,"
                + "\"transferable\":false,"
                + "\"shareable\":false"
                + "},"
                + "\"out_request_no\":\"100002322019090134234sfdf\","
                + "\"coupon_code_mode\":\"WECHATPAY_MODE\""
                + "}";
    StringEntity entity = new StringEntity(reqdata,"utf-8");
    entity.setContentType("application/json");
    httpPost.setEntity(entity);
    httpPost.setHeader("Accept", "application/json");

    //完成簽名并執(zhí)行請求
    CloseableHttpResponse response = httpClient.execute(httpPost);

    try {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) { //處理成功
            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
        } else if (statusCode == 204) { //處理成功,無返回Body
            System.out.println("success");
        } else {
            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
            throw new IOException("request failed");
        }
    } finally {
        response.close();
    }
}

try {
    $resp = $client->request(
        'POST',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks', //請求URL
        [
            // JSON請求體
            'json' => [
                "stock_name" => "8月1日活動券",
                "belong_merchant" => "10000098",
                "comment" => "活動使用",
                "goods_name" => "填寫代金券可適用的商品或服務(wù)",
                "stock_type" => "NORMAL",
                "coupon_use_rule" => [
                    "coupon_available_time" => [
                        "available_begin_time" => "2015-05-20T13:29:35+08:00",
                        "available_end_time" => "2015-05-20T13:29:35+08:00",
                        "available_day_after_receive" => 3,
                        "wait_days_after_receive" => 7,
                        "available_week" => [
                            "week_day" => [
                                "0" => 1,
                                "1" => 2,
                            ],
                            "available_day_time" => [
                                [
                                    "begin_time" => 3600,
                                    "end_time" => 86399,
                                ],
                            ],
                        ],
                        "irregulary_avaliable_time" => [
                            [
                                "begin_time" => "2015-05-20T13:29:35+08:00",
                                "end_time" => "2015-05-20T13:29:35+08:00",
                            ],
                        ],
                    ],
                    "fixed_normal_coupon" => [
                        "discount_amount" => 5,
                        "transaction_minimum" => 100,
                    ],
                    "use_method" => "OFF_LINE",
                    "mini_programs_appid" => "wx23232232323",
                    "mini_programs_path" => "/path/index/index",
                ],
                "stock_send_rule" => [
                    "max_coupons" => 100,
                    "max_coupons_per_user" => 5,
                    "max_coupons_by_day" => 100,
                    "natural_person_limit" => false,
                    "prevent_api_abuse" => false,
                    "transferable" => false,
                    "shareable" => false,
                ],
                "out_request_no" => "100002322019090134234sfdf",
                "custom_entrance" => [
                    "mini_programs_info" => [
                        "mini_programs_appid" => "wx234545656765876",
                        "mini_programs_path" => "/path/index/index",
                        "entrance_words" => "歡迎選購",
                        "guiding_words" => "獲取更多優(yōu)惠",
                    ],
                    "appid" => "wx324345hgfhfghfg",
                    "hall_id" => "233455656",
                    "store_id" => "233554655",
                ],
                "display_pattern_info" => [
                    "description" => "xxx門店可用",
                    "merchant_logo_url" => "https://xxx",
                    "merchant_name" => "微信支付",
                    "background_color" => "Color020",
                    "coupon_image_url" => "https://qpic.cn/xxx",
                ],
                "coupon_code_mode" => "WECHATPAY_MODE",
            ],
            'headers' => [ 'Accept' => 'application/json' ]
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func CreateBusiStocks() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
   //設(shè)置請求地址
 URL := "https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks"
  //設(shè)置請求信息,此處也可以使用結(jié)構(gòu)體來進行請求
  mapInfo := map[string]interface{}{
    "stock_name": "8月1日活動券",
    "belong_merchant": "10000098",
    "comment": "活動使用",
    "goods_name": "填寫代金券可適用的商品或服務(wù)",
    "stock_type": "NORMAL",
    "coupon_use_rule": map[string]interface{}{
      "coupon_available_time": map[string]interface{}{
        "available_begin_time": "2015-05-20T13:29:35+08:00",
        "available_end_time": "2015-05-20T13:29:35+08:00",
        "available_day_after_receive": 3,
        "wait_days_after_receive": 7,
     },
      "fixed_normal_coupon": map[string]interface{}{
        "discount_amount": 5,
        "transaction_minimum": 100,
     },
      "use_method": "OFF_LINE",
    },
    "stock_send_rule": map[string]interface{}{
      "max_coupons": 100,
      "max_coupons_per_user": 5,
      "max_coupons_by_day": 100,
      "natural_person_limit": false,
      "prevent_api_abuse": false,
      "transferable": false,
      "shareable": false,
    },
    "out_request_no": "100002322019090134234sfdf",
    "coupon_code_mode": "WECHATPAY_MODE",
  }

  // 發(fā)起請求
  response, err := client.Post(ctx, URL, mapInfo)
  if err != nil{
    log.Printf("client post err:%s",err)
    return
  }
  // 校驗回包內(nèi)容是否有邏輯錯誤
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 讀取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
    

重要入?yún)⒄f明

? belong_merchant:批次歸屬商戶號,批次歸屬于哪個商戶。服務(wù)商模式填寫為子商戶號,間連模式填寫為子商戶號

? out_request_no:商戶請求單號,商戶創(chuàng)建批次憑據(jù)號(格式:商戶id+日期+流水號),商戶側(cè)需保持唯一性。

? max_coupons: 批次最大發(fā)放個數(shù),批次最大可發(fā)放個數(shù)限制。特殊規(guī)則:取值范圍 1 ≤ value ≤ 1000000000

? notify_appid:事件通知appid,用于回調(diào)通知時,計算返回操作用戶的openid(諸如領(lǐng)券用戶),支持小程序or公眾號的APPID;如該字段不填寫,則回調(diào)通知中涉及到用戶身份信息的openid與unionid都將為空。

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 創(chuàng)建商家券接口文檔

3.2.2. 【服務(wù)端】查詢商家券詳情

步驟說明:商戶可通過該接口查詢已創(chuàng)建的商家券批次詳情信息。

示例代碼


public void GetBusiStocksInfo() throws Exception{
    //請求URL
    HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/1212");
    httpGet.setHeader("Accept", "application/json");

    //完成簽名并執(zhí)行請求
    CloseableHttpResponse response = httpClient.execute(httpGet);

    try {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) { //處理成功
            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
        } else if (statusCode == 204) { //處理成功,無返回Body
            System.out.println("success");
        } else {
            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
            throw new IOException("request failed");
        }
    } finally {
        response.close();
    }
}

try {
    $resp = $client->request(
        'GET',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/1212', //請求URL
        [
            'headers' => [ 'Accept' => 'application/json']
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func GetBusiStocksInfo() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
   //設(shè)置請求地址
   URL := "https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/1212"
  // 發(fā)起請求
  response, err := client.Get(ctx, URL)
  if err != nil{
    log.Printf("client get err:%s",err)
    return
  }
  // 校驗回包內(nèi)容是否有邏輯錯誤
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 讀取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
}
    

重要入?yún)⒄f明

? stock_id:批次號,微信為每個商家券批次分配的唯一ID

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 查詢商家券詳情接口文檔

3.2.3. 【服務(wù)端】核銷用戶券

步驟說明:在用戶滿足優(yōu)惠門檻后,服務(wù)商可通過該接口核銷用戶微信卡包中具體某一張商家券。

示例代碼


public void SetBusiStockUse() throws Exception{
    //請求URL
    HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/use");
    // 請求body參數(shù)
    String reqdata = "{"
            + "\"coupon_code\":\"sxxe34343434\","
            + "\"stock_id\":\"100088\","
            + "\"appid\":\"wx1234567889999\","
            + "\"use_time\":\"2015-05-20T13:29:35+08:00\","
            + "\"use_request_no\":\"1002600620019090123143254435\","
            + "\"openid\":\"xsd3434454567676\""
            + "}";
    StringEntity entity = new StringEntity(reqdata,"utf-8");
    entity.setContentType("application/json");
    httpPost.setEntity(entity);
    httpPost.setHeader("Accept", "application/json");

    //完成簽名并執(zhí)行請求
    CloseableHttpResponse response = httpClient.execute(httpPost);

    try {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) { //處理成功
            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
        } else if (statusCode == 204) { //處理成功,無返回Body
            System.out.println("success");
        } else {
            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
            throw new IOException("request failed");
        }
    } finally {
        response.close();
    }
}

try {
    $resp = $client->request(
        'POST',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/use', //請求URL
        [
            // JSON請求體
            'json' => [
                "coupon_code" => "sxxe34343434",
                "stock_id" => "100088",
                "appid" => "wx1234567889999",
                "use_time" => "2015-05-20T13:29:35+08:00",
                "use_request_no" => "1002600620019090123143254435",
                "openid" => "xsd3434454567676",
            ],
            'headers' => [ 'Accept' => 'application/json' ]
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func SetBusiStockUse() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
    //設(shè)置請求地址
  URL := "https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/use"
  //設(shè)置請求信息,此處也可以使用結(jié)構(gòu)體來進行請求
  mapInfo := map[string]interface{}{
    "coupon_code": "sxxe34343434",
    "stock_id": "100088",
    "appid": "wx1234567889999",
    "use_time": "2015-05-20T13:29:35+08:00",
    "use_request_no": "1002600620019090123143254435",
    "openid": "xsd3434454567676",
  }

  // 發(fā)起請求
  response, err := client.Post(ctx, URL, mapInfo)
  if err != nil{
    log.Printf("client post err:%s",err)
    return
  }
  // 校驗回包內(nèi)容是否有邏輯錯誤
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 讀取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
    

重要入?yún)⒄f明

? coupon_code:券code,券的唯一標識。

? appid:公眾賬號ID,支持傳入與當前調(diào)用接口商戶號有綁定關(guān)系的appid。支持小程序appid與公眾號appid。核銷接口返回的openid會在該傳入appid下進行計算獲得。

? use_request_no:核銷請求單據(jù)號,每次核銷請求的唯一標識,商戶需保證唯一。

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 核銷用戶券接口文檔

3.2.4. 【服務(wù)端】根據(jù)過濾條件查詢用戶券

步驟說明:商戶自定義篩選條件(如創(chuàng)建商戶號、歸屬商戶號、發(fā)放商戶號等),查詢指定微信用戶卡包中滿足對應(yīng)條件的所有商家券信息。

示例代碼


public void FilterUserStocks() throws Exception{
    //請求URL
    HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/marketing/busifavor/users/o4GgauInH_RCEdvrrNGrntXDu6D4/coupons?appid=wx233544546545989&stock_id=9865000&coupon_state=USED&creator_merchant=1000000001&offset=0&limit=20");
    httpGet.setHeader("Accept", "application/json");

    //完成簽名并執(zhí)行請求
    CloseableHttpResponse response = httpClient.execute(httpGet);

    try {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) { //處理成功
            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
        } else if (statusCode == 204) { //處理成功,無返回Body
            System.out.println("success");
        } else {
            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
            throw new IOException("request failed");
        }
    } finally {
        response.close();
    }
}

try {
    $resp = $client->request(
        'GET',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/users/o4GgauInH_RCEdvrrNGrntXDu6D4/coupons?appid=wx233544546545989&stock_id=9865000&coupon_state=USED&creator_merchant=1000000001&offset=0&limit=20', //請求URL
        [
            'headers' => [ 'Accept' => 'application/json']
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func FilterUserStocks() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
   //設(shè)置請求地址
   URL := "https://api.mch.weixin.qq.com/v3/marketing/busifavor/users/2323dfsdf342342/coupons?appid=wx233544546545989&stock_id=9865000&coupon_state=USED&creator_merchant=1000000001&offset=0&limit=20"
  // 發(fā)起請求
  response, err := client.Get(ctx, URL)
  if err != nil{
    log.Printf("client get err:%s",err)
    return
  }
  // 校驗回包內(nèi)容是否有邏輯錯誤
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 讀取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
}
    

重要入?yún)⒄f明

? openid:用戶標識,Openid信息,用戶在appid下的唯一標識。

? appid:公眾賬號ID,支持傳入與當前調(diào)用接口商戶號有綁定關(guān)系的appid。支持小程序appid與公眾號appid。

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 根據(jù)過濾條件查詢用戶券接口文檔

3.2.5. 【服務(wù)端】查詢用戶單張券詳情

步驟說明:服務(wù)商可通過該接口查詢微信用戶卡包中某一張商家券的詳情信息。

示例代碼


public void FilterUserStocks() throws Exception{
    //請求URL
    HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/marketing/busifavor/users/o4GgauInH_RCEdvrrNGrntXDu6D4/coupons/123446565767/appids/wx233544546545989");
    httpGet.setHeader("Accept", "application/json");

    //完成簽名并執(zhí)行請求
    CloseableHttpResponse response = httpClient.execute(httpGet);

    try {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) { //處理成功
            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
        } else if (statusCode == 204) { //處理成功,無返回Body
            System.out.println("success");
        } else {
            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
            throw new IOException("request failed");
        }
    } finally {
        response.close();
    }
}

try {
    $resp = $client->request(
        'GET',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/users/o4GgauInH_RCEdvrrNGrntXDu6D4/coupons/123446565767/appids/wx233544546545989', //請求URL
        [
            'headers' => [ 'Accept' => 'application/json']
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func FilterUserStocks() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
   //設(shè)置請求地址
   URL := "https://api.mch.weixin.qq.com/v3/marketing/busifavor/users/2323dfsdf342342/coupons/123446565767/appids/wx233544546545989"
  // 發(fā)起請求
  response, err := client.Get(ctx, URL)
  if err != nil{
    log.Printf("client get err:%s",err)
    return
  }
  // 校驗回包內(nèi)容是否有邏輯錯誤
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 讀取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
}
    

重要入?yún)⒄f明

? coupon_code:券code,券的唯一標識。

? openid:用戶標識,Openid信息,用戶在appid下的唯一標識。

? appid:公眾賬號ID,支持傳入與當前調(diào)用接口商戶號有綁定關(guān)系的appid。支持小程序appid與公眾號appid。

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 查詢用戶單張券詳情接口文檔

3.2.6. 【服務(wù)端】上傳預(yù)存code

步驟說明:商家券的Code碼可由微信后臺隨機分配,同時支持商戶自定義。如商家已有自己的優(yōu)惠券系統(tǒng),可直接使用自定義模式。即商家預(yù)先向微信支付上傳券Code,當券在發(fā)放時,微信支付自動從已導(dǎo)入的Code中隨機取值(不能指定),派發(fā)給用戶。

示例代碼


public void UploadBusiStockCodes() throws Exception{
    //請求URL
    HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/98065001/couponcodes");
    // 請求body參數(shù)
    String reqdata = "{"
            + "\"coupon_code_list\": ["
            + "\"0\":\"ABC9588200\","
            + "\"1\":\"ABC9588201\""
            + "],"
            + "\"upload_request_no\":\"100002322019090134234sfdf\""
            + "}";
    StringEntity entity = new StringEntity(reqdata,"utf-8");
    entity.setContentType("application/json");
    httpPost.setEntity(entity);
    httpPost.setHeader("Accept", "application/json");

    //完成簽名并執(zhí)行請求
    CloseableHttpResponse response = httpClient.execute(httpPost);

    try {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) { //處理成功
            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
        } else if (statusCode == 204) { //處理成功,無返回Body
            System.out.println("success");
        } else {
            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
            throw new IOException("request failed");
        }
    } finally {
        response.close();
    }
}

try {
    $resp = $client->request(
        'POST',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/98065001/couponcodes', //請求URL
        [
            // JSON請求體
            'json' => [
                "coupon_code_list" => [
                    "0" => "ABC9588200",
                    "1" => "ABC9588201",
                ],
                "upload_request_no" => "100002322019090134234sfdf",
            ],
            'headers' => [ 'Accept' => 'application/json' ]
        ]

    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func UploadBusiStockCodes() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
 //設(shè)置請求地址
  URL := "https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/{stock_id}/couponcodes"
  //設(shè)置請求信息,此處也可以使用結(jié)構(gòu)體來進行請求
  mapInfo := map[string]interface{}{
    "coupon_code_list": []map[string]interface{}{
      "ABC9588200",
      "ABC9588201",
    },
    "upload_request_no": "100002322019090134234sfdf",
  }

  // 發(fā)起請求
  response, err := client.Post(ctx, URL, mapInfo)
  if err != nil{
    log.Printf("client post err:%s",err)
    return
  }
  // 校驗回包內(nèi)容是否有邏輯錯誤
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 讀取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
    

重要入?yún)⒄f明

? stock_id:批次號,微信為每個商家券批次分配的唯一ID

? upload_request_no:請求業(yè)務(wù)單據(jù)號,商戶上傳code的憑據(jù)號,商戶側(cè)需保持唯一性。

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 上傳預(yù)存code接口文檔

3.2.7. 【服務(wù)端】設(shè)置商家券事件通知地址

步驟說明:用于設(shè)置接收商家券相關(guān)事件通知的URL,可接收商家券相關(guān)的事件通知、包括發(fā)放通知等。需要設(shè)置接收通知的URL,并在服務(wù)商平臺開通營銷事件推送的能力,即可接收到相關(guān)通知。

示例代碼


public void SetBusiStockCallback() throws Exception{
    //請求URL
    HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/marketing/busifavor/callbacks");
    // 請求body參數(shù)
    String reqdata = "{"
            + "\"mchid\":\"10000098\","
            + "\"notify_url\":\"http://www.tg885.com\""
            + "}";
    StringEntity entity = new StringEntity(reqdata,"utf-8");
    entity.setContentType("application/json");
    httpPost.setEntity(entity);
    httpPost.setHeader("Accept", "application/json");

    //完成簽名并執(zhí)行請求
    CloseableHttpResponse response = httpClient.execute(httpPost);

    try {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) { //處理成功
            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
        } else if (statusCode == 204) { //處理成功,無返回Body
            System.out.println("success");
        } else {
            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
            throw new IOException("request failed");
        }
    } finally {
        response.close();
    }
}

try {
    $resp = $client->request(
        'POST',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/callbacks', //請求URL
        [
            // JSON請求體
            'json' => [
                "mchid" => "10000098",
                "notify_url" => "http://www.tg885.com",
            ],
            'headers' => [ 'Accept' => 'application/json' ]
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func SetBusiStockCallback() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
   //設(shè)置請求地址
  URL := "https://api.mch.weixin.qq.com/v3/marketing/busifavor/callbacks"
  //設(shè)置請求信息,此處也可以使用結(jié)構(gòu)體來進行請求
  mapInfo := map[string]interface{}{
    "mchid": "10000098",
    "notify_url": "http://www.tg885.com",
  }

  // 發(fā)起請求
  response, err := client.Post(ctx, URL, mapInfo)
  if err != nil{
    log.Printf("client post err:%s",err)
    return
  }
  // 校驗回包內(nèi)容是否有邏輯錯誤
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 讀取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
    

重要入?yún)⒄f明

? notify_url:通知URL地址,商戶提供的用于接收商家券事件通知的url地址,必須支持https。

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 設(shè)置商家券事件通知地址接口文檔

3.2.8. 【服務(wù)端】查詢商家券事件通知地址

步驟說明:通過調(diào)用此接口可查詢設(shè)置的通知URL。

示例代碼


public void QueryBusiStockCallback() throws Exception {

  //請求URL
  HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/marketing/busifavor/callbacks?mchid=10000098");
  httpGet.setHeader("Accept", "application/json");

  //完成簽名并執(zhí)行請求
  CloseableHttpResponse response = httpClient.execute(httpGet);

  try {
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode == 200) { //處理成功
          System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
      } else if (statusCode == 204) { //處理成功,無返回Body
          System.out.println("success");
      } else {
          System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
          throw new IOException("request failed");
      }
  } finally {
      response.close();
  }
}

try {
    $resp = $client->request(
        'GET',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/callbacks?mchid=10000098', //請求URL
        [
            'headers' => [ 'Accept' => 'application/json']
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func QueryBusiStockCallback() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
   //設(shè)置請求地址
   URL := "https://api.mch.weixin.qq.com/v3/marketing/busifavor/callbacks?mchid=10000098"
  // 發(fā)起請求
  response, err := client.Get(ctx, URL)
  if err != nil{
    log.Printf("client get err:%s",err)
    return
  }
  // 校驗回包內(nèi)容是否有邏輯錯誤
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 讀取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
    

重要入?yún)⒄f明

? mchid:商戶號,微信支付商戶的商戶號,由微信支付生成并下發(fā),不填默認查詢調(diào)用方商戶的通知URL。

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 查詢商家券事件通知地址接口文檔

3.2.9. 【服務(wù)端】關(guān)聯(lián)訂單信息

步驟說明:將有效態(tài)(未核銷)的商家券與訂單信息關(guān)聯(lián),用于后續(xù)參與搖獎&返傭激勵等操作的統(tǒng)計。

示例代碼


public void AssociateBusiStockOrder() throws Exception{
    //請求URL
    HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/associate");
    // 請求body參數(shù)
    String reqdata = "{"
            + "\"coupon_code\":\"sxxe34343434\","
            + "\"out_trade_no\":\"MCH_102233445\","
            + "\"stock_id\":\"100088\","
            + "\"out_request_no\":\"1002600620019090123143254435\""
            + "}";
    StringEntity entity = new StringEntity(reqdata,"utf-8");
    entity.setContentType("application/json");
    httpPost.setEntity(entity);
    httpPost.setHeader("Accept", "application/json");

    //完成簽名并執(zhí)行請求
    CloseableHttpResponse response = httpClient.execute(httpPost);

    try {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) { //處理成功
            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
        } else if (statusCode == 204) { //處理成功,無返回Body
            System.out.println("success");
        } else {
            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
            throw new IOException("request failed");
        }
    } finally {
        response.close();
    }
}

try {
    $resp = $client->request(
        'POST',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/associate', //請求URL
        [
            // JSON請求體
            'json' => [
                "coupon_code" => "sxxe34343434",
                "out_trade_no" => "MCH_102233445",
                "stock_id" => "100088",
                "out_request_no" => "1002600620019090123143254435",
            ],
            'headers' => [ 'Accept' => 'application/json' ]
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func AssociateBusiStockOrder() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
   //設(shè)置請求地址
  URL := "https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/associate"
  //設(shè)置請求信息,此處也可以使用結(jié)構(gòu)體來進行請求
  mapInfo := map[string]interface{}{
    "coupon_code": "sxxe34343434",
    "out_trade_no": "MCH_102233445",
    "stock_id": "100088",
    "out_request_no": "1002600620019090123143254435",
  }

  // 發(fā)起請求
  response, err := client.Post(ctx, URL, mapInfo)
  if err != nil{
    log.Printf("client post err:%s",err)
    return
  }
  // 校驗回包內(nèi)容是否有邏輯錯誤
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 讀取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
    

重要入?yún)⒄f明

? stock_id:批次號,微信為每個商家券批次分配的唯一ID

? coupon_code:券code,券的唯一標識。

? out_trade_no:關(guān)聯(lián)的商戶訂單號,微信支付下單時的商戶訂單號,預(yù)與該商家券關(guān)聯(lián)的微信支付

? out_request_no:商戶請求單號,商戶創(chuàng)建批次憑據(jù)號(格式:商戶id+日期+流水號),商戶側(cè)需保持唯一性,可包含英文字母,數(shù)字,|,_,*,-等內(nèi)容,不允許出現(xiàn)其他不合法符號。

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 關(guān)聯(lián)訂單信息接口文檔

3.2.10. 【服務(wù)端】取消關(guān)聯(lián)訂單信息

步驟說明:取消商家券與訂單信息的關(guān)聯(lián)關(guān)系

示例代碼


public void CancelAssociateBusiStockOrder() throws Exception {
//請求URL
  HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/disassociate");
  // 請求body參數(shù)
  String reqdata = "{"
          + "\"coupon_code\":\"213dsadfsa\","
          + "\"out_trade_no\":\"treads8a9f980\","
          + "\"stock_id\":\"100088\","
          + "\"out_request_no\":\"fdsafdsafdsa231321\""
          + "}";
  StringEntity entity = new StringEntity(reqdata,"utf-8");
  entity.setContentType("application/json");
  httpPost.setEntity(entity);
  httpPost.setHeader("Accept", "application/json");

  //完成簽名并執(zhí)行請求
  CloseableHttpResponse response = httpClient.execute(httpPost);

  try {
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode == 200) { //處理成功
          System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
      } else if (statusCode == 204) { //處理成功,無返回Body
          System.out.println("success");
      } else {
          System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
          throw new IOException("request failed");
      }
  } finally {
      response.close();
  }
}

try {
    $resp = $client->request(
        'POST',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/disassociate', //請求URL
        [
            // JSON請求體
            'json' => [
                "coupon_code" => "213dsadfsa",
                "out_trade_no" => "treads8a9f980",
                "stock_id" => "100088",
                "out_request_no" => "fdsafdsafdsa231321",
            ],
            'headers' => [ 'Accept' => 'application/json' ]
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func CancelAssociateBusiStockOrder() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
   //設(shè)置請求地址
  URL := "https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/disassociate"
  //設(shè)置請求信息,此處也可以使用結(jié)構(gòu)體來進行請求
  mapInfo := map[string]interface{}{
    "coupon_code": "213dsadfsa",
    "out_trade_no": "treads8a9f980",
    "stock_id": "100088",
    "out_request_no": "fdsafdsafdsa231321",
  }

  // 發(fā)起請求
  response, err := client.Post(ctx, URL, mapInfo)
  if err != nil{
    log.Printf("client post err:%s",err)
    return
  }
  // 校驗回包內(nèi)容是否有邏輯錯誤
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 讀取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
    

重要入?yún)⒄f明

? stock_id:批次號,微信為每個商家券批次分配的唯一ID

? coupon_code:券code,券的唯一標識。

? out_trade_no:關(guān)聯(lián)的商戶訂單號,微信支付下單時的商戶訂單號,預(yù)與該商家券關(guān)聯(lián)的微信支付

? out_request_no:商戶請求單號,商戶創(chuàng)建批次憑據(jù)號(格式:商戶id+日期+流水號),商戶側(cè)需保持唯一性,可包含英文字母,數(shù)字,|,_,*,-等內(nèi)容,不允許出現(xiàn)其他不合法符號。

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 取消關(guān)聯(lián)訂單信息接口文檔

3.2.11. 【服務(wù)端】修改批次預(yù)算

步驟說明:商戶可以通過該接口修改批次單天發(fā)放上限數(shù)量或者批次最大發(fā)放數(shù)量

示例代碼


public void UpdataBusiStockBudget() throws Exception{
    //請求URL
    HttpPatch httpPatch = new HttpPatch("https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/98065001/budget");
    // 請求body參數(shù)
    String reqdata = "{"
            + "\"target_max_coupons\":3000,"
            + "\"current_max_coupons\":500,"
            + "\"modify_budget_request_no\":\"1002600620019090123143254436\""
            + "}";
    StringEntity entity = new StringEntity(reqdata,"utf-8");
    entity.setContentType("application/json");
    httpPatch.setEntity(entity);
    httpPatch.setHeader("Accept", "application/json");

    //完成簽名并執(zhí)行請求
    CloseableHttpResponse response = httpClient.execute(httpPatch);

    try {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) { //處理成功
            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
        } else if (statusCode == 204) { //處理成功,無返回Body
            System.out.println("success");
        } else {
            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
            throw new IOException("request failed");
        }
    } finally {
        response.close();
    }
}

try {
    $resp = $client->request(
        'PATCH',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/98065001/budget', //請求URL
        [
            // JSON請求體
            'json' => [
                "target_max_coupons" => 3000,
                "current_max_coupons" => 500,
                "modify_budget_request_no" => "1002600620019090123143254436",
            ],
            'headers' => [ 'Accept' => 'application/json' ]
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func UpdataBusiStockBudget() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
   //設(shè)置請求地址
}
    

重要入?yún)⒄f明

? stock_id:批次號,微信為每個商家券批次分配的唯一ID

? modify_budget_request_no:修改預(yù)算請求單據(jù)號(格式:商戶id+日期+流水號),商戶側(cè)需保持唯一性。

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 修改批次預(yù)算接口文檔

3.2.12. 【服務(wù)端】修改商家券基本信息

步驟說明:商戶可以通過該接口修改商家券基本信息

示例代碼


public void UpdataBusiStockInfo() throws Exception{
    //請求URL
    HttpPatch httpPatch = new HttpPatch("https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/101156451224");
    // 請求body參數(shù)
    String reqdata = "{"
            + "\"custom_entrance\": {"
            + "\"mini_programs_info\": {"
            + "\"mini_programs_appid\":\"wx234545656765876\","
            + "\"mini_programs_path\":\"/path/index/index\","
            + "\"entrance_words\":\"歡迎選購\","
            + "\"guiding_words\":\"獲取更多優(yōu)惠\""
            + "},"
            + "\"appid\":\"wx324345hgfhfghfg\","
            + "\"hall_id\":\"233455656\","
            + "\"code_display_mode\":\"BARCODE\""
            + "},"
            + "\"stock_name\":\"8月1日活動券\","
            + "\"comment\":\"活動使用\","
            + "\"goods_name\":\"xxx商品使用\","
            + "\"out_request_no\":\"6122352020010133287985742\","
            + "\"display_pattern_info\": {"
            + "\"description\":\"xxx門店可用\","
            + "\"merchant_logo_url\":\"https://xxx\","
            + "\"merchant_name\":\"微信支付\","
            + "\"background_color\":\"xxxxx\","
            + "\"coupon_image_url\":\"圖片cdn地址\""
            + "},"
            + "\"coupon_use_rule\": {"
            + "\"use_method\":\"OFF_LINE\","
            + "\"mini_programs_appid\":\"wx23232232323\","
            + "\"mini_programs_path\":\"/path/index/index\""
            + "},"
            + "\"stock_send_rule\": {"
            + "\"prevent_api_abuse\":false"
            + "},"
            + "\"notify_config\": {"
            + "\"notify_appid\":\"wx23232232323\""
            + "}"
            + "}";
    StringEntity entity = new StringEntity(reqdata,"utf-8");
    entity.setContentType("application/json");
    httpPatch.setEntity(entity);
    httpPatch.setHeader("Accept", "application/json");

    //完成簽名并執(zhí)行請求
    CloseableHttpResponse response = httpClient.execute(httpPatch);

    try {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) { //處理成功
            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
        } else if (statusCode == 204) { //處理成功,無返回Body
            System.out.println("success");
        } else {
            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
            throw new IOException("request failed");
        }
    } finally {
        response.close();
    }
}

try {
    $resp = $client->request(
        'PATCH',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/101156451224', //請求URL
        [
            // JSON請求體
            'json' => [
                "custom_entrance" => [
                    "mini_programs_info" => [
                        "mini_programs_appid" => "wx234545656765876",
                        "mini_programs_path" => "/path/index/index",
                        "entrance_words" => "歡迎選購",
                        "guiding_words" => "獲取更多優(yōu)惠",
                    ],
                    "appid" => "wx324345hgfhfghfg",
                    "hall_id" => "233455656",
                    "code_display_mode" => "BARCODE",
                ],
                "stock_name" => "8月1日活動券",
                "comment" => "活動使用",
                "goods_name" => "xxx商品使用",
                "out_request_no" => "6122352020010133287985742",
                "display_pattern_info" => [
                    "description" => "xxx門店可用",
                    "merchant_logo_url" => "https://xxx",
                    "merchant_name" => "微信支付",
                    "background_color" => "xxxxx",
                    "coupon_image_url" => "圖片cdn地址",
                ],
                "coupon_use_rule" => [
                    "use_method" => "OFF_LINE",
                    "mini_programs_appid" => "wx23232232323",
                    "mini_programs_path" => "/path/index/index",
                ],
                "stock_send_rule" => [
                    "prevent_api_abuse" => false,
                ],
                "notify_config" => [
                    "notify_appid" => "wx23232232323",
                ]
            ],
            'headers' => [ 'Accept' => 'application/json' ]
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func UpdataBusiStockInfo() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
   //設(shè)置請求地址
}
    

重要入?yún)⒄f明

? stock_id:批次號,微信為每個商家券批次分配的唯一ID

? out_request_no:商戶請求單號,商戶修改批次憑據(jù)號(格式:商戶id+日期+流水號),商戶側(cè)需保持唯一性。

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 修改商家券基本信息接口文檔

3.2.13. 【服務(wù)端】申請退券

步驟說明:商戶可以通過該接口為已核銷的券申請退券

示例代碼


public void ReturnBusiStock() throws Exception{
    //請求URL
    HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/return");
    // 請求body參數(shù)
    String reqdata = "{"
            + "\"coupon_code\":\"sxxe34343434\","
            + "\"stock_id\":\"1234567891\","
            + "\"return_request_no\":\"1002600620019090123143254436\""
            + "}";
    StringEntity entity = new StringEntity(reqdata,"utf-8");
    entity.setContentType("application/json");
    httpPost.setEntity(entity);
    httpPost.setHeader("Accept", "application/json");

    //完成簽名并執(zhí)行請求
    CloseableHttpResponse response = httpClient.execute(httpPost);

    try {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) { //處理成功
            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
        } else if (statusCode == 204) { //處理成功,無返回Body
            System.out.println("success");
        } else {
            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
            throw new IOException("request failed");
        }
    } finally {
        response.close();
    }
}

try {
    $resp = $client->request(
        'POST',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/return', //請求URL
        [
            // JSON請求體
            'json' => [
                "coupon_code" => "sxxe34343434",
                "stock_id" => "1234567891",
                "return_request_no" => "1002600620019090123143254436",
            ],
            'headers' => [ 'Accept' => 'application/json' ]
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func ReturnBusiStock() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
   //設(shè)置請求地址
  URL := "https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/return"
  //設(shè)置請求信息,此處也可以使用結(jié)構(gòu)體來進行請求
  mapInfo := map[string]interface{}{
    "coupon_code": "sxxe34343434",
    "stock_id": "1234567891",
    "return_request_no": "1002600620019090123143254436",
  }

  // 發(fā)起請求
  response, err := client.Post(ctx, URL, mapInfo)
  if err != nil{
    log.Printf("client post err:%s",err)
    return
  }
  // 校驗回包內(nèi)容是否有邏輯錯誤
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 讀取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
    

重要入?yún)⒄f明

? stock_id:批次號,微信為每個商家券批次分配的唯一ID

? coupon_code:券code,券的唯一標識。

? return_request_no:退券請求單據(jù)號,每次退券請求的唯一標識,商戶需保證唯一

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 申請退券接口文檔

3.2.14. 【服務(wù)端】使券失效

步驟說明:商戶可通過該接口將單張領(lǐng)取后未核銷的券進行失效處理

示例代碼


public void DeactivateBusiStock() throws Exception{
    //請求URL
    HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/deactivate");
    // 請求body參數(shù)
    String reqdata = "{"
            + "\"coupon_code\":\"sxxe34343434\","
            + "\"stock_id\":\"1234567891\","
            + "\"deactivate_request_no\":\"1002600620019090123143254436\","
            + "\"deactivate_reason\":\"此券使用時間設(shè)置錯誤\""
            + "}";
    StringEntity entity = new StringEntity(reqdata,"utf-8");
    entity.setContentType("application/json");
    httpPost.setEntity(entity);
    httpPost.setHeader("Accept", "application/json");

    //完成簽名并執(zhí)行請求
    CloseableHttpResponse response = httpClient.execute(httpPost);

    try {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 200) { //處理成功
            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
        } else if (statusCode == 204) { //處理成功,無返回Body
            System.out.println("success");
        } else {
            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
            throw new IOException("request failed");
        }
    } finally {
        response.close();
    }
}

try {
    $resp = $client->request(
        'POST',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/deactivate', //請求URL
        [
            // JSON請求體
            'json' => [
                "coupon_code" => "sxxe34343434",
                "stock_id" => "1234567891",
                "deactivate_request_no" => "1002600620019090123143254436",
                "deactivate_reason" => "此券使用時間設(shè)置錯誤",
            ],
            'headers' => [ 'Accept' => 'application/json' ]
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func DeactivateBusiStock() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
  //設(shè)置請求地址
  URL := "https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/deactivate"
  //設(shè)置請求信息,此處也可以使用結(jié)構(gòu)體來進行請求
  mapInfo := map[string]interface{}{
    "coupon_code": "sxxe34343434",
    "stock_id": "1234567891",
    "deactivate_request_no": "1002600620019090123143254436",
    "deactivate_reason": "此券使用時間設(shè)置錯誤",
  }

  // 發(fā)起請求
  response, err := client.Post(ctx, URL, mapInfo)
  if err != nil{
    log.Printf("client post err:%s",err)
    return
  }
  // 校驗回包內(nèi)容是否有邏輯錯誤
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 讀取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}   

重要入?yún)⒄f明

? stock_id:批次號,微信為每個商家券批次分配的唯一ID

? coupon_code:券code,券的唯一標識。

? deactivate_request_no:失效請求單據(jù)號,每次失效請求的唯一標識,商戶需保證唯一

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 使券失效接口文檔

3.2.15. 【服務(wù)端】營銷補差付款

步驟說明:商戶可以通過該接口給核銷了商家券的商戶做營銷資金補差

示例代碼


public void CreateSubsidyPay() throws Exception {

  //請求URL
  HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/marketing/busifavor/subsidy/pay-receipts");
  // 請求body參數(shù)
  String reqdata = "{"
          + "\"stock_id\":\"128888000000001\","
          + "\"coupon_code\":\"ABCD12345678\","
          + "\"transaction_id\":\"4200000913202101152566792388\","
          + "\"payer_merchant\":\"1900000001\","
          + "\"payee_merchant\":\"1900000002\","
          + "\"amount\":100,"
          + "\"description\":\"20210115DESCRIPTION\","
          + "\"out_subsidy_no\":\"subsidy-abcd-12345678\""
          + "}";
  StringEntity entity = new StringEntity(reqdata,"utf-8");
  entity.setContentType("application/json");
  httpPost.setEntity(entity);
  httpPost.setHeader("Accept", "application/json");

  //完成簽名并執(zhí)行請求
  CloseableHttpResponse response = httpClient.execute(httpPost);

  try {
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode == 200) { //處理成功
          System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
      } else if (statusCode == 204) { //處理成功,無返回Body
          System.out.println("success");
      } else {
          System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
          throw new IOException("request failed");
      }
  } finally {
      response.close();
  }
}

try {
    $resp = $client->request(
        'POST',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/subsidy/pay-receipts', //請求URL
        [
            // JSON請求體
            'json' => [
                "stock_id" => "128888000000001",
                "coupon_code" => "ABCD12345678",
                "transaction_id" => "4200000913202101152566792388",
                "payer_merchant" => "1900000001",
                "payee_merchant" => "1900000002",
                "amount" => 100,
                "description" => "20210115DESCRIPTION",
                "out_subsidy_no" => "subsidy-abcd-12345678",
            ],
            'headers' => [ 'Accept' => 'application/json' ]
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func CreateSubsidyPay() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
   //設(shè)置請求地址
}
    

重要入?yún)⒄f明

? stock_id:批次號,微信為每個商家券批次分配的唯一ID

? coupon_code:券code,券的唯一標識。

? deactivate_request_no:失效請求單據(jù)號,每次失效請求的唯一標識,商戶需保證唯一

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 營銷補差付款接口文檔

3.2.16. 【服務(wù)端】查詢營銷補差付款單詳情

步驟說明:商戶可以通過該接口查詢商家券營銷補差付款單詳情

示例代碼


public void QuerySubsidyPay() throws Exception {

  //請求URL
  HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/marketing/busifavor/subsidy/pay-receipts/1120200119165100000000000001");
  httpGet.setHeader("Accept", "application/json");

  //完成簽名并執(zhí)行請求
  CloseableHttpResponse response = httpClient.execute(httpGet);

  try {
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode == 200) { //處理成功
          System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
      } else if (statusCode == 204) { //處理成功,無返回Body
          System.out.println("success");
      } else {
          System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
          throw new IOException("request failed");
      }
  } finally {
      response.close();
  }
}


try {
    $resp = $client->request(
        'GET',
        'https://api.mch.weixin.qq.com/v3/marketing/busifavor/subsidy/pay-receipts/1120200119165100000000000001', //請求URL
        [
            'headers' => [ 'Accept' => 'application/json']
        ]
    );
    $statusCode = $resp->getStatusCode();
    if ($statusCode == 200) { //處理成功
        echo "success,return body = " . $resp->getBody()->getContents()."\n";
    } else if ($statusCode == 204) { //處理成功,無返回Body
        echo "success";
    }
} catch (RequestException $e) {
    // 進行錯誤處理
    echo $e->getMessage()."\n";
    if ($e->hasResponse()) {
        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
    }
    return;
}
      

func QuerySubsidyPay() {
       // 初始化客戶端
    ctx := context.TODO()
    opts, err := SetUp()
    if err != nil {
        return
    }
    client, err := core.NewClient(ctx, opts...,)
    if err != nil{
        log.Printf("init client err:%s",err)
        return
    }
   //設(shè)置請求地址
   URL := "https://api.mch.weixin.qq.com/v3/marketing/busifavor/subsidy/pay-receipts/1120200119165100000000000001"
  // 發(fā)起請求
  response, err := client.Get(ctx, URL)
  if err != nil{
    log.Printf("client get err:%s",err)
    return
  }
  // 校驗回包內(nèi)容是否有邏輯錯誤
  err = core.CheckResponse(response)
  if err != nil{
    log.Printf("check response err:%s",err)
    return
  }
  // 讀取回包信息
  body, err := ioutil.ReadAll(response.Body)
  if err != nil{
    log.Printf("read response body err:%s",err)
    return
  }
  fmt.Println(string(body))
}
    

重要入?yún)⒄f明

? stock_id:批次號,微信為每個商家券批次分配的唯一ID

? coupon_code:券code,券的唯一標識。

? deactivate_request_no:失效請求單據(jù)號,每次失效請求的唯一標識,商戶需保證唯一

注意

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 查詢營銷補差付款單詳情接口文檔

3.2.17.【服務(wù)端】領(lǐng)券事件回調(diào)通知

步驟說明:領(lǐng)券完成后,微信會把相關(guān)領(lǐng)券結(jié)果和用戶信息發(fā)送給商戶,商戶需要接收處理,并按照文檔規(guī)范返回應(yīng)答。出于安全的考慮,我們對支付結(jié)果數(shù)據(jù)進行了加密,商戶需要先對通知數(shù)據(jù)進行解密,才能得到支付結(jié)果數(shù)據(jù)。

注意

  • 領(lǐng)券事件通知是以POST 方法訪問商戶設(shè)置的通知url,通知的數(shù)據(jù)以JSON 格式通過請求主體(BODY)傳輸。通知的數(shù)據(jù)包括了加密的支付結(jié)果詳情
  • 加密不能保證通知請求來自微信。微信會對發(fā)送給商戶的通知進行簽名,并將簽名值放在通知的HTTP頭Wechatpay-Signature。商戶應(yīng)當驗證簽名,以確認請求來自微信,而不是其他的第三方。簽名驗證的算法請參考 《微信支付API v3簽名驗證》
  • 支付通知http應(yīng)答碼為200或204才會當作正常接收,當回調(diào)處理異常時,應(yīng)答的HTTP狀態(tài)碼應(yīng)為500,或者4xx
  • 商戶成功接收到回調(diào)通知后應(yīng)返回成功的http應(yīng)答碼為200或204
  • 同樣的通知可能會多次發(fā)送給商戶系統(tǒng)。商戶系統(tǒng)必須能夠正確處理重復(fù)的通知。 推薦的做法是,當商戶系統(tǒng)收到通知進行處理時,先檢查對應(yīng)業(yè)務(wù)數(shù)據(jù)的狀態(tài),并判斷該通知是否已經(jīng)處理。如果未處理,則再進行處理;如果已處理,則直接返回結(jié)果成功。在對業(yè)務(wù)數(shù)據(jù)進行狀態(tài)檢查和處理之前,要采用數(shù)據(jù)鎖進行并發(fā)控制,以避免函數(shù)重入造成的數(shù)據(jù)混亂
  • 對后臺通知交互時,如果微信收到應(yīng)答不是成功或超時,微信認為通知失敗,微信會通過一定的策略定期重新發(fā)起通知,盡可能提高通知的成功率,但微信不保證通知最終能成功。(通知頻率為60s/次 - 總計11次 )

更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 領(lǐng)券事件回調(diào)通知支付通知API接口文檔

4. 常見問題

Q:調(diào)用創(chuàng)建商家券接口返回“非法敏感圖片”

A:請求參數(shù)商戶logo(merchant_url)的內(nèi)容要求使用圖片上傳(營銷專用)接口上傳后獲取,請檢查確認。

Q:創(chuàng)建商家券接口,goods_name字段展示在哪里?

A:展示在商家券詳情里面的優(yōu)惠說明中

Q:調(diào)用修改商家券基本信息API返回:無法將輸入源“/body/stock_id”映射到目標字段“批次號”中,此字段并非多重字段但被輸入源“/uri_template/stock_id”映射過了

A:請注意參數(shù)stock_id傳到請求url里面,body里面就不用傳該參數(shù)

Q:商家券領(lǐng)券回調(diào),正常設(shè)置地址,為什么接收不到回調(diào)信息?

A:請按以下幾點檢查

1. 請檢查是否有正確設(shè)置apiv3。設(shè)置步驟如下: 【微信服務(wù)商平臺—>賬戶設(shè)置—>API安全—>設(shè)置apiv3】

2. 請檢查回調(diào)url是否能正常公網(wǎng)訪問

3. 如果是http地址,建議更換支持https

4. 是否開啟了防火墻,如果開戶了防火墻,請?zhí)砑游⑿胖Ц稜I銷回調(diào)IP:

  • 上海電信出口網(wǎng)段 101.226.103.0/2
  • 上海聯(lián)通出口網(wǎng)段 140.207.54.0/25
  • 上海CAP出口網(wǎng)段 121.51.58.128/25
Q:商家券消費門檻字段transaction_minimum不填寫為什么會報錯?

A:該字段屬于必填字段,可以填寫為0



技術(shù)咨詢

文檔反饋