forked from wechatpay-apiv3/wechatpay-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_transfer_batch.go
190 lines (161 loc) · 7.95 KB
/
api_transfer_batch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Copyright 2021 Tencent Inc. All rights reserved.
//
// 商家转账对外API
//
// * 场景及业务流程: 商户可通过该产品实现同时向多个用户微信零钱进行转账的操作,可用于发放奖金补贴、佣金货款结算、员工报销等场景。 [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方式发起转账”。 * 调用批量转账接口,对多个用户微信零钱发起转账。 * 调用查询批次接口,可获取到转账批次详情及当前状态。 * 调用查询明细接口,可获取到单条转账明细详情及当前状态。
//
// API version: 1.0.5
// Code generated by WechatPay APIv3 Generator based on [OpenAPI Generator](https://openapi-generator.tech); DO NOT EDIT.
package transferbatch
import (
"context"
"fmt"
nethttp "net/http"
neturl "net/url"
"strings"
"github.com/rjm521/wechatpay-go/core"
"github.com/rjm521/wechatpay-go/core/consts"
"github.com/rjm521/wechatpay-go/services"
)
type TransferBatchApiService services.Service
// GetTransferBatchByNo 通过微信批次单号查询批次单
//
// 微信批次单号查单接口。商户可以通过该接口查询转账批次单以及指定状态的转账明细单。返回消息中包含微信批次单号、批次状态、批次类型、转账总金额、转账总笔数、成功金额、失败金额等信息。
func (a *TransferBatchApiService) GetTransferBatchByNo(ctx context.Context, req GetTransferBatchByNoRequest) (resp *TransferBatchEntity, result *core.APIResult, err error) {
var (
localVarHTTPMethod = nethttp.MethodGet
localVarPostBody interface{}
localVarQueryParams neturl.Values
localVarHeaderParams = nethttp.Header{}
)
// Make sure Path Params are properly set
if req.BatchId == nil {
return nil, nil, fmt.Errorf("field `BatchId` is required and must be specified in GetTransferBatchByNoRequest")
}
localVarPath := consts.WechatPayAPIServer + "/v3/transfer/batches/batch-id/{batch_id}"
// Build Path with Path Params
localVarPath = strings.Replace(localVarPath, "{"+"batch_id"+"}", neturl.PathEscape(core.ParameterToString(*req.BatchId, "")), -1)
// Make sure All Required Params are properly set
if req.NeedQueryDetail == nil {
return nil, nil, fmt.Errorf("field `NeedQueryDetail` is required and must be specified in GetTransferBatchByNoRequest")
}
// Setup Query Params
localVarQueryParams = neturl.Values{}
localVarQueryParams.Add("need_query_detail", core.ParameterToString(*req.NeedQueryDetail, ""))
if req.Offset != nil {
localVarQueryParams.Add("offset", core.ParameterToString(*req.Offset, ""))
}
if req.Limit != nil {
localVarQueryParams.Add("limit", core.ParameterToString(*req.Limit, ""))
}
if req.DetailStatus != nil {
localVarQueryParams.Add("detail_status", core.ParameterToString(*req.DetailStatus, ""))
}
// Determine the Content-Type Header
localVarHTTPContentTypes := []string{}
// Setup Content-Type
localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
// Perform Http Request
result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
if err != nil {
return nil, result, err
}
// Extract TransferBatchEntity from Http Response
resp = new(TransferBatchEntity)
err = core.UnMarshalResponse(result.Response, resp)
if err != nil {
return nil, result, err
}
return resp, result, nil
}
// GetTransferBatchByOutNo 通过商家批次单号查询批次单
//
// 商家明细单号查单接口。商户可以通过该接口查询转账批次单以及指定状态的转账明细单。返回消息中包含微信批次单号、批次状态、批次类型、转账总金额、转账总笔数、成功金额、失败金额等信息。
func (a *TransferBatchApiService) GetTransferBatchByOutNo(ctx context.Context, req GetTransferBatchByOutNoRequest) (resp *TransferBatchEntity, result *core.APIResult, err error) {
var (
localVarHTTPMethod = nethttp.MethodGet
localVarPostBody interface{}
localVarQueryParams neturl.Values
localVarHeaderParams = nethttp.Header{}
)
// Make sure Path Params are properly set
if req.OutBatchNo == nil {
return nil, nil, fmt.Errorf("field `OutBatchNo` is required and must be specified in GetTransferBatchByOutNoRequest")
}
localVarPath := consts.WechatPayAPIServer + "/v3/transfer/batches/out-batch-no/{out_batch_no}"
// Build Path with Path Params
localVarPath = strings.Replace(localVarPath, "{"+"out_batch_no"+"}", neturl.PathEscape(core.ParameterToString(*req.OutBatchNo, "")), -1)
// Make sure All Required Params are properly set
if req.NeedQueryDetail == nil {
return nil, nil, fmt.Errorf("field `NeedQueryDetail` is required and must be specified in GetTransferBatchByOutNoRequest")
}
// Setup Query Params
localVarQueryParams = neturl.Values{}
localVarQueryParams.Add("need_query_detail", core.ParameterToString(*req.NeedQueryDetail, ""))
if req.Offset != nil {
localVarQueryParams.Add("offset", core.ParameterToString(*req.Offset, ""))
}
if req.Limit != nil {
localVarQueryParams.Add("limit", core.ParameterToString(*req.Limit, ""))
}
if req.DetailStatus != nil {
localVarQueryParams.Add("detail_status", core.ParameterToString(*req.DetailStatus, ""))
}
// Determine the Content-Type Header
localVarHTTPContentTypes := []string{}
// Setup Content-Type
localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
// Perform Http Request
result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
if err != nil {
return nil, result, err
}
// Extract TransferBatchEntity from Http Response
resp = new(TransferBatchEntity)
err = core.UnMarshalResponse(result.Response, resp)
if err != nil {
return nil, result, err
}
return resp, result, nil
}
// InitiateBatchTransfer 发起商家转账
//
// 发起商家转账接口。商户可以通过该接口同时向多个用户微信零钱进行转账操作。请求消息中应包含商家批次单号、转账名称、appid、转账总金额、转账总笔数、转账openid、收款用户姓名等信息。注意受理成功将返回批次单号,此时并不代表转账成功,请通过查单接口查询单据的付款状态。
func (a *TransferBatchApiService) InitiateBatchTransfer(ctx context.Context, req InitiateBatchTransferRequest) (resp *InitiateBatchTransferResponse, result *core.APIResult, err error) {
var (
localVarHTTPMethod = nethttp.MethodPost
localVarPostBody interface{}
localVarQueryParams neturl.Values
localVarHeaderParams = nethttp.Header{}
)
// 对请求中敏感字段进行加密
encReq := req.Clone()
encryptCertificate, err := a.Client.EncryptRequest(ctx, encReq)
if err != nil {
return nil, nil, fmt.Errorf("encrypt request failed: %v", err)
}
if encryptCertificate != "" {
localVarHeaderParams.Set(consts.WechatPaySerial, encryptCertificate)
}
req = *encReq
localVarPath := consts.WechatPayAPIServer + "/v3/transfer/batches"
// Make sure All Required Params are properly set
// Setup Body Params
localVarPostBody = req
// Determine the Content-Type Header
localVarHTTPContentTypes := []string{"application/json"}
// Setup Content-Type
localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
// Perform Http Request
result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
if err != nil {
return nil, result, err
}
// Extract InitiateBatchTransferResponse from Http Response
resp = new(InitiateBatchTransferResponse)
err = core.UnMarshalResponse(result.Response, resp)
if err != nil {
return nil, result, err
}
return resp, result, nil
}