api_brands_example_test.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2021 Tencent Inc. All rights reserved.
  2. //
  3. // 爱心餐对外API
  4. //
  5. // 微信支付爱心餐公益计划旨在面向深圳市的市政一线环卫工人提供每周一餐的1分钱用餐公益服务。在受助端,微信支付联动上千家餐饮门店关爱特殊人群,通过微信支付数字化能力将人群身份认证与公益福利领用全流程线上化,实现公益福利精准到人。在捐赠端,微信支付发挥连接优势与平台能力,结合用户就餐场景通过爱心餐一块捐插件让用户可在点餐时顺手捐1元,带动更多社会力量致谢城市美容师。
  6. //
  7. // API version: 0.0.4
  8. // Code generated by WechatPay APIv3 Generator based on [OpenAPI Generator](https://openapi-generator.tech); DO NOT EDIT.
  9. package lovefeast_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/lovefeast"
  16. "git.nanodreamtech.com/sg/wechatpay-go/utils"
  17. )
  18. func ExampleBrandsApiService_GetBrand() {
  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 := lovefeast.BrandsApiService{Client: client}
  41. resp, result, err := svc.GetBrand(ctx,
  42. lovefeast.GetBrandRequest{
  43. BrandId: core.Int64(1442),
  44. },
  45. )
  46. if err != nil {
  47. // 处理错误
  48. log.Printf("call GetBrand err:%s", err)
  49. } else {
  50. // 处理返回结果
  51. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  52. }
  53. }