forked from wechatpay-apiv3/wechatpay-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_authentications.go
224 lines (191 loc) · 8.45 KB
/
api_authentications.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// Copyright 2021 Tencent Inc. All rights reserved.
//
// 微工卡接口文档
//
// 服务商通过本API文档提供的接口,查询商户和微工卡的授权关系、生成预授权的token口令、核身预下单、核身结果的查询等。
//
// API version: 1.5.2
// Code generated by WechatPay APIv3 Generator based on [OpenAPI Generator](https://openapi-generator.tech); DO NOT EDIT.
package payrollcard
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 AuthenticationsApiService services.Service
// GetAuthentication 获取核身结果
//
// 按商户拉起核身时预下单的单号获取该次微工卡核身的结果
func (a *AuthenticationsApiService) GetAuthentication(ctx context.Context, req GetAuthenticationRequest) (resp *AuthenticationEntity, 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.AuthenticateNumber == nil {
return nil, nil, fmt.Errorf("field `AuthenticateNumber` is required and must be specified in GetAuthenticationRequest")
}
localVarPath := consts.WechatPayAPIServer + "/v3/payroll-card/authentications/{authenticate_number}"
// Build Path with Path Params
localVarPath = strings.Replace(localVarPath, "{"+"authenticate_number"+"}", neturl.PathEscape(core.ParameterToString(*req.AuthenticateNumber, "")), -1)
// Make sure All Required Params are properly set
if req.SubMchid == nil {
return nil, nil, fmt.Errorf("field `SubMchid` is required and must be specified in GetAuthenticationRequest")
}
// Setup Query Params
localVarQueryParams = neturl.Values{}
localVarQueryParams.Add("sub_mchid", core.ParameterToString(*req.SubMchid, ""))
// 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 AuthenticationEntity from Http Response
resp = new(AuthenticationEntity)
err = core.UnMarshalResponse(result.Response, resp)
if err != nil {
return nil, result, err
}
return resp, result, nil
}
// ListAuthentications 查询核身记录
//
// 查询指定用户指定日期微工卡核身记录,查询结果仅展示核身成功的记录
func (a *AuthenticationsApiService) ListAuthentications(ctx context.Context, req ListAuthenticationsRequest) (resp *ListAuthenticationsResponse, result *core.APIResult, err error) {
var (
localVarHTTPMethod = nethttp.MethodGet
localVarPostBody interface{}
localVarQueryParams neturl.Values
localVarHeaderParams = nethttp.Header{}
)
localVarPath := consts.WechatPayAPIServer + "/v3/payroll-card/authentications"
// Make sure All Required Params are properly set
if req.Openid == nil {
return nil, nil, fmt.Errorf("field `Openid` is required and must be specified in ListAuthenticationsRequest")
}
if req.SubMchid == nil {
return nil, nil, fmt.Errorf("field `SubMchid` is required and must be specified in ListAuthenticationsRequest")
}
if req.AuthenticateDate == nil {
return nil, nil, fmt.Errorf("field `AuthenticateDate` is required and must be specified in ListAuthenticationsRequest")
}
// Setup Query Params
localVarQueryParams = neturl.Values{}
localVarQueryParams.Add("openid", core.ParameterToString(*req.Openid, ""))
if req.Appid != nil {
localVarQueryParams.Add("appid", core.ParameterToString(*req.Appid, ""))
}
if req.SubAppid != nil {
localVarQueryParams.Add("sub_appid", core.ParameterToString(*req.SubAppid, ""))
}
localVarQueryParams.Add("sub_mchid", core.ParameterToString(*req.SubMchid, ""))
localVarQueryParams.Add("authenticate_date", core.ParameterToString(*req.AuthenticateDate, ""))
if req.AuthenticateState != nil {
localVarQueryParams.Add("authenticate_state", core.ParameterToString(*req.AuthenticateState, ""))
}
if req.Offset != nil {
localVarQueryParams.Add("offset", core.ParameterToString(*req.Offset, ""))
}
if req.Limit != nil {
localVarQueryParams.Add("limit", core.ParameterToString(*req.Limit, ""))
}
// 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 ListAuthenticationsResponse from Http Response
resp = new(ListAuthenticationsResponse)
err = core.UnMarshalResponse(result.Response, resp)
if err != nil {
return nil, result, err
}
return resp, result, nil
}
// PreOrderAuthentication 微工卡核身预下单
//
// 服务商在拉起微工卡前端服务给用户做微工卡核身前,需要先调用本接口预下单,下单成功后才能进行核身
func (a *AuthenticationsApiService) PreOrderAuthentication(ctx context.Context, req PreOrderAuthenticationRequest) (resp *PreOrderAuthenticationResponse, result *core.APIResult, err error) {
var (
localVarHTTPMethod = nethttp.MethodPost
localVarPostBody interface{}
localVarQueryParams neturl.Values
localVarHeaderParams = nethttp.Header{}
)
localVarPath := consts.WechatPayAPIServer + "/v3/payroll-card/authentications/pre-order"
// 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 PreOrderAuthenticationResponse from Http Response
resp = new(PreOrderAuthenticationResponse)
err = core.UnMarshalResponse(result.Response, resp)
if err != nil {
return nil, result, err
}
return resp, result, nil
}
// PreOrderAuthenticationWithAuth 微工卡核身预下单(流程中完成授权)
//
// 本接口适用于用户需同步完成服务开通、授权及身份核验的场景。在拉起微工卡前端服务为用户核身前,需调用本接口预下单,下单成功后才能进行核身。如此时用户未开通微工卡服务或未完成对商户的授权,则先完成开通、授权,同步完成身份核验,并提供可信的核验结果。
func (a *AuthenticationsApiService) PreOrderAuthenticationWithAuth(ctx context.Context, req PreOrderAuthenticationWithAuthRequest) (resp *PreOrderAuthenticationWithAuthResponse, 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/payroll-card/authentications/pre-order-with-auth"
// 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 PreOrderAuthenticationWithAuthResponse from Http Response
resp = new(PreOrderAuthenticationWithAuthResponse)
err = core.UnMarshalResponse(result.Response, resp)
if err != nil {
return nil, result, err
}
return resp, result, nil
}