api_subsidy_example_test.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 ExampleSubsidyApiService_PayReceiptInfo() {
  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.SubsidyApiService{Client: client}
  41. resp, result, err := svc.PayReceiptInfo(ctx,
  42. merchantexclusivecoupon.PayReceiptInfoRequest{
  43. SubsidyReceiptId: core.String("1120200119165100000000000001"),
  44. },
  45. )
  46. if err != nil {
  47. // 处理错误
  48. log.Printf("call PayReceiptInfo err:%s", err)
  49. } else {
  50. // 处理返回结果
  51. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  52. }
  53. }
  54. func ExampleSubsidyApiService_PayReceiptList() {
  55. var (
  56. mchID string = "190000****" // 商户号
  57. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  58. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  59. )
  60. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  61. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  62. if err != nil {
  63. log.Printf("load merchant private key error:%s", err)
  64. return
  65. }
  66. ctx := context.Background()
  67. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  68. opts := []core.ClientOption{
  69. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  70. }
  71. client, err := core.NewClient(ctx, opts...)
  72. if err != nil {
  73. log.Printf("new wechat pay client err:%s", err)
  74. return
  75. }
  76. svc := merchantexclusivecoupon.SubsidyApiService{Client: client}
  77. resp, result, err := svc.PayReceiptList(ctx,
  78. merchantexclusivecoupon.PayReceiptListRequest{
  79. StockId: core.String("128888000000001"),
  80. CouponCode: core.String("ABCD12345678"),
  81. OutSubsidyNo: core.String("subsidy-abcd-12345678"),
  82. },
  83. )
  84. if err != nil {
  85. // 处理错误
  86. log.Printf("call PayReceiptList err:%s", err)
  87. } else {
  88. // 处理返回结果
  89. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  90. }
  91. }
  92. func ExampleSubsidyApiService_ReturnReceiptInfo() {
  93. var (
  94. mchID string = "190000****" // 商户号
  95. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  96. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  97. )
  98. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  99. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  100. if err != nil {
  101. log.Printf("load merchant private key error:%s", err)
  102. return
  103. }
  104. ctx := context.Background()
  105. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  106. opts := []core.ClientOption{
  107. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  108. }
  109. client, err := core.NewClient(ctx, opts...)
  110. if err != nil {
  111. log.Printf("new wechat pay client err:%s", err)
  112. return
  113. }
  114. svc := merchantexclusivecoupon.SubsidyApiService{Client: client}
  115. resp, result, err := svc.ReturnReceiptInfo(ctx,
  116. merchantexclusivecoupon.ReturnReceiptInfoRequest{
  117. SubsidyReturnReceiptId: core.String("2120200119165100000000000001"),
  118. },
  119. )
  120. if err != nil {
  121. // 处理错误
  122. log.Printf("call ReturnReceiptInfo err:%s", err)
  123. } else {
  124. // 处理返回结果
  125. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  126. }
  127. }
  128. func ExampleSubsidyApiService_SubsidyPay() {
  129. var (
  130. mchID string = "190000****" // 商户号
  131. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  132. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  133. )
  134. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  135. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  136. if err != nil {
  137. log.Printf("load merchant private key error:%s", err)
  138. return
  139. }
  140. ctx := context.Background()
  141. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  142. opts := []core.ClientOption{
  143. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  144. }
  145. client, err := core.NewClient(ctx, opts...)
  146. if err != nil {
  147. log.Printf("new wechat pay client err:%s", err)
  148. return
  149. }
  150. svc := merchantexclusivecoupon.SubsidyApiService{Client: client}
  151. resp, result, err := svc.SubsidyPay(ctx,
  152. merchantexclusivecoupon.SubsidyPayRequest{
  153. StockId: core.String("128888000000001"),
  154. CouponCode: core.String("ABCD12345678"),
  155. TransactionId: core.String("4200000913202101152566792388"),
  156. PayerMerchant: core.String("1900000001"),
  157. PayeeMerchant: core.String("1900000002"),
  158. Amount: core.Int64(100),
  159. Description: core.String("20210115DESCRIPTION"),
  160. OutSubsidyNo: core.String("subsidy-abcd-12345678"),
  161. },
  162. )
  163. if err != nil {
  164. // 处理错误
  165. log.Printf("call SubsidyPay err:%s", err)
  166. } else {
  167. // 处理返回结果
  168. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  169. }
  170. }
  171. func ExampleSubsidyApiService_SubsidyReturn() {
  172. var (
  173. mchID string = "190000****" // 商户号
  174. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  175. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  176. )
  177. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  178. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  179. if err != nil {
  180. log.Printf("load merchant private key error:%s", err)
  181. return
  182. }
  183. ctx := context.Background()
  184. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  185. opts := []core.ClientOption{
  186. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  187. }
  188. client, err := core.NewClient(ctx, opts...)
  189. if err != nil {
  190. log.Printf("new wechat pay client err:%s", err)
  191. return
  192. }
  193. svc := merchantexclusivecoupon.SubsidyApiService{Client: client}
  194. resp, result, err := svc.SubsidyReturn(ctx,
  195. merchantexclusivecoupon.SubsidyReturnRequest{
  196. StockId: core.String("128888000000001"),
  197. CouponCode: core.String("ABCD12345678"),
  198. TransactionId: core.String("4200000913202101152566792388"),
  199. RefundId: core.String("50100506732021010105138718375"),
  200. PayerMerchant: core.String("1900000001"),
  201. PayeeMerchant: core.String("1900000002"),
  202. Amount: core.Int64(100),
  203. Description: core.String("20210115DESCRIPTION"),
  204. OutSubsidyReturnNo: core.String("subsidy-abcd-12345678"),
  205. },
  206. )
  207. if err != nil {
  208. // 处理错误
  209. log.Printf("call SubsidyReturn err:%s", err)
  210. } else {
  211. // 处理返回结果
  212. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  213. }
  214. }