為了在保證支付安全的前提下,帶給商戶簡單、一致且易用的開發(fā)體驗,我們推出了全新的微信支付APIv3接口。該版本API的具體規(guī)則請參考“APIv3接口規(guī)則”
為了幫助開發(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();
}
3、基于接口的示例代碼,替換請求參數(shù)后可發(fā)起測試
說明:
? 上面的開發(fā)庫為微信支付官方開發(fā)庫,其它沒有審核或者控制下的第三方工具和庫,微信支付不保證它們的安全性和可靠性
通過包管理工具引入SDK后,可根據(jù)下面每個接口的示例代碼替換相關(guān)參數(shù)后進行快速測試
? 開發(fā)者如果想詳細了解簽名生成、簽名驗證、敏感信息加/解密、媒體文件上傳等常用方法的具體代碼實現(xiàn),可閱讀下面的詳細說明:
1.簽名生成
2.簽名驗證
3.敏感信息加解密
? 如想更詳細的了解我們的接口規(guī)則,可查看我們的接口規(guī)則指引文檔
? 開通營銷事件推送能力說明:
a. 用于設(shè)置接收商家券相關(guān)事件通知的URL,可接收商家券相關(guān)的事件通知、包括發(fā)放通知等。需要設(shè)置接收通知的URL,并在服務(wù)商平臺開通營銷事件推送的能力,即可接收到相關(guān)通知。
b. 營銷事件推送:點擊開通產(chǎn)品權(quán)限。 由商家券批次創(chuàng)建方登錄Pay平臺,操作開通
重點步驟說明:
步驟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)用《核銷用戶券》來核銷用戶微信卡包中具體某一張商家券。
文檔展示了如何使用微信支付服務(wù)端 SDK 快速接入商家券產(chǎn)品,完成與微信支付對接的部分。
注意:
步驟說明:通過此接口可為有需求的商戶創(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();
}
}
重要入?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)建商家券接口文檔
步驟說明:商戶可通過該接口查詢已創(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();
}
}
重要入?yún)⒄f明:
? stock_id:批次號,微信為每個商家券批次分配的唯一ID
注意:
更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 查詢商家券詳情接口文檔
步驟說明:在用戶滿足優(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();
}
}
重要入?yún)⒄f明:
? coupon_code:券code,券的唯一標識。
? appid:公眾賬號ID,支持傳入與當前調(diào)用接口商戶號有綁定關(guān)系的appid。支持小程序appid與公眾號appid。核銷接口返回的openid會在該傳入appid下進行計算獲得。
? use_request_no:核銷請求單據(jù)號,每次核銷請求的唯一標識,商戶需保證唯一。
注意:
更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 核銷用戶券接口文檔
步驟說明:商戶自定義篩選條件(如創(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();
}
}
重要入?yún)⒄f明:
? openid:用戶標識,Openid信息,用戶在appid下的唯一標識。
? appid:公眾賬號ID,支持傳入與當前調(diào)用接口商戶號有綁定關(guān)系的appid。支持小程序appid與公眾號appid。
注意:
更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 根據(jù)過濾條件查詢用戶券接口文檔
步驟說明:服務(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();
}
}
重要入?yún)⒄f明:
? coupon_code:券code,券的唯一標識。
? openid:用戶標識,Openid信息,用戶在appid下的唯一標識。
? appid:公眾賬號ID,支持傳入與當前調(diào)用接口商戶號有綁定關(guān)系的appid。支持小程序appid與公眾號appid。
注意:
更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 查詢用戶單張券詳情接口文檔
步驟說明:商家券的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();
}
}
重要入?yún)⒄f明:
? stock_id:批次號,微信為每個商家券批次分配的唯一ID
? upload_request_no:請求業(yè)務(wù)單據(jù)號,商戶上傳code的憑據(jù)號,商戶側(cè)需保持唯一性。
注意:
更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 上傳預(yù)存code接口文檔
步驟說明:用于設(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();
}
}
重要入?yún)⒄f明:
? notify_url:通知URL地址,商戶提供的用于接收商家券事件通知的url地址,必須支持https。
注意:
更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 設(shè)置商家券事件通知地址接口文檔
步驟說明:通過調(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();
}
}
重要入?yún)⒄f明:
? mchid:商戶號,微信支付商戶的商戶號,由微信支付生成并下發(fā),不填默認查詢調(diào)用方商戶的通知URL。
注意:
更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 查詢商家券事件通知地址接口文檔
步驟說明:將有效態(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();
}
}
重要入?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)訂單信息接口文檔
步驟說明:取消商家券與訂單信息的關(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();
}
}
重要入?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)訂單信息接口文檔
步驟說明:商戶可以通過該接口修改批次單天發(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();
}
}
重要入?yún)⒄f明:
? stock_id:批次號,微信為每個商家券批次分配的唯一ID
? modify_budget_request_no:修改預(yù)算請求單據(jù)號(格式:商戶id+日期+流水號),商戶側(cè)需保持唯一性。
注意:
更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 修改批次預(yù)算接口文檔
步驟說明:商戶可以通過該接口修改商家券基本信息
示例代碼:
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();
}
}
重要入?yún)⒄f明:
? stock_id:批次號,微信為每個商家券批次分配的唯一ID
? out_request_no:商戶請求單號,商戶修改批次憑據(jù)號(格式:商戶id+日期+流水號),商戶側(cè)需保持唯一性。
注意:
更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 修改商家券基本信息接口文檔
步驟說明:商戶可以通過該接口為已核銷的券申請退券
示例代碼:
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();
}
}
重要入?yún)⒄f明:
? stock_id:批次號,微信為每個商家券批次分配的唯一ID
? coupon_code:券code,券的唯一標識。
? return_request_no:退券請求單據(jù)號,每次退券請求的唯一標識,商戶需保證唯一
注意:
更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 申請退券接口文檔
步驟說明:商戶可通過該接口將單張領(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();
}
}
重要入?yún)⒄f明:
? stock_id:批次號,微信為每個商家券批次分配的唯一ID
? coupon_code:券code,券的唯一標識。
? deactivate_request_no:失效請求單據(jù)號,每次失效請求的唯一標識,商戶需保證唯一
注意:
更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 使券失效接口文檔
步驟說明:商戶可以通過該接口給核銷了商家券的商戶做營銷資金補差
示例代碼:
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();
}
}
重要入?yún)⒄f明:
? stock_id:批次號,微信為每個商家券批次分配的唯一ID
? coupon_code:券code,券的唯一標識。
? deactivate_request_no:失效請求單據(jù)號,每次失效請求的唯一標識,商戶需保證唯一
注意:
更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 營銷補差付款接口文檔
步驟說明:商戶可以通過該接口查詢商家券營銷補差付款單詳情
示例代碼:
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();
}
}
重要入?yún)⒄f明:
? stock_id:批次號,微信為每個商家券批次分配的唯一ID
? coupon_code:券code,券的唯一標識。
? deactivate_request_no:失效請求單據(jù)號,每次失效請求的唯一標識,商戶需保證唯一
注意:
更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 查詢營銷補差付款單詳情接口文檔
步驟說明:領(lǐng)券完成后,微信會把相關(guān)領(lǐng)券結(jié)果和用戶信息發(fā)送給商戶,商戶需要接收處理,并按照文檔規(guī)范返回應(yīng)答。出于安全的考慮,我們對支付結(jié)果數(shù)據(jù)進行了加密,商戶需要先對通知數(shù)據(jù)進行解密,才能得到支付結(jié)果數(shù)據(jù)。
注意:
更多參數(shù)、響應(yīng)詳情及錯誤碼請參見 領(lǐng)券事件回調(diào)通知支付通知API接口文檔
A:請求參數(shù)商戶logo(merchant_url)的內(nèi)容要求使用圖片上傳(營銷專用)接口上傳后獲取,請檢查確認。
A:展示在商家券詳情里面的優(yōu)惠說明中
A:請注意參數(shù)stock_id傳到請求url里面,body里面就不用傳該參數(shù)
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:
A:該字段屬于必填字段,可以填寫為0