api_h5_example_test.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. // Copyright 2021 Tencent Inc. All rights reserved.
  2. //
  3. // H5支付
  4. //
  5. // H5支付API
  6. //
  7. // API version: 1.2.3
  8. // Code generated by WechatPay APIv3 Generator based on [OpenAPI Generator](https://openapi-generator.tech); DO NOT EDIT.
  9. package h5_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/partnerpayments/h5"
  17. "git.nanodreamtech.com/sg/wechatpay-go/utils"
  18. )
  19. func ExampleH5ApiService_CloseOrder() {
  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.Print("load merchant private key error")
  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. }
  39. svc := h5.H5ApiService{Client: client}
  40. result, err := svc.CloseOrder(ctx,
  41. h5.CloseOrderRequest{
  42. OutTradeNo: core.String("OutTradeNo_example"),
  43. SpMchid: core.String("1230000109"),
  44. SubMchid: core.String("1230000109"),
  45. },
  46. )
  47. if err != nil {
  48. // 处理错误
  49. log.Printf("call CloseOrder err:%s", err)
  50. } else {
  51. // 处理返回结果
  52. log.Printf("status=%d", result.Response.StatusCode)
  53. }
  54. }
  55. func ExampleH5ApiService_Prepay() {
  56. var (
  57. mchID string = "190000****" // 商户号
  58. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  59. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  60. )
  61. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  62. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  63. if err != nil {
  64. log.Print("load merchant private key error")
  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. }
  75. svc := h5.H5ApiService{Client: client}
  76. resp, result, err := svc.Prepay(ctx,
  77. h5.PrepayRequest{
  78. SpAppid: core.String("wxd678efh567hg6787"),
  79. SpMchid: core.String("1230000109"),
  80. SubAppid: core.String("wxd678efh567hg6787"),
  81. SubMchid: core.String("1230000109"),
  82. Description: core.String("Image形象店-深圳腾大-QQ公仔"),
  83. OutTradeNo: core.String("1217752501201407033233368018"),
  84. TimeExpire: core.Time(time.Now()),
  85. Attach: core.String("自定义数据说明"),
  86. NotifyUrl: core.String("https://www.weixin.qq.com/wxpay/pay.php"),
  87. GoodsTag: core.String("WXG"),
  88. LimitPay: []string{"LimitPay_example"},
  89. SupportFapiao: core.Bool(false),
  90. Amount: &h5.Amount{
  91. Currency: core.String("CNY"),
  92. Total: core.Int64(100),
  93. },
  94. Detail: &h5.Detail{
  95. CostPrice: core.Int64(608800),
  96. GoodsDetail: []h5.GoodsDetail{h5.GoodsDetail{
  97. GoodsName: core.String("iPhoneX 256G"),
  98. MerchantGoodsId: core.String("ABC"),
  99. Quantity: core.Int64(1),
  100. UnitPrice: core.Int64(828800),
  101. WechatpayGoodsId: core.String("1001"),
  102. }},
  103. InvoiceId: core.String("wx123"),
  104. },
  105. SceneInfo: &h5.SceneInfo{
  106. DeviceId: core.String("013467007045764"),
  107. H5Info: &h5.H5Info{
  108. AppName: core.String("王者荣耀"),
  109. AppUrl: core.String("https://pay.qq.com"),
  110. BundleId: core.String("com.tencent.wzryiOS"),
  111. PackageName: core.String("com.tencent.tmgp.sgame"),
  112. Type: core.String("iOS"),
  113. },
  114. PayerClientIp: core.String("14.23.150.211"),
  115. StoreInfo: &h5.StoreInfo{
  116. Address: core.String("广东省深圳市南山区科技中一道10000号"),
  117. AreaCode: core.String("440305"),
  118. Id: core.String("0001"),
  119. Name: core.String("腾讯大厦分店"),
  120. },
  121. },
  122. SettleInfo: &h5.SettleInfo{
  123. ProfitSharing: core.Bool(false),
  124. },
  125. },
  126. )
  127. if err != nil {
  128. // 处理错误
  129. log.Printf("call Prepay err:%s", err)
  130. } else {
  131. // 处理返回结果
  132. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  133. }
  134. }
  135. func ExampleH5ApiService_QueryOrderById() {
  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.Print("load merchant private key error")
  145. }
  146. ctx := context.Background()
  147. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  148. opts := []core.ClientOption{
  149. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  150. }
  151. client, err := core.NewClient(ctx, opts...)
  152. if err != nil {
  153. log.Printf("new wechat pay client err:%s", err)
  154. }
  155. svc := h5.H5ApiService{Client: client}
  156. resp, result, err := svc.QueryOrderById(ctx,
  157. h5.QueryOrderByIdRequest{
  158. TransactionId: core.String("TransactionId_example"),
  159. SpMchid: core.String("SpMchid_example"),
  160. SubMchid: core.String("SubMchid_example"),
  161. },
  162. )
  163. if err != nil {
  164. // 处理错误
  165. log.Printf("call QueryOrderById err:%s", err)
  166. } else {
  167. // 处理返回结果
  168. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  169. }
  170. }
  171. func ExampleH5ApiService_QueryOrderByOutTradeNo() {
  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.Print("load merchant private key error")
  181. }
  182. ctx := context.Background()
  183. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  184. opts := []core.ClientOption{
  185. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  186. }
  187. client, err := core.NewClient(ctx, opts...)
  188. if err != nil {
  189. log.Printf("new wechat pay client err:%s", err)
  190. }
  191. svc := h5.H5ApiService{Client: client}
  192. resp, result, err := svc.QueryOrderByOutTradeNo(ctx,
  193. h5.QueryOrderByOutTradeNoRequest{
  194. OutTradeNo: core.String("OutTradeNo_example"),
  195. SpMchid: core.String("SpMchid_example"),
  196. SubMchid: core.String("SubMchid_example"),
  197. },
  198. )
  199. if err != nil {
  200. // 处理错误
  201. log.Printf("call QueryOrderByOutTradeNo err:%s", err)
  202. } else {
  203. // 处理返回结果
  204. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  205. }
  206. }