api_call_back_example_test.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 ExampleCallBackApiService_GetCouponNotify() {
  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.CallBackApiService{Client: client}
  41. resp, result, err := svc.GetCouponNotify(ctx,
  42. merchantexclusivecoupon.GetCouponNotifyRequest{
  43. Mchid: core.String("98568888"),
  44. },
  45. )
  46. if err != nil {
  47. // 处理错误
  48. log.Printf("call GetCouponNotify err:%s", err)
  49. } else {
  50. // 处理返回结果
  51. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  52. }
  53. }
  54. func ExampleCallBackApiService_SetCouponNotify() {
  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.CallBackApiService{Client: client}
  77. resp, result, err := svc.SetCouponNotify(ctx,
  78. merchantexclusivecoupon.SetCouponNotifyRequest{
  79. Mchid: core.String("98568888"),
  80. NotifyUrl: core.String("https://pay.weixin.qq.com"),
  81. },
  82. )
  83. if err != nil {
  84. // 处理错误
  85. log.Printf("call SetCouponNotify err:%s", err)
  86. } else {
  87. // 处理返回结果
  88. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  89. }
  90. }