api_relations_example_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2021 Tencent Inc. All rights reserved.
  2. //
  3. // 微工卡接口文档
  4. //
  5. // 服务商通过本API文档提供的接口,查询商户和微工卡的授权关系、生成预授权的token口令、核身预下单、核身结果的查询等。
  6. //
  7. // API version: 1.5.2
  8. // Code generated by WechatPay APIv3 Generator based on [OpenAPI Generator](https://openapi-generator.tech); DO NOT EDIT.
  9. package payrollcard_test
  10. import (
  11. "context"
  12. "log"
  13. "github.com/wechatpay-apiv3/wechatpay-go/core"
  14. "github.com/wechatpay-apiv3/wechatpay-go/core/option"
  15. "github.com/wechatpay-apiv3/wechatpay-go/services/payrollcard"
  16. "github.com/wechatpay-apiv3/wechatpay-go/utils"
  17. )
  18. func ExampleRelationsApiService_GetRelation() {
  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 := payrollcard.RelationsApiService{Client: client}
  41. resp, result, err := svc.GetRelation(ctx,
  42. payrollcard.GetRelationRequest{
  43. Openid: core.String("onqOjjmo8wmTOOtSKwXtGjg9Gb58"),
  44. SubMchid: core.String("1111111"),
  45. Appid: core.String("wxa1111111"),
  46. SubAppid: core.String("wxa1111111"),
  47. },
  48. )
  49. if err != nil {
  50. // 处理错误
  51. log.Printf("call GetRelation err:%s", err)
  52. } else {
  53. // 处理返回结果
  54. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  55. }
  56. }