api_busi_favor_example_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. // Copyright 2021 Tencent Inc. All rights reserved.
  2. //
  3. // 营销商家券对外API
  4. //
  5. // No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
  6. //
  7. // API version: 0.0.11
  8. // Code generated by WechatPay APIv3 Generator based on [OpenAPI Generator](https://openapi-generator.tech); DO NOT EDIT.
  9. package merchantexclusivecoupon_test
  10. import (
  11. "context"
  12. "log"
  13. "time"
  14. "git.nanodreamtech.com/sg/wechatpay-go/core"
  15. "git.nanodreamtech.com/sg/wechatpay-go/core/option"
  16. "git.nanodreamtech.com/sg/wechatpay-go/services/merchantexclusivecoupon"
  17. "git.nanodreamtech.com/sg/wechatpay-go/utils"
  18. )
  19. func ExampleBusiFavorApiService_CouponCodeInfo() {
  20. var (
  21. mchID string = "190000****" // 商户号
  22. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  23. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  24. )
  25. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  26. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  27. if err != nil {
  28. log.Printf("load merchant private key error:%s", err)
  29. return
  30. }
  31. ctx := context.Background()
  32. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  33. opts := []core.ClientOption{
  34. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  35. }
  36. client, err := core.NewClient(ctx, opts...)
  37. if err != nil {
  38. log.Printf("new wechat pay client err:%s", err)
  39. return
  40. }
  41. svc := merchantexclusivecoupon.BusiFavorApiService{Client: client}
  42. resp, result, err := svc.CouponCodeInfo(ctx,
  43. merchantexclusivecoupon.CouponCodeInfoRequest{
  44. StockId: core.String("98065001"),
  45. CouponCode: core.String("ABC1234567"),
  46. Appid: core.String("wx1234567889999"),
  47. },
  48. )
  49. if err != nil {
  50. // 处理错误
  51. log.Printf("call CouponCodeInfo err:%s", err)
  52. } else {
  53. // 处理返回结果
  54. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  55. }
  56. }
  57. func ExampleBusiFavorApiService_CreateBusifavorStock() {
  58. var (
  59. mchID string = "190000****" // 商户号
  60. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  61. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  62. )
  63. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  64. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  65. if err != nil {
  66. log.Printf("load merchant private key error:%s", err)
  67. return
  68. }
  69. ctx := context.Background()
  70. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  71. opts := []core.ClientOption{
  72. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  73. }
  74. client, err := core.NewClient(ctx, opts...)
  75. if err != nil {
  76. log.Printf("new wechat pay client err:%s", err)
  77. return
  78. }
  79. svc := merchantexclusivecoupon.BusiFavorApiService{Client: client}
  80. resp, result, err := svc.CreateBusifavorStock(ctx,
  81. merchantexclusivecoupon.CreateBusifavorStockRequest{
  82. StockName: core.String("8月1日活动券"),
  83. BelongMerchant: core.String("10000098"),
  84. Comment: core.String("活动使用"),
  85. GoodsName: core.String("填写商家券可适用的商品或服务"),
  86. StockType: merchantexclusivecoupon.BUSIFAVORSTOCKTYPE_NORMAL.Ptr(),
  87. CouponUseRule: &merchantexclusivecoupon.CouponUseRule{
  88. CouponAvailableTime: &merchantexclusivecoupon.FavorAvailableTime{
  89. AvailableBeginTime: core.Time(time.Now()),
  90. AvailableEndTime: core.Time(time.Now()),
  91. AvailableDayAfterReceive: core.Int64(3),
  92. AvailableWeek: &merchantexclusivecoupon.AvailableWeek{
  93. WeekDay: []int64{int64(1)},
  94. AvailableDayTime: []merchantexclusivecoupon.AvailableCurrentDayTime{merchantexclusivecoupon.AvailableCurrentDayTime{
  95. BeginTime: core.Int64(3600),
  96. EndTime: core.Int64(86399),
  97. }},
  98. },
  99. IrregularyAvaliableTime: []merchantexclusivecoupon.IrregularAvailableTime{merchantexclusivecoupon.IrregularAvailableTime{
  100. BeginTime: core.Time(time.Now()),
  101. EndTime: core.Time(time.Now()),
  102. }},
  103. WaitDaysAfterReceive: core.Int64(7),
  104. },
  105. FixedNormalCoupon: &merchantexclusivecoupon.FixedValueStockMsg{
  106. DiscountAmount: core.Int64(5),
  107. TransactionMinimum: core.Int64(100),
  108. },
  109. DiscountCoupon: &merchantexclusivecoupon.DiscountMsg{
  110. DiscountPercent: core.Int64(88),
  111. TransactionMinimum: core.Int64(100),
  112. },
  113. ExchangeCoupon: &merchantexclusivecoupon.ExchangeMsg{
  114. ExchangePrice: core.Int64(100),
  115. TransactionMinimum: core.Int64(100),
  116. },
  117. UseMethod: merchantexclusivecoupon.COUPONUSEMETHOD_OFF_LINE.Ptr(),
  118. MiniProgramsAppid: core.String("wx23232232323"),
  119. MiniProgramsPath: core.String("/path/index/index"),
  120. },
  121. StockSendRule: &merchantexclusivecoupon.StockSendRule{
  122. MaxAmount: core.Int64(100000),
  123. MaxCoupons: core.Int64(100),
  124. MaxCouponsPerUser: core.Int64(5),
  125. MaxAmountByDay: core.Int64(1000),
  126. MaxCouponsByDay: core.Int64(100),
  127. NaturalPersonLimit: core.Bool(false),
  128. PreventApiAbuse: core.Bool(false),
  129. Transferable: core.Bool(false),
  130. Shareable: core.Bool(false),
  131. },
  132. OutRequestNo: core.String("100002322019090134234sfdf"),
  133. CustomEntrance: &merchantexclusivecoupon.CustomEntrance{
  134. MiniProgramsInfo: &merchantexclusivecoupon.MiniAppInfo{
  135. MiniProgramsAppid: core.String("wx234545656765876"),
  136. MiniProgramsPath: core.String("/path/index/index"),
  137. EntranceWords: core.String("欢迎选购"),
  138. GuidingWords: core.String("获取更多优惠"),
  139. },
  140. Appid: core.String("wx324345hgfhfghfg"),
  141. HallId: core.String("233455656"),
  142. StoreId: core.String("233554655"),
  143. CodeDisplayMode: merchantexclusivecoupon.CODEDISPLAYMODE_NOT_SHOW.Ptr(),
  144. },
  145. DisplayPatternInfo: &merchantexclusivecoupon.DisplayPatternInfo{
  146. Description: core.String("xxx门店可用"),
  147. MerchantLogoUrl: core.String("https://xxx"),
  148. MerchantName: core.String("微信支付"),
  149. BackgroundColor: core.String("xxxxx"),
  150. CouponImageUrl: core.String("图片cdn地址"),
  151. FinderInfo: &merchantexclusivecoupon.FinderInfo{
  152. FinderId: core.String("sph6Rngt2T4RlUf"),
  153. FinderVideoId: core.String("export/UzFfAgtgekIEAQAAAAAAb4MgnPInmAAAAAstQy6ubaLX4KHWvLEZgBPEwIEgVnk9HIP-zNPgMJofG6tpdGPJNg_ojtEjoT94"),
  154. FinderVideoCoverImageUrl: core.String("https://wxpaylogo.qpic.cn/xxx"),
  155. },
  156. },
  157. CouponCodeMode: merchantexclusivecoupon.COUPONCODEMODE_WECHATPAY_MODE.Ptr(),
  158. NotifyConfig: &merchantexclusivecoupon.NotifyConfig{
  159. NotifyAppid: core.String("wx23232232323"),
  160. },
  161. Subsidy: core.Bool(false),
  162. },
  163. )
  164. if err != nil {
  165. // 处理错误
  166. log.Printf("call CreateBusifavorStock err:%s", err)
  167. } else {
  168. // 处理返回结果
  169. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  170. }
  171. }
  172. func ExampleBusiFavorApiService_DeleteCouponCode() {
  173. var (
  174. mchID string = "190000****" // 商户号
  175. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  176. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  177. )
  178. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  179. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  180. if err != nil {
  181. log.Printf("load merchant private key error:%s", err)
  182. return
  183. }
  184. ctx := context.Background()
  185. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  186. opts := []core.ClientOption{
  187. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  188. }
  189. client, err := core.NewClient(ctx, opts...)
  190. if err != nil {
  191. log.Printf("new wechat pay client err:%s", err)
  192. return
  193. }
  194. svc := merchantexclusivecoupon.BusiFavorApiService{Client: client}
  195. resp, result, err := svc.DeleteCouponCode(ctx,
  196. merchantexclusivecoupon.DeleteCouponCodeRequest{
  197. StockId: core.String("98065001"),
  198. CouponCode: core.String("ABC9588201"),
  199. DeleteRequestNo: core.String("100002322019090134234sfdf"),
  200. },
  201. )
  202. if err != nil {
  203. // 处理错误
  204. log.Printf("call DeleteCouponCode err:%s", err)
  205. } else {
  206. // 处理返回结果
  207. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  208. }
  209. }
  210. func ExampleBusiFavorApiService_ModifyBudget() {
  211. var (
  212. mchID string = "190000****" // 商户号
  213. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  214. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  215. )
  216. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  217. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  218. if err != nil {
  219. log.Printf("load merchant private key error:%s", err)
  220. return
  221. }
  222. ctx := context.Background()
  223. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  224. opts := []core.ClientOption{
  225. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  226. }
  227. client, err := core.NewClient(ctx, opts...)
  228. if err != nil {
  229. log.Printf("new wechat pay client err:%s", err)
  230. return
  231. }
  232. svc := merchantexclusivecoupon.BusiFavorApiService{Client: client}
  233. resp, result, err := svc.ModifyBudget(ctx,
  234. merchantexclusivecoupon.ModifyBudgetRequest{
  235. StockId: core.String("98065001"),
  236. TargetMaxCoupons: core.Int64(3000),
  237. CurrentMaxCoupons: core.Int64(500),
  238. TargetMaxCouponsByDay: core.Int64(500),
  239. CurrentMaxCouponsByDay: core.Int64(300),
  240. ModifyBudgetRequestNo: core.String("1002600620019090123143254436"),
  241. },
  242. )
  243. if err != nil {
  244. // 处理错误
  245. log.Printf("call ModifyBudget err:%s", err)
  246. } else {
  247. // 处理返回结果
  248. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  249. }
  250. }
  251. func ExampleBusiFavorApiService_ModifyStockInfo() {
  252. var (
  253. mchID string = "190000****" // 商户号
  254. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  255. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  256. )
  257. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  258. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  259. if err != nil {
  260. log.Printf("load merchant private key error:%s", err)
  261. return
  262. }
  263. ctx := context.Background()
  264. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  265. opts := []core.ClientOption{
  266. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  267. }
  268. client, err := core.NewClient(ctx, opts...)
  269. if err != nil {
  270. log.Printf("new wechat pay client err:%s", err)
  271. return
  272. }
  273. svc := merchantexclusivecoupon.BusiFavorApiService{Client: client}
  274. result, err := svc.ModifyStockInfo(ctx,
  275. merchantexclusivecoupon.ModifyStockInfoRequest{
  276. StockId: core.String("101156451224"),
  277. CustomEntrance: &merchantexclusivecoupon.ModifyCustomEntrance{
  278. MiniProgramsInfo: &merchantexclusivecoupon.ModifyMiniAppInfo{
  279. MiniProgramsAppid: core.String("wx234545656765876"),
  280. MiniProgramsPath: core.String("/path/index/index"),
  281. EntranceWords: core.String("欢迎选购"),
  282. GuidingWords: core.String("获取更多优惠"),
  283. },
  284. Appid: core.String("wx324345hgfhfghfg"),
  285. HallId: core.String("233455656"),
  286. CodeDisplayMode: merchantexclusivecoupon.CODEDISPLAYMODE_NOT_SHOW.Ptr(),
  287. },
  288. StockName: core.String("8月1日活动券"),
  289. Comment: core.String("活动使用"),
  290. GoodsName: core.String("xxx商品使用"),
  291. OutRequestNo: core.String("6122352020010133287985742"),
  292. DisplayPatternInfo: &merchantexclusivecoupon.DisplayPatternInfo{
  293. Description: core.String("xxx门店可用"),
  294. MerchantLogoUrl: core.String("https://xxx"),
  295. MerchantName: core.String("微信支付"),
  296. BackgroundColor: core.String("xxxxx"),
  297. CouponImageUrl: core.String("图片cdn地址"),
  298. FinderInfo: &merchantexclusivecoupon.FinderInfo{
  299. FinderId: core.String("sph6Rngt2T4RlUf"),
  300. FinderVideoId: core.String("export/UzFfAgtgekIEAQAAAAAAb4MgnPInmAAAAAstQy6ubaLX4KHWvLEZgBPEwIEgVnk9HIP-zNPgMJofG6tpdGPJNg_ojtEjoT94"),
  301. FinderVideoCoverImageUrl: core.String("https://wxpaylogo.qpic.cn/xxx"),
  302. },
  303. },
  304. CouponUseRule: &merchantexclusivecoupon.ModifyCouponUseRule{
  305. UseMethod: merchantexclusivecoupon.COUPONUSEMETHOD_OFF_LINE.Ptr(),
  306. MiniProgramsAppid: core.String("wx23232232323"),
  307. MiniProgramsPath: core.String("/path/index/index"),
  308. },
  309. StockSendRule: &merchantexclusivecoupon.ModifyStockSendRule{
  310. NaturalPersonLimit: core.Bool(false),
  311. PreventApiAbuse: core.Bool(false),
  312. },
  313. NotifyConfig: &merchantexclusivecoupon.NotifyConfig{
  314. NotifyAppid: core.String("wx23232232323"),
  315. },
  316. Subsidy: core.Bool(true),
  317. },
  318. )
  319. if err != nil {
  320. // 处理错误
  321. log.Printf("call ModifyStockInfo err:%s", err)
  322. } else {
  323. // 处理返回结果
  324. log.Printf("status=%d", result.Response.StatusCode)
  325. }
  326. }
  327. func ExampleBusiFavorApiService_QueryCouponCodeList() {
  328. var (
  329. mchID string = "190000****" // 商户号
  330. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  331. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  332. )
  333. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  334. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  335. if err != nil {
  336. log.Printf("load merchant private key error:%s", err)
  337. return
  338. }
  339. ctx := context.Background()
  340. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  341. opts := []core.ClientOption{
  342. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  343. }
  344. client, err := core.NewClient(ctx, opts...)
  345. if err != nil {
  346. log.Printf("new wechat pay client err:%s", err)
  347. return
  348. }
  349. svc := merchantexclusivecoupon.BusiFavorApiService{Client: client}
  350. resp, result, err := svc.QueryCouponCodeList(ctx,
  351. merchantexclusivecoupon.QueryCouponCodeListRequest{
  352. StockId: core.String("98065001"),
  353. Limit: core.Int64(100),
  354. Offset: core.Int64(10),
  355. Appid: core.String("wx1234567889999"),
  356. Status: merchantexclusivecoupon.COUPONCODESTATUS_AVAILABLE.Ptr(),
  357. },
  358. )
  359. if err != nil {
  360. // 处理错误
  361. log.Printf("call QueryCouponCodeList err:%s", err)
  362. } else {
  363. // 处理返回结果
  364. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  365. }
  366. }
  367. func ExampleBusiFavorApiService_QueryStock() {
  368. var (
  369. mchID string = "190000****" // 商户号
  370. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  371. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  372. )
  373. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  374. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  375. if err != nil {
  376. log.Printf("load merchant private key error:%s", err)
  377. return
  378. }
  379. ctx := context.Background()
  380. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  381. opts := []core.ClientOption{
  382. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  383. }
  384. client, err := core.NewClient(ctx, opts...)
  385. if err != nil {
  386. log.Printf("new wechat pay client err:%s", err)
  387. return
  388. }
  389. svc := merchantexclusivecoupon.BusiFavorApiService{Client: client}
  390. resp, result, err := svc.QueryStock(ctx,
  391. merchantexclusivecoupon.QueryStockRequest{
  392. StockId: core.String("100088"),
  393. },
  394. )
  395. if err != nil {
  396. // 处理错误
  397. log.Printf("call QueryStock err:%s", err)
  398. } else {
  399. // 处理返回结果
  400. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  401. }
  402. }
  403. func ExampleBusiFavorApiService_UploadCouponCode() {
  404. var (
  405. mchID string = "190000****" // 商户号
  406. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  407. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  408. )
  409. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  410. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  411. if err != nil {
  412. log.Printf("load merchant private key error:%s", err)
  413. return
  414. }
  415. ctx := context.Background()
  416. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  417. opts := []core.ClientOption{
  418. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  419. }
  420. client, err := core.NewClient(ctx, opts...)
  421. if err != nil {
  422. log.Printf("new wechat pay client err:%s", err)
  423. return
  424. }
  425. svc := merchantexclusivecoupon.BusiFavorApiService{Client: client}
  426. resp, result, err := svc.UploadCouponCode(ctx,
  427. merchantexclusivecoupon.UploadCouponCodeRequest{
  428. StockId: core.String("98065001"),
  429. CouponCodeList: []string{"ABC9588200"},
  430. UploadRequestNo: core.String("100002322019090134234sfdf"),
  431. },
  432. )
  433. if err != nil {
  434. // 处理错误
  435. log.Printf("call UploadCouponCode err:%s", err)
  436. } else {
  437. // 处理返回结果
  438. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  439. }
  440. }