api_activity_example_test.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2021 Tencent Inc. All rights reserved.
  2. //
  3. // 营销加价购对外API
  4. //
  5. // 指定服务商可通过该接口报名加价购活动、查询某个区域内的加价购活动列表、锁定加价活动购资格以及解锁加价购活动资格。
  6. //
  7. // API version: 1.4.0
  8. // Code generated by WechatPay APIv3 Generator based on [OpenAPI Generator](https://openapi-generator.tech); DO NOT EDIT.
  9. package retailstore_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/retailstore"
  16. "git.nanodreamtech.com/sg/wechatpay-go/utils"
  17. )
  18. func ExampleActivityApiService_ApplyActivity() {
  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 := retailstore.ActivityApiService{Client: client}
  41. resp, result, err := svc.ApplyActivity(ctx,
  42. retailstore.ApplyActivityRequest{
  43. ActivityId: core.String("123"),
  44. CallerMerchantId: core.String("1894101023"),
  45. ApplyInfos: []retailstore.ActApplyInfo{retailstore.ActApplyInfo{
  46. StoreInfo: &retailstore.StoreInfo{
  47. StoreId: core.String("100"),
  48. AccountingMerchantId: core.String("2831255701"),
  49. MerchantId: core.String("6281399112"),
  50. },
  51. GoodsOriginalPrice: core.Int64(100),
  52. }},
  53. },
  54. )
  55. if err != nil {
  56. // 处理错误
  57. log.Printf("call ApplyActivity err:%s", err)
  58. } else {
  59. // 处理返回结果
  60. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  61. }
  62. }
  63. func ExampleActivityApiService_ListActsByArea() {
  64. var (
  65. mchID string = "190000****" // 商户号
  66. mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
  67. mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
  68. )
  69. // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
  70. mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
  71. if err != nil {
  72. log.Printf("load merchant private key error:%s", err)
  73. return
  74. }
  75. ctx := context.Background()
  76. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  77. opts := []core.ClientOption{
  78. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  79. }
  80. client, err := core.NewClient(ctx, opts...)
  81. if err != nil {
  82. log.Printf("new wechat pay client err:%s", err)
  83. return
  84. }
  85. svc := retailstore.ActivityApiService{Client: client}
  86. resp, result, err := svc.ListActsByArea(ctx,
  87. retailstore.ListActsByAreaRequest{
  88. CityId: core.String("123"),
  89. Offset: core.Int64(0),
  90. Limit: core.Int64(20),
  91. },
  92. )
  93. if err != nil {
  94. // 处理错误
  95. log.Printf("call ListActsByArea err:%s", err)
  96. } else {
  97. // 处理返回结果
  98. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  99. }
  100. }