创建全场满额送活动
更新时间:2024.11.18使用场景:商户可以创建满额送活动,用户支付后送全场券,提升交易额。
可调用商户:商户/服务商/渠道商
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/marketing/paygiftactivity/unique-threshold-activity
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
Content-Type 必填 string
请设置为application/json
body 包体参数
activity_base_info 必填 object
【活动基本信息】用于创建活动的基本信息
属性 | |||||||||||||
activity_name 必填 string(10) 【活动名称】活动名称 activity_second_title 必填 string(9) 【活动副标题】活动副标题 merchant_logo_url 必填 string(128) 【商户logo】商户logo,送出优惠券时展示 background_color 选填 string 【背景颜色】代金券的背景颜色,可设置10种颜色,颜色取值可参考开发指引 3.2.1 background_color取值,默认为微信支付绿色, 颜色取值为颜色图中的颜色名称。 begin_time 必填 string(32) 【活动开始时间】活动开始时间,最长可以配置1年内的活动,活动有效期最长90天 end_time 必填 string(32) 【活动结束时间】活动结束时间,最长可以配置1年内的活动,活动有效期最长90天 available_periods 选填 object 【可用时间段】可自定义活动有效时间内可用的多个时间段以及天内时间点
out_request_no 必填 string(128) 【商户请求单号】商户创建批次凭据号(格式:商户id+日期+流水号),商户侧需保持唯一性,可包含英文字母,数字,|,_,*,-等内容,不允许出现其他不合法符号 delivery_purpose 必填 string 【投放目的】OFF_LINE_PAY:拉用户回店消费;JUMP_MINI_APP:引导用户前往小程序消费 可选取值:
mini_programs_appid 选填 string(32) 【商家小程序appid】投放目的为跳转小程序时必填 mini_programs_path 选填 string(128) 【商家小程序path】投放目的为跳转小程序必填 |
award_send_rule 必填 object
【活动奖品发放规则】满送活动规则
属性 | |||||
transaction_amount_minimum 必填 integer 【消费金额门槛】消费金额门槛 单位分 send_content 必填 string 【发放内容】发放内容,可选单张券或礼包,选礼包时奖品限定3-5个 可选取值:
award_type 必填 string 【奖品类型】奖品类型,暂时只支持商家券 可选取值:
award_list 必填 array[object] 【奖品基本信息列表】奖品基本信息列表
merchant_option 必填 string 【发券商户号选项】发券商户号选取规则,支持选择在用券商户或手动输入商户号两种,选择手动时,发券商户号必填(商家券只支持手动输入) 可选取值:
merchant_id_list 选填 array[string(15)] 【发券商户号】发券商户号,列表 |
advanced_setting 选填 object
【活动高级设置】其他高级配置项
属性 | |||||||||
delivery_user_category 选填 string 【投放用户类别】DELIVERY_ALL_PERSON:所有用户;DELIVERY_MEMBER_PERSON:会员用户 可选取值:
merchant_member_appid 选填 string(32) 【商家会员appid】当投放用户类别为会员用户时必填 payment_mode 选填 object 【支付模式】主要用于指定可用的支付场景,不限制支付模式不填,限制选填(商家券暂不开放)
payment_method_information 选填 object 【支付方式信息】支付方式信息,不填为不限制(商家券暂不开放)
goods_tags 选填 array[string(15)] 【订单优惠标记】商户下单时需要传入相同的标记(goods_tag),用户同时符合其他规则才能享受优惠 |
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/marketing/paygiftactivity/unique-threshold-activity \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "activity_base_info" : { 8 "activity_name" : "良品铺子回馈活动", 9 "activity_second_title" : "海飞丝的券", 10 "merchant_logo_url" : "https://tool.oschina.net/regex.jpg", 11 "background_color" : "Color010", 12 "begin_time" : "2015-05-20T13:29:35.120+08:00", 13 "end_time" : "2015-05-20T13:29:35.120+08:00", 14 "available_periods" : { 15 "available_time" : [ 16 { 17 "begin_time" : "2015-05-20T00:00:00.000+08:00", 18 "end_time" : "2015-05-20T23:59:59.000+08:00" 19 } 20 ], 21 "available_day_time" : [ 22 { 23 "begin_day_time" : "110000", 24 "end_day_time" : "135959" 25 } 26 ] 27 }, 28 "out_request_no" : "100002322019090134234sfdf", 29 "delivery_purpose" : "OFF_LINE_PAY", 30 "mini_programs_appid" : "wx23232232323", 31 "mini_programs_path" : "/path/index/index" 32 }, 33 "award_send_rule" : { 34 "transaction_amount_minimum" : 100, 35 "send_content" : "SINGLE_COUPON", 36 "award_type" : "BUSIFAVOR", 37 "award_list" : [ 38 { 39 "stock_id" : "98065001", 40 "original_image_url" : "https://tool.oschina.net/regex.jpg", 41 "thumbnail_url" : "https://tool.oschina.net/regex.jpg" 42 } 43 ], 44 "merchant_option" : "IN_SEVICE_COUPON_MERCHANT", 45 "merchant_id_list" : [ 46 "10000022" 47 ] 48 }, 49 "advanced_setting" : { 50 "delivery_user_category" : "DELIVERY_ALL_PERSON", 51 "merchant_member_appid" : "34567890", 52 "payment_mode" : { 53 "payment_scene_list" : [ 54 "APP_SCENE" 55 ] 56 }, 57 "payment_method_information" : { 58 "payment_method" : "CFT", 59 "bank_abbreviation" : "AHRCUB_CREDIT" 60 }, 61 "goods_tags" : [ 62 "xxx" 63 ] 64 } 65 }' 66
需配合微信支付工具库 WXPayUtility 使用,请参考Java
1package com.java.demo; 2 3import com.java.utils.WXPayUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/v3/partner/4014985777 4 5import com.google.gson.annotations.SerializedName; 6import com.google.gson.annotations.Expose; 7import okhttp3.MediaType; 8import okhttp3.OkHttpClient; 9import okhttp3.Request; 10import okhttp3.RequestBody; 11import okhttp3.Response; 12 13import java.io.IOException; 14import java.io.UncheckedIOException; 15import java.security.PrivateKey; 16import java.security.PublicKey; 17import java.util.ArrayList; 18import java.util.HashMap; 19import java.util.List; 20import java.util.Map; 21 22/** 23 * 创建全场满额送活动 24 */ 25public class CreateFullSendAct { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/marketing/paygiftactivity/unique-threshold-activity"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 CreateFullSendAct client = new CreateFullSendAct( 33 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 34 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 35 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 36 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 37 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 38 ); 39 40 CreateFullSendActRequest request = new CreateFullSendActRequest(); 41 request.activityBaseInfo = new ActBaseInfo(); 42 request.activityBaseInfo.activityName = "良品铺子回馈活动"; 43 request.activityBaseInfo.activitySecondTitle = "海飞丝的券"; 44 request.activityBaseInfo.merchantLogoUrl = "https://tool.oschina.net/regex.jpg"; 45 request.activityBaseInfo.backgroundColor = "Color010"; 46 request.activityBaseInfo.beginTime = "2015-05-20T13:29:35.120+08:00"; 47 request.activityBaseInfo.endTime = "2015-05-20T13:29:35.120+08:00"; 48 request.activityBaseInfo.availablePeriods = new AvailablePeriod(); 49 request.activityBaseInfo.availablePeriods.availableTime = new ArrayList<>(); 50 { 51 AvailableTime availableTimeItem = new AvailableTime(); 52 availableTimeItem.beginTime = "2015-05-20T00:00:00.000+08:00"; 53 availableTimeItem.endTime = "2015-05-20T23:59:59.000+08:00"; 54 request.activityBaseInfo.availablePeriods.availableTime.add(availableTimeItem); 55 }; 56 request.activityBaseInfo.availablePeriods.availableDayTime = new ArrayList<>(); 57 { 58 AvailableDayTime availableDayTimeItem = new AvailableDayTime(); 59 availableDayTimeItem.beginDayTime = "110000"; 60 availableDayTimeItem.endDayTime = "135959"; 61 request.activityBaseInfo.availablePeriods.availableDayTime.add(availableDayTimeItem); 62 }; 63 request.activityBaseInfo.outRequestNo = "100002322019090134234sfdf"; 64 request.activityBaseInfo.deliveryPurpose = DeliveryPurposeCategory.OFF_LINE_PAY; 65 request.activityBaseInfo.miniProgramsAppid = "wx23232232323"; 66 request.activityBaseInfo.miniProgramsPath = "/path/index/index"; 67 request.awardSendRule = new FullSendRule(); 68 request.awardSendRule.transactionAmountMinimum = 100L; 69 request.awardSendRule.sendContent = SendContentCategory.SINGLE_COUPON; 70 request.awardSendRule.awardType = AwardType.BUSIFAVOR; 71 request.awardSendRule.awardList = new ArrayList<>(); 72 { 73 AwardBaseInfo awardListItem = new AwardBaseInfo(); 74 awardListItem.stockId = "98065001"; 75 awardListItem.originalImageUrl = "https://tool.oschina.net/regex.jpg"; 76 awardListItem.thumbnailUrl = "https://tool.oschina.net/regex.jpg"; 77 request.awardSendRule.awardList.add(awardListItem); 78 }; 79 request.awardSendRule.merchantOption = SendMerchantOption.IN_SEVICE_COUPON_MERCHANT; 80 request.awardSendRule.merchantIdList = new ArrayList<>(); 81 { 82 request.awardSendRule.merchantIdList.add("10000022"); 83 }; 84 request.advancedSetting = new ActAdvancedSetting(); 85 request.advancedSetting.deliveryUserCategory = DeliveryUserCategory.DELIVERY_ALL_PERSON; 86 request.advancedSetting.merchantMemberAppid = "34567890"; 87 request.advancedSetting.paymentMode = new PaymentMode(); 88 request.advancedSetting.paymentMode.paymentSceneList = new ArrayList<>(); 89 { 90 request.advancedSetting.paymentMode.paymentSceneList.add(PaymentScene.APP_SCENE); 91 }; 92 request.advancedSetting.paymentMethodInformation = new PaymentMethodInfo(); 93 request.advancedSetting.paymentMethodInformation.paymentMethod = PaymentMethodCategory.CFT; 94 request.advancedSetting.paymentMethodInformation.bankAbbreviation = "AHRCUB_CREDIT"; 95 request.advancedSetting.goodsTags = new ArrayList<>(); 96 { 97 request.advancedSetting.goodsTags.add("xxx"); 98 }; 99 try { 100 CreateFullSendActResponse response = client.run(request); 101 // TODO: 请求成功,继续业务逻辑 102 System.out.println(response); 103 } catch (WXPayUtility.ApiException e) { 104 // TODO: 请求失败,根据状态码执行不同的逻辑 105 e.printStackTrace(); 106 } 107 } 108 109 public CreateFullSendActResponse run(CreateFullSendActRequest request) { 110 String uri = PATH; 111 String reqBody = WXPayUtility.toJson(request); 112 113 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 114 reqBuilder.addHeader("Accept", "application/json"); 115 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 116 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 117 reqBuilder.addHeader("Content-Type", "application/json"); 118 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 119 reqBuilder.method(METHOD, requestBody); 120 Request httpRequest = reqBuilder.build(); 121 122 // 发送HTTP请求 123 OkHttpClient client = new OkHttpClient.Builder().build(); 124 try (Response httpResponse = client.newCall(httpRequest).execute()) { 125 String respBody = WXPayUtility.extractBody(httpResponse); 126 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 127 // 2XX 成功,验证应答签名 128 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 129 httpResponse.headers(), respBody); 130 131 // 从HTTP应答报文构建返回数据 132 return WXPayUtility.fromJson(respBody, CreateFullSendActResponse.class); 133 } else { 134 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 135 } 136 } catch (IOException e) { 137 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 138 } 139 } 140 141 private final String mchid; 142 private final String certificateSerialNo; 143 private final PrivateKey privateKey; 144 private final String wechatPayPublicKeyId; 145 private final PublicKey wechatPayPublicKey; 146 147 public CreateFullSendAct(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 148 this.mchid = mchid; 149 this.certificateSerialNo = certificateSerialNo; 150 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 151 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 152 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 153 } 154 155 public static class CreateFullSendActRequest { 156 @SerializedName("activity_base_info") 157 public ActBaseInfo activityBaseInfo; 158 159 @SerializedName("award_send_rule") 160 public FullSendRule awardSendRule; 161 162 @SerializedName("advanced_setting") 163 public ActAdvancedSetting advancedSetting; 164 } 165 166 public static class CreateFullSendActResponse { 167 @SerializedName("activity_id") 168 public String activityId; 169 170 @SerializedName("create_time") 171 public String createTime; 172 } 173 174 public static class ActBaseInfo { 175 @SerializedName("activity_name") 176 public String activityName; 177 178 @SerializedName("activity_second_title") 179 public String activitySecondTitle; 180 181 @SerializedName("merchant_logo_url") 182 public String merchantLogoUrl; 183 184 @SerializedName("background_color") 185 public String backgroundColor; 186 187 @SerializedName("begin_time") 188 public String beginTime; 189 190 @SerializedName("end_time") 191 public String endTime; 192 193 @SerializedName("available_periods") 194 public AvailablePeriod availablePeriods; 195 196 @SerializedName("out_request_no") 197 public String outRequestNo; 198 199 @SerializedName("delivery_purpose") 200 public DeliveryPurposeCategory deliveryPurpose; 201 202 @SerializedName("mini_programs_appid") 203 public String miniProgramsAppid; 204 205 @SerializedName("mini_programs_path") 206 public String miniProgramsPath; 207 } 208 209 public static class FullSendRule { 210 @SerializedName("transaction_amount_minimum") 211 public Long transactionAmountMinimum; 212 213 @SerializedName("send_content") 214 public SendContentCategory sendContent; 215 216 @SerializedName("award_type") 217 public AwardType awardType; 218 219 @SerializedName("award_list") 220 public List<AwardBaseInfo> awardList = new ArrayList<AwardBaseInfo>(); 221 222 @SerializedName("merchant_option") 223 public SendMerchantOption merchantOption; 224 225 @SerializedName("merchant_id_list") 226 public List<String> merchantIdList; 227 } 228 229 public static class ActAdvancedSetting { 230 @SerializedName("delivery_user_category") 231 public DeliveryUserCategory deliveryUserCategory; 232 233 @SerializedName("merchant_member_appid") 234 public String merchantMemberAppid; 235 236 @SerializedName("payment_mode") 237 public PaymentMode paymentMode; 238 239 @SerializedName("payment_method_information") 240 public PaymentMethodInfo paymentMethodInformation; 241 242 @SerializedName("goods_tags") 243 public List<String> goodsTags; 244 } 245 246 public static class AvailablePeriod { 247 @SerializedName("available_time") 248 public List<AvailableTime> availableTime; 249 250 @SerializedName("available_day_time") 251 public List<AvailableDayTime> availableDayTime; 252 } 253 254 public enum DeliveryPurposeCategory { 255 @SerializedName("OFF_LINE_PAY") 256 OFF_LINE_PAY, 257 @SerializedName("JUMP_MINI_APP") 258 JUMP_MINI_APP 259 } 260 261 public enum SendContentCategory { 262 @SerializedName("SINGLE_COUPON") 263 SINGLE_COUPON, 264 @SerializedName("GIFT_PACKAGE") 265 GIFT_PACKAGE 266 } 267 268 public enum AwardType { 269 @SerializedName("BUSIFAVOR") 270 BUSIFAVOR 271 } 272 273 public static class AwardBaseInfo { 274 @SerializedName("stock_id") 275 public String stockId; 276 277 @SerializedName("original_image_url") 278 public String originalImageUrl; 279 280 @SerializedName("thumbnail_url") 281 public String thumbnailUrl; 282 } 283 284 public enum SendMerchantOption { 285 @SerializedName("IN_SEVICE_COUPON_MERCHANT") 286 IN_SEVICE_COUPON_MERCHANT, 287 @SerializedName("MANUAL_INPUT_MERCHANT") 288 MANUAL_INPUT_MERCHANT 289 } 290 291 public enum DeliveryUserCategory { 292 @SerializedName("DELIVERY_ALL_PERSON") 293 DELIVERY_ALL_PERSON, 294 @SerializedName("DELIVERY_MEMBER_PERSON") 295 DELIVERY_MEMBER_PERSON 296 } 297 298 public static class PaymentMode { 299 @SerializedName("payment_scene_list") 300 public List<PaymentScene> paymentSceneList; 301 } 302 303 public static class PaymentMethodInfo { 304 @SerializedName("payment_method") 305 public PaymentMethodCategory paymentMethod; 306 307 @SerializedName("bank_abbreviation") 308 public String bankAbbreviation; 309 } 310 311 public static class AvailableTime { 312 @SerializedName("begin_time") 313 public String beginTime; 314 315 @SerializedName("end_time") 316 public String endTime; 317 } 318 319 public static class AvailableDayTime { 320 @SerializedName("begin_day_time") 321 public String beginDayTime; 322 323 @SerializedName("end_day_time") 324 public String endDayTime; 325 } 326 327 public enum PaymentScene { 328 @SerializedName("APP_SCENE") 329 APP_SCENE, 330 @SerializedName("SWING_CARD_SCENE") 331 SWING_CARD_SCENE, 332 @SerializedName("NO_SECRET_SCENE") 333 NO_SECRET_SCENE, 334 @SerializedName("MINIAPP_SCENE") 335 MINIAPP_SCENE, 336 @SerializedName("FACE_PAY_SCENE") 337 FACE_PAY_SCENE, 338 @SerializedName("OTHER_SCENE") 339 OTHER_SCENE 340 } 341 342 public enum PaymentMethodCategory { 343 @SerializedName("CFT") 344 CFT, 345 @SerializedName("SPECIFIC_BANK_CARD") 346 SPECIFIC_BANK_CARD 347 } 348 349} 350
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "bytes" 5 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446 6 "encoding/json" 7 "fmt" 8 "net/http" 9 "net/url" 10) 11 12func main() { 13 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 14 config, err := wxpay_utility.CreateMchConfig( 15 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 16 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 17 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 18 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 19 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 20 ) 21 if err != nil { 22 fmt.Println(err) 23 return 24 } 25 26 request := &CreateFullSendActRequest{ 27 ActivityBaseInfo: &ActBaseInfo{ 28 ActivityName: wxpay_utility.String("良品铺子回馈活动"), 29 ActivitySecondTitle: wxpay_utility.String("海飞丝的券"), 30 MerchantLogoUrl: wxpay_utility.String("https://tool.oschina.net/regex.jpg"), 31 BackgroundColor: wxpay_utility.String("Color010"), 32 BeginTime: wxpay_utility.String("2015-05-20T13:29:35.120+08:00"), 33 EndTime: wxpay_utility.String("2015-05-20T13:29:35.120+08:00"), 34 AvailablePeriods: &AvailablePeriod{ 35 AvailableTime: []AvailableTime{AvailableTime{ 36 BeginTime: wxpay_utility.String("2015-05-20T00:00:00.000+08:00"), 37 EndTime: wxpay_utility.String("2015-05-20T23:59:59.000+08:00"), 38 }}, 39 AvailableDayTime: []AvailableDayTime{AvailableDayTime{ 40 BeginDayTime: wxpay_utility.String("110000"), 41 EndDayTime: wxpay_utility.String("135959"), 42 }}, 43 }, 44 OutRequestNo: wxpay_utility.String("100002322019090134234sfdf"), 45 DeliveryPurpose: DELIVERYPURPOSECATEGORY_OFF_LINE_PAY.Ptr(), 46 MiniProgramsAppid: wxpay_utility.String("wx23232232323"), 47 MiniProgramsPath: wxpay_utility.String("/path/index/index"), 48 }, 49 AwardSendRule: &FullSendRule{ 50 TransactionAmountMinimum: wxpay_utility.Int64(100), 51 SendContent: SENDCONTENTCATEGORY_SINGLE_COUPON.Ptr(), 52 AwardType: AWARDTYPE_BUSIFAVOR.Ptr(), 53 AwardList: []AwardBaseInfo{AwardBaseInfo{ 54 StockId: wxpay_utility.String("98065001"), 55 OriginalImageUrl: wxpay_utility.String("https://tool.oschina.net/regex.jpg"), 56 ThumbnailUrl: wxpay_utility.String("https://tool.oschina.net/regex.jpg"), 57 }}, 58 MerchantOption: SENDMERCHANTOPTION_IN_SEVICE_COUPON_MERCHANT.Ptr(), 59 MerchantIdList: []string{"10000022"}, 60 }, 61 AdvancedSetting: &ActAdvancedSetting{ 62 DeliveryUserCategory: DELIVERYUSERCATEGORY_DELIVERY_ALL_PERSON.Ptr(), 63 MerchantMemberAppid: wxpay_utility.String("34567890"), 64 PaymentMode: &PaymentMode{ 65 PaymentSceneList: []PaymentScene{PAYMENTSCENE_APP_SCENE}, 66 }, 67 PaymentMethodInformation: &PaymentMethodInfo{ 68 PaymentMethod: PAYMENTMETHODCATEGORY_CFT.Ptr(), 69 BankAbbreviation: wxpay_utility.String("AHRCUB_CREDIT"), 70 }, 71 GoodsTags: []string{"xxx"}, 72 }, 73 } 74 75 response, err := CreateFullSendAct(config, request) 76 if err != nil { 77 fmt.Printf("请求失败: %+v\n", err) 78 // TODO: 请求失败,根据状态码执行不同的处理 79 return 80 } 81 82 // TODO: 请求成功,继续业务逻辑 83 fmt.Printf("请求成功: %+v\n", response) 84} 85 86func CreateFullSendAct(config *wxpay_utility.MchConfig, request *CreateFullSendActRequest) (response *CreateFullSendActResponse, err error) { 87 const ( 88 host = "https://api.mch.weixin.qq.com" 89 method = "POST" 90 path = "/v3/marketing/paygiftactivity/unique-threshold-activity" 91 ) 92 93 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 94 if err != nil { 95 return nil, err 96 } 97 reqBody, err := json.Marshal(request) 98 if err != nil { 99 return nil, err 100 } 101 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 102 if err != nil { 103 return nil, err 104 } 105 httpRequest.Header.Set("Accept", "application/json") 106 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 107 httpRequest.Header.Set("Content-Type", "application/json") 108 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 109 if err != nil { 110 return nil, err 111 } 112 httpRequest.Header.Set("Authorization", authorization) 113 114 client := &http.Client{} 115 httpResponse, err := client.Do(httpRequest) 116 if err != nil { 117 return nil, err 118 } 119 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 120 if err != nil { 121 return nil, err 122 } 123 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 124 // 2XX 成功,验证应答签名 125 err = wxpay_utility.ValidateResponse( 126 config.WechatPayPublicKeyId(), 127 config.WechatPayPublicKey(), 128 &httpResponse.Header, 129 respBody, 130 ) 131 if err != nil { 132 return nil, err 133 } 134 response := &CreateFullSendActResponse{} 135 if err := json.Unmarshal(respBody, response); err != nil { 136 return nil, err 137 } 138 139 return response, nil 140 } else { 141 return nil, wxpay_utility.NewApiException( 142 httpResponse.StatusCode, 143 httpResponse.Header, 144 respBody, 145 ) 146 } 147} 148 149type CreateFullSendActRequest struct { 150 ActivityBaseInfo *ActBaseInfo `json:"activity_base_info,omitempty"` 151 AwardSendRule *FullSendRule `json:"award_send_rule,omitempty"` 152 AdvancedSetting *ActAdvancedSetting `json:"advanced_setting,omitempty"` 153} 154 155type CreateFullSendActResponse struct { 156 ActivityId *string `json:"activity_id,omitempty"` 157 CreateTime *string `json:"create_time,omitempty"` 158} 159 160type ActBaseInfo struct { 161 ActivityName *string `json:"activity_name,omitempty"` 162 ActivitySecondTitle *string `json:"activity_second_title,omitempty"` 163 MerchantLogoUrl *string `json:"merchant_logo_url,omitempty"` 164 BackgroundColor *string `json:"background_color,omitempty"` 165 BeginTime *string `json:"begin_time,omitempty"` 166 EndTime *string `json:"end_time,omitempty"` 167 AvailablePeriods *AvailablePeriod `json:"available_periods,omitempty"` 168 OutRequestNo *string `json:"out_request_no,omitempty"` 169 DeliveryPurpose *DeliveryPurposeCategory `json:"delivery_purpose,omitempty"` 170 MiniProgramsAppid *string `json:"mini_programs_appid,omitempty"` 171 MiniProgramsPath *string `json:"mini_programs_path,omitempty"` 172} 173 174type FullSendRule struct { 175 TransactionAmountMinimum *int64 `json:"transaction_amount_minimum,omitempty"` 176 SendContent *SendContentCategory `json:"send_content,omitempty"` 177 AwardType *AwardType `json:"award_type,omitempty"` 178 AwardList []AwardBaseInfo `json:"award_list,omitempty"` 179 MerchantOption *SendMerchantOption `json:"merchant_option,omitempty"` 180 MerchantIdList []string `json:"merchant_id_list,omitempty"` 181} 182 183type ActAdvancedSetting struct { 184 DeliveryUserCategory *DeliveryUserCategory `json:"delivery_user_category,omitempty"` 185 MerchantMemberAppid *string `json:"merchant_member_appid,omitempty"` 186 PaymentMode *PaymentMode `json:"payment_mode,omitempty"` 187 PaymentMethodInformation *PaymentMethodInfo `json:"payment_method_information,omitempty"` 188 GoodsTags []string `json:"goods_tags,omitempty"` 189} 190 191type AvailablePeriod struct { 192 AvailableTime []AvailableTime `json:"available_time,omitempty"` 193 AvailableDayTime []AvailableDayTime `json:"available_day_time,omitempty"` 194} 195 196type DeliveryPurposeCategory string 197 198func (e DeliveryPurposeCategory) Ptr() *DeliveryPurposeCategory { 199 return &e 200} 201 202const ( 203 DELIVERYPURPOSECATEGORY_OFF_LINE_PAY DeliveryPurposeCategory = "OFF_LINE_PAY" 204 DELIVERYPURPOSECATEGORY_JUMP_MINI_APP DeliveryPurposeCategory = "JUMP_MINI_APP" 205) 206 207type SendContentCategory string 208 209func (e SendContentCategory) Ptr() *SendContentCategory { 210 return &e 211} 212 213const ( 214 SENDCONTENTCATEGORY_SINGLE_COUPON SendContentCategory = "SINGLE_COUPON" 215 SENDCONTENTCATEGORY_GIFT_PACKAGE SendContentCategory = "GIFT_PACKAGE" 216) 217 218type AwardType string 219 220func (e AwardType) Ptr() *AwardType { 221 return &e 222} 223 224const ( 225 AWARDTYPE_BUSIFAVOR AwardType = "BUSIFAVOR" 226) 227 228type AwardBaseInfo struct { 229 StockId *string `json:"stock_id,omitempty"` 230 OriginalImageUrl *string `json:"original_image_url,omitempty"` 231 ThumbnailUrl *string `json:"thumbnail_url,omitempty"` 232} 233 234type SendMerchantOption string 235 236func (e SendMerchantOption) Ptr() *SendMerchantOption { 237 return &e 238} 239 240const ( 241 SENDMERCHANTOPTION_IN_SEVICE_COUPON_MERCHANT SendMerchantOption = "IN_SEVICE_COUPON_MERCHANT" 242 SENDMERCHANTOPTION_MANUAL_INPUT_MERCHANT SendMerchantOption = "MANUAL_INPUT_MERCHANT" 243) 244 245type DeliveryUserCategory string 246 247func (e DeliveryUserCategory) Ptr() *DeliveryUserCategory { 248 return &e 249} 250 251const ( 252 DELIVERYUSERCATEGORY_DELIVERY_ALL_PERSON DeliveryUserCategory = "DELIVERY_ALL_PERSON" 253 DELIVERYUSERCATEGORY_DELIVERY_MEMBER_PERSON DeliveryUserCategory = "DELIVERY_MEMBER_PERSON" 254) 255 256type PaymentMode struct { 257 PaymentSceneList []PaymentScene `json:"payment_scene_list,omitempty"` 258} 259 260type PaymentMethodInfo struct { 261 PaymentMethod *PaymentMethodCategory `json:"payment_method,omitempty"` 262 BankAbbreviation *string `json:"bank_abbreviation,omitempty"` 263} 264 265type AvailableTime struct { 266 BeginTime *string `json:"begin_time,omitempty"` 267 EndTime *string `json:"end_time,omitempty"` 268} 269 270type AvailableDayTime struct { 271 BeginDayTime *string `json:"begin_day_time,omitempty"` 272 EndDayTime *string `json:"end_day_time,omitempty"` 273} 274 275type PaymentScene string 276 277func (e PaymentScene) Ptr() *PaymentScene { 278 return &e 279} 280 281const ( 282 PAYMENTSCENE_APP_SCENE PaymentScene = "APP_SCENE" 283 PAYMENTSCENE_SWING_CARD_SCENE PaymentScene = "SWING_CARD_SCENE" 284 PAYMENTSCENE_NO_SECRET_SCENE PaymentScene = "NO_SECRET_SCENE" 285 PAYMENTSCENE_MINIAPP_SCENE PaymentScene = "MINIAPP_SCENE" 286 PAYMENTSCENE_FACE_PAY_SCENE PaymentScene = "FACE_PAY_SCENE" 287 PAYMENTSCENE_OTHER_SCENE PaymentScene = "OTHER_SCENE" 288) 289 290type PaymentMethodCategory string 291 292func (e PaymentMethodCategory) Ptr() *PaymentMethodCategory { 293 return &e 294} 295 296const ( 297 PAYMENTMETHODCATEGORY_CFT PaymentMethodCategory = "CFT" 298 PAYMENTMETHODCATEGORY_SPECIFIC_BANK_CARD PaymentMethodCategory = "SPECIFIC_BANK_CARD" 299) 300
应答参数
|
activity_id 必填 string(20)
【活动id】活动id
create_time 必填 string(32)
【创建时间】创建时间
应答示例
200 OK
1{ 2 "activity_id" : "10028001", 3 "create_time" : "2015-05-20T13:29:35.120+08:00" 4} 5
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | APPID_MCHID_NOT_MATCH | AppID与mchid不匹配 | 请确认AppID是否正确填写 |
400 | INVALID_REQUEST | 请求参数符合参数格式,但不符合业务规则 | 根据错误提示,传入符合业务规则的参数 |
400 | MCH_NOT_EXISTS | 商户号不存在 | 请确认发券商户号信息是否有误 |
401 | SIGN_ERROR | 签名错误或签名信息不完整 | 登录商户平台核对,传入正确信息 |
403 | NO_AUTH | 商户未被授权 | 登录商户平台核对,传入正确信息 |
404 | RESOURCE_NOT_EXISTS | 资源不存在或无可用 | 请确认资源均存在且可用 |
429 | FREQUENCY_LIMITED | 频率超限 | 请求量不要超过接口调用频率限制 |
500 | SYSTEM_ERROR | 系统错误 | 请使用相同参数稍后重新调用 |