api_coupon_example_test.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. "git.nanodreamtech.com/sg/wechatpay-go/core"
  14. "git.nanodreamtech.com/sg/wechatpay-go/core/option"
  15. "git.nanodreamtech.com/sg/wechatpay-go/services/merchantexclusivecoupon"
  16. "git.nanodreamtech.com/sg/wechatpay-go/utils"
  17. )
  18. func ExampleCouponApiService_AssociateTradeInfo() {
  19. var (
  20. mchID string = "190000****" // 商户号
  21. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  22. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  23. )
  24. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  25. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  26. if err != nil {
  27. log.Printf("load merchant private key error:%s", err)
  28. return
  29. }
  30. ctx := context.Background()
  31. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  32. opts := []core.ClientOption{
  33. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  34. }
  35. client, err := core.NewClient(ctx, opts...)
  36. if err != nil {
  37. log.Printf("new wechat pay client err:%s", err)
  38. return
  39. }
  40. svc := merchantexclusivecoupon.CouponApiService{Client: client}
  41. resp, result, err := svc.AssociateTradeInfo(ctx,
  42. merchantexclusivecoupon.AssociateTradeInfoRequest{
  43. StockId: core.String("100088"),
  44. CouponCode: core.String("sxxe34343434"),
  45. OutTradeNo: core.String("MCH_102233445"),
  46. OutRequestNo: core.String("1002600620019090123143254435"),
  47. },
  48. )
  49. if err != nil {
  50. // 处理错误
  51. log.Printf("call AssociateTradeInfo err:%s", err)
  52. } else {
  53. // 处理返回结果
  54. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  55. }
  56. }
  57. func ExampleCouponApiService_DeactivateCoupon() {
  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.CouponApiService{Client: client}
  80. resp, result, err := svc.DeactivateCoupon(ctx,
  81. merchantexclusivecoupon.DeactivateCouponRequest{
  82. CouponCode: core.String("sxxe34343434"),
  83. StockId: core.String("1234567891"),
  84. DeactivateRequestNo: core.String("1002600620019090123143254436"),
  85. DeactivateReason: core.String("此券使用时间设置错误"),
  86. },
  87. )
  88. if err != nil {
  89. // 处理错误
  90. log.Printf("call DeactivateCoupon err:%s", err)
  91. } else {
  92. // 处理返回结果
  93. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  94. }
  95. }
  96. func ExampleCouponApiService_DisassociateTradeInfo() {
  97. var (
  98. mchID string = "190000****" // 商户号
  99. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  100. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  101. )
  102. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  103. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  104. if err != nil {
  105. log.Printf("load merchant private key error:%s", err)
  106. return
  107. }
  108. ctx := context.Background()
  109. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  110. opts := []core.ClientOption{
  111. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  112. }
  113. client, err := core.NewClient(ctx, opts...)
  114. if err != nil {
  115. log.Printf("new wechat pay client err:%s", err)
  116. return
  117. }
  118. svc := merchantexclusivecoupon.CouponApiService{Client: client}
  119. resp, result, err := svc.DisassociateTradeInfo(ctx,
  120. merchantexclusivecoupon.DisassociateTradeInfoRequest{
  121. StockId: core.String("100088"),
  122. CouponCode: core.String("213dsadfsa"),
  123. OutTradeNo: core.String("treads8a9f980"),
  124. OutRequestNo: core.String("fdsafdsafdsa231321"),
  125. },
  126. )
  127. if err != nil {
  128. // 处理错误
  129. log.Printf("call DisassociateTradeInfo err:%s", err)
  130. } else {
  131. // 处理返回结果
  132. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  133. }
  134. }
  135. func ExampleCouponApiService_ListCouponsByFilter() {
  136. var (
  137. mchID string = "190000****" // 商户号
  138. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  139. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  140. )
  141. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  142. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  143. if err != nil {
  144. log.Printf("load merchant private key error:%s", err)
  145. return
  146. }
  147. ctx := context.Background()
  148. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  149. opts := []core.ClientOption{
  150. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  151. }
  152. client, err := core.NewClient(ctx, opts...)
  153. if err != nil {
  154. log.Printf("new wechat pay client err:%s", err)
  155. return
  156. }
  157. svc := merchantexclusivecoupon.CouponApiService{Client: client}
  158. resp, result, err := svc.ListCouponsByFilter(ctx,
  159. merchantexclusivecoupon.ListCouponsByFilterRequest{
  160. Openid: core.String("2323dfsdf342342"),
  161. Appid: core.String("wx233544546545989"),
  162. StockId: core.String("100088"),
  163. CreatorMerchant: core.String("1000000001"),
  164. BelongMerchant: core.String("1000000002"),
  165. SenderMerchant: core.String("1000000003"),
  166. Offset: core.Int64(0),
  167. Limit: core.Int64(20),
  168. CouponState: merchantexclusivecoupon.COUPONSTATUS_SENDED.Ptr(),
  169. },
  170. )
  171. if err != nil {
  172. // 处理错误
  173. log.Printf("call ListCouponsByFilter err:%s", err)
  174. } else {
  175. // 处理返回结果
  176. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  177. }
  178. }
  179. func ExampleCouponApiService_QueryCoupon() {
  180. var (
  181. mchID string = "190000****" // 商户号
  182. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  183. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  184. )
  185. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  186. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  187. if err != nil {
  188. log.Printf("load merchant private key error:%s", err)
  189. return
  190. }
  191. ctx := context.Background()
  192. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  193. opts := []core.ClientOption{
  194. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  195. }
  196. client, err := core.NewClient(ctx, opts...)
  197. if err != nil {
  198. log.Printf("new wechat pay client err:%s", err)
  199. return
  200. }
  201. svc := merchantexclusivecoupon.CouponApiService{Client: client}
  202. resp, result, err := svc.QueryCoupon(ctx,
  203. merchantexclusivecoupon.QueryCouponRequest{
  204. CouponCode: core.String("123446565767"),
  205. Appid: core.String("wx233544546545989"),
  206. Openid: core.String("2323dfsdf342342"),
  207. },
  208. )
  209. if err != nil {
  210. // 处理错误
  211. log.Printf("call QueryCoupon err:%s", err)
  212. } else {
  213. // 处理返回结果
  214. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  215. }
  216. }
  217. func ExampleCouponApiService_ReturnCoupon() {
  218. var (
  219. mchID string = "190000****" // 商户号
  220. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  221. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  222. )
  223. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  224. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  225. if err != nil {
  226. log.Printf("load merchant private key error:%s", err)
  227. return
  228. }
  229. ctx := context.Background()
  230. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  231. opts := []core.ClientOption{
  232. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  233. }
  234. client, err := core.NewClient(ctx, opts...)
  235. if err != nil {
  236. log.Printf("new wechat pay client err:%s", err)
  237. return
  238. }
  239. svc := merchantexclusivecoupon.CouponApiService{Client: client}
  240. resp, result, err := svc.ReturnCoupon(ctx,
  241. merchantexclusivecoupon.ReturnCouponRequest{
  242. CouponCode: core.String("sxxe34343434"),
  243. StockId: core.String("1234567891"),
  244. ReturnRequestNo: core.String("1002600620019090123143254436"),
  245. },
  246. )
  247. if err != nil {
  248. // 处理错误
  249. log.Printf("call ReturnCoupon err:%s", err)
  250. } else {
  251. // 处理返回结果
  252. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  253. }
  254. }
  255. func ExampleCouponApiService_SendCoupon() {
  256. var (
  257. mchID string = "190000****" // 商户号
  258. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  259. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  260. )
  261. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  262. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  263. if err != nil {
  264. log.Printf("load merchant private key error:%s", err)
  265. return
  266. }
  267. ctx := context.Background()
  268. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  269. opts := []core.ClientOption{
  270. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  271. }
  272. client, err := core.NewClient(ctx, opts...)
  273. if err != nil {
  274. log.Printf("new wechat pay client err:%s", err)
  275. return
  276. }
  277. svc := merchantexclusivecoupon.CouponApiService{Client: client}
  278. resp, result, err := svc.SendCoupon(ctx,
  279. merchantexclusivecoupon.SendCouponRequest{
  280. Openid: core.String("xsd3434454567676"),
  281. Appid: core.String("wx1234567889999"),
  282. StockId: core.String("12312354"),
  283. OutRequestNo: core.String("2335465"),
  284. CouponCode: core.String("202007019999"),
  285. },
  286. )
  287. if err != nil {
  288. // 处理错误
  289. log.Printf("call SendCoupon err:%s", err)
  290. } else {
  291. // 处理返回结果
  292. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  293. }
  294. }
  295. func ExampleCouponApiService_SendGovCard() {
  296. var (
  297. mchID string = "190000****" // 商户号
  298. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  299. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  300. )
  301. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  302. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  303. if err != nil {
  304. log.Printf("load merchant private key error:%s", err)
  305. return
  306. }
  307. ctx := context.Background()
  308. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  309. opts := []core.ClientOption{
  310. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  311. }
  312. client, err := core.NewClient(ctx, opts...)
  313. if err != nil {
  314. log.Printf("new wechat pay client err:%s", err)
  315. return
  316. }
  317. svc := merchantexclusivecoupon.CouponApiService{Client: client}
  318. resp, result, err := svc.SendGovCard(ctx,
  319. merchantexclusivecoupon.SendGovCardRequest{
  320. CardId: core.String("pIJMr5MMiIkO_93VtPyIiEk2DZ4w"),
  321. Appid: core.String("wxc0b84a53ed8e8d29"),
  322. Openid: core.String("obLatjhnqgy2syxrXVM3MJirbkdI"),
  323. OutRequestNo: core.String("oTYhjfdsahnssddj_0136"),
  324. SendTime: core.String("2019-12-31T13:29:35+08:00"),
  325. },
  326. )
  327. if err != nil {
  328. // 处理错误
  329. log.Printf("call SendGovCard err:%s", err)
  330. } else {
  331. // 处理返回结果
  332. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  333. }
  334. }
  335. func ExampleCouponApiService_UseCoupon() {
  336. var (
  337. mchID string = "190000****" // 商户号
  338. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  339. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  340. )
  341. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  342. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  343. if err != nil {
  344. log.Printf("load merchant private key error:%s", err)
  345. return
  346. }
  347. ctx := context.Background()
  348. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  349. opts := []core.ClientOption{
  350. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  351. }
  352. client, err := core.NewClient(ctx, opts...)
  353. if err != nil {
  354. log.Printf("new wechat pay client err:%s", err)
  355. return
  356. }
  357. svc := merchantexclusivecoupon.CouponApiService{Client: client}
  358. resp, result, err := svc.UseCoupon(ctx,
  359. merchantexclusivecoupon.UseCouponRequest{
  360. CouponCode: core.String("sxxe34343434"),
  361. StockId: core.String("100088"),
  362. Appid: core.String("wx1234567889999"),
  363. UseTime: core.String("2015-05-20T13:29:35+08:00"),
  364. UseRequestNo: core.String("1002600620019090123143254435"),
  365. Openid: core.String("xsd3434454567676"),
  366. },
  367. )
  368. if err != nil {
  369. // 处理错误
  370. log.Printf("call UseCoupon err:%s", err)
  371. } else {
  372. // 处理返回结果
  373. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  374. }
  375. }