api_transfer_detail_example_test.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2021 Tencent Inc. All rights reserved.
  2. //
  3. // 商家转账对外API
  4. //
  5. // * 场景及业务流程: 商户可通过该产品实现同时向多个用户微信零钱进行转账的操作,可用于发放奖金补贴、佣金货款结算、员工报销等场景。 [https://pay.weixin.qq.com/index.php/public/product/detail?pid=108&productType=0](https://pay.weixin.qq.com/index.php/public/product/detail?pid=108&productType=0) * 接入步骤: * 商户在微信支付商户平台开通“批量转账到零钱”产品权限,并勾选“使用API方式发起转账”。 * 调用批量转账接口,对多个用户微信零钱发起转账。 * 调用查询批次接口,可获取到转账批次详情及当前状态。 * 调用查询明细接口,可获取到单条转账明细详情及当前状态。
  6. //
  7. // API version: 1.0.5
  8. // Code generated by WechatPay APIv3 Generator based on [OpenAPI Generator](https://openapi-generator.tech); DO NOT EDIT.
  9. package transferbatch_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/transferbatch"
  16. "github.com/wechatpay-apiv3/wechatpay-go/utils"
  17. )
  18. func ExampleTransferDetailApiService_GetTransferDetailByNo() {
  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 := transferbatch.TransferDetailApiService{Client: client}
  41. resp, result, err := svc.GetTransferDetailByNo(ctx,
  42. transferbatch.GetTransferDetailByNoRequest{
  43. BatchId: core.String("1030000071100999991182020050700019480001"),
  44. DetailId: core.String("1040000071100999991182020050700019500100"),
  45. },
  46. )
  47. if err != nil {
  48. // 处理错误
  49. log.Printf("call GetTransferDetailByNo err:%s", err)
  50. } else {
  51. // 处理返回结果
  52. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  53. }
  54. }
  55. func ExampleTransferDetailApiService_GetTransferDetailByOutNo() {
  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.Printf("load merchant private key error:%s", err)
  65. return
  66. }
  67. ctx := context.Background()
  68. // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
  69. opts := []core.ClientOption{
  70. option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
  71. }
  72. client, err := core.NewClient(ctx, opts...)
  73. if err != nil {
  74. log.Printf("new wechat pay client err:%s", err)
  75. return
  76. }
  77. svc := transferbatch.TransferDetailApiService{Client: client}
  78. resp, result, err := svc.GetTransferDetailByOutNo(ctx,
  79. transferbatch.GetTransferDetailByOutNoRequest{
  80. OutDetailNo: core.String("x23zy545Bd5436"),
  81. OutBatchNo: core.String("plfk2020042013"),
  82. },
  83. )
  84. if err != nil {
  85. // 处理错误
  86. log.Printf("call GetTransferDetailByOutNo err:%s", err)
  87. } else {
  88. // 处理返回结果
  89. log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
  90. }
  91. }