api_authentications.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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
  10. import (
  11. "context"
  12. "fmt"
  13. nethttp "net/http"
  14. neturl "net/url"
  15. "strings"
  16. "github.com/wechatpay-apiv3/wechatpay-go/core"
  17. "github.com/wechatpay-apiv3/wechatpay-go/core/consts"
  18. "github.com/wechatpay-apiv3/wechatpay-go/services"
  19. )
  20. type AuthenticationsApiService services.Service
  21. // GetAuthentication 获取核身结果
  22. //
  23. // 按商户拉起核身时预下单的单号获取该次微工卡核身的结果
  24. func (a *AuthenticationsApiService) GetAuthentication(ctx context.Context, req GetAuthenticationRequest) (resp *AuthenticationEntity, result *core.APIResult, err error) {
  25. var (
  26. localVarHTTPMethod = nethttp.MethodGet
  27. localVarPostBody interface{}
  28. localVarQueryParams neturl.Values
  29. localVarHeaderParams = nethttp.Header{}
  30. )
  31. // Make sure Path Params are properly set
  32. if req.AuthenticateNumber == nil {
  33. return nil, nil, fmt.Errorf("field `AuthenticateNumber` is required and must be specified in GetAuthenticationRequest")
  34. }
  35. localVarPath := consts.WechatPayAPIServer + "/v3/payroll-card/authentications/{authenticate_number}"
  36. // Build Path with Path Params
  37. localVarPath = strings.Replace(localVarPath, "{"+"authenticate_number"+"}", neturl.PathEscape(core.ParameterToString(*req.AuthenticateNumber, "")), -1)
  38. // Make sure All Required Params are properly set
  39. if req.SubMchid == nil {
  40. return nil, nil, fmt.Errorf("field `SubMchid` is required and must be specified in GetAuthenticationRequest")
  41. }
  42. // Setup Query Params
  43. localVarQueryParams = neturl.Values{}
  44. localVarQueryParams.Add("sub_mchid", core.ParameterToString(*req.SubMchid, ""))
  45. // Determine the Content-Type Header
  46. localVarHTTPContentTypes := []string{}
  47. // Setup Content-Type
  48. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  49. // Perform Http Request
  50. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  51. if err != nil {
  52. return nil, result, err
  53. }
  54. // Extract AuthenticationEntity from Http Response
  55. resp = new(AuthenticationEntity)
  56. err = core.UnMarshalResponse(result.Response, resp)
  57. if err != nil {
  58. return nil, result, err
  59. }
  60. return resp, result, nil
  61. }
  62. // ListAuthentications 查询核身记录
  63. //
  64. // 查询指定用户指定日期微工卡核身记录,查询结果仅展示核身成功的记录
  65. func (a *AuthenticationsApiService) ListAuthentications(ctx context.Context, req ListAuthenticationsRequest) (resp *ListAuthenticationsResponse, result *core.APIResult, err error) {
  66. var (
  67. localVarHTTPMethod = nethttp.MethodGet
  68. localVarPostBody interface{}
  69. localVarQueryParams neturl.Values
  70. localVarHeaderParams = nethttp.Header{}
  71. )
  72. localVarPath := consts.WechatPayAPIServer + "/v3/payroll-card/authentications"
  73. // Make sure All Required Params are properly set
  74. if req.Openid == nil {
  75. return nil, nil, fmt.Errorf("field `Openid` is required and must be specified in ListAuthenticationsRequest")
  76. }
  77. if req.SubMchid == nil {
  78. return nil, nil, fmt.Errorf("field `SubMchid` is required and must be specified in ListAuthenticationsRequest")
  79. }
  80. if req.AuthenticateDate == nil {
  81. return nil, nil, fmt.Errorf("field `AuthenticateDate` is required and must be specified in ListAuthenticationsRequest")
  82. }
  83. // Setup Query Params
  84. localVarQueryParams = neturl.Values{}
  85. localVarQueryParams.Add("openid", core.ParameterToString(*req.Openid, ""))
  86. if req.Appid != nil {
  87. localVarQueryParams.Add("appid", core.ParameterToString(*req.Appid, ""))
  88. }
  89. if req.SubAppid != nil {
  90. localVarQueryParams.Add("sub_appid", core.ParameterToString(*req.SubAppid, ""))
  91. }
  92. localVarQueryParams.Add("sub_mchid", core.ParameterToString(*req.SubMchid, ""))
  93. localVarQueryParams.Add("authenticate_date", core.ParameterToString(*req.AuthenticateDate, ""))
  94. if req.AuthenticateState != nil {
  95. localVarQueryParams.Add("authenticate_state", core.ParameterToString(*req.AuthenticateState, ""))
  96. }
  97. if req.Offset != nil {
  98. localVarQueryParams.Add("offset", core.ParameterToString(*req.Offset, ""))
  99. }
  100. if req.Limit != nil {
  101. localVarQueryParams.Add("limit", core.ParameterToString(*req.Limit, ""))
  102. }
  103. // Determine the Content-Type Header
  104. localVarHTTPContentTypes := []string{}
  105. // Setup Content-Type
  106. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  107. // Perform Http Request
  108. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  109. if err != nil {
  110. return nil, result, err
  111. }
  112. // Extract ListAuthenticationsResponse from Http Response
  113. resp = new(ListAuthenticationsResponse)
  114. err = core.UnMarshalResponse(result.Response, resp)
  115. if err != nil {
  116. return nil, result, err
  117. }
  118. return resp, result, nil
  119. }
  120. // PreOrderAuthentication 微工卡核身预下单
  121. //
  122. // 服务商在拉起微工卡前端服务给用户做微工卡核身前,需要先调用本接口预下单,下单成功后才能进行核身
  123. func (a *AuthenticationsApiService) PreOrderAuthentication(ctx context.Context, req PreOrderAuthenticationRequest) (resp *PreOrderAuthenticationResponse, result *core.APIResult, err error) {
  124. var (
  125. localVarHTTPMethod = nethttp.MethodPost
  126. localVarPostBody interface{}
  127. localVarQueryParams neturl.Values
  128. localVarHeaderParams = nethttp.Header{}
  129. )
  130. localVarPath := consts.WechatPayAPIServer + "/v3/payroll-card/authentications/pre-order"
  131. // Make sure All Required Params are properly set
  132. // Setup Body Params
  133. localVarPostBody = req
  134. // Determine the Content-Type Header
  135. localVarHTTPContentTypes := []string{"application/json"}
  136. // Setup Content-Type
  137. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  138. // Perform Http Request
  139. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  140. if err != nil {
  141. return nil, result, err
  142. }
  143. // Extract PreOrderAuthenticationResponse from Http Response
  144. resp = new(PreOrderAuthenticationResponse)
  145. err = core.UnMarshalResponse(result.Response, resp)
  146. if err != nil {
  147. return nil, result, err
  148. }
  149. return resp, result, nil
  150. }
  151. // PreOrderAuthenticationWithAuth 微工卡核身预下单(流程中完成授权)
  152. //
  153. // 本接口适用于用户需同步完成服务开通、授权及身份核验的场景。在拉起微工卡前端服务为用户核身前,需调用本接口预下单,下单成功后才能进行核身。如此时用户未开通微工卡服务或未完成对商户的授权,则先完成开通、授权,同步完成身份核验,并提供可信的核验结果。
  154. func (a *AuthenticationsApiService) PreOrderAuthenticationWithAuth(ctx context.Context, req PreOrderAuthenticationWithAuthRequest) (resp *PreOrderAuthenticationWithAuthResponse, result *core.APIResult, err error) {
  155. var (
  156. localVarHTTPMethod = nethttp.MethodPost
  157. localVarPostBody interface{}
  158. localVarQueryParams neturl.Values
  159. localVarHeaderParams = nethttp.Header{}
  160. )
  161. // 对请求中敏感字段进行加密
  162. encReq := req.Clone()
  163. encryptCertificate, err := a.Client.EncryptRequest(ctx, encReq)
  164. if err != nil {
  165. return nil, nil, fmt.Errorf("encrypt request failed: %v", err)
  166. }
  167. if encryptCertificate != "" {
  168. localVarHeaderParams.Set(consts.WechatPaySerial, encryptCertificate)
  169. }
  170. req = *encReq
  171. localVarPath := consts.WechatPayAPIServer + "/v3/payroll-card/authentications/pre-order-with-auth"
  172. // Make sure All Required Params are properly set
  173. // Setup Body Params
  174. localVarPostBody = req
  175. // Determine the Content-Type Header
  176. localVarHTTPContentTypes := []string{"application/json"}
  177. // Setup Content-Type
  178. localVarHTTPContentType := core.SelectHeaderContentType(localVarHTTPContentTypes)
  179. // Perform Http Request
  180. result, err = a.Client.Request(ctx, localVarHTTPMethod, localVarPath, localVarHeaderParams, localVarQueryParams, localVarPostBody, localVarHTTPContentType)
  181. if err != nil {
  182. return nil, result, err
  183. }
  184. // Extract PreOrderAuthenticationWithAuthResponse from Http Response
  185. resp = new(PreOrderAuthenticationWithAuthResponse)
  186. err = core.UnMarshalResponse(result.Response, resp)
  187. if err != nil {
  188. return nil, result, err
  189. }
  190. return resp, result, nil
  191. }