Skip to content

Commit 014f59b

Browse files
committed
alipay v3 add api
1 parent 7485422 commit 014f59b

7 files changed

+484
-10
lines changed

alipay/v3/constant.go

+19
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,23 @@ const (
6262
v3FundAuthOrderUnfreeze = "/v3/alipay/fund/auth/order/unfreeze" // 资金授权解冻接口
6363
v3FundAuthOrderVoucherCreate = "/v3/alipay/fund/auth/order/voucher/create" // 资金授权发码接口
6464

65+
// 会员
66+
v3UserCertifyOpenQuery = "/v3/alipay/user/certify/open/query" // 身份认证记录查询
67+
v3UserCertifyOpenInitialize = "/v3/alipay/user/certify/open/initialize" // 身份认证初始化服务
68+
v3SystemOauthToken = "/v3/alipay/system/oauth/token" // 换取授权访问令牌
69+
v3UserInfoShare = "/v3/alipay/user/info/share" // 支付宝会员授权信息查询接口
70+
v3UserAuthRelationshipQuery = "/v3/alipay/open/auth/userauth/relationship/query" // 用户授权关系查询
71+
v3UserDelOauthDetailQuery = "/v3/alipay/user/deloauth/detail/query" // 查询解除授权明细
72+
v3FaceVerificationInitialize = "/v3/datadigital/fincloud/generalsaas/face/verification/initialize" // 人脸核身初始化
73+
v3FaceVerificationQuery = "/v3/datadigital/fincloud/generalsaas/face/verification/query" // 人脸核身结果查询
74+
v3FaceCertifyInitialize = "/v3/datadigital/fincloud/generalsaas/face/certify/initialize" // 跳转支付宝人脸核身初始化
75+
v3FaceCertifyVerify = "/v3/datadigital/fincloud/generalsaas/face/certify/verify" // 跳转支付宝人脸核身开始认证
76+
v3FaceCertifyQuery = "/v3/datadigital/fincloud/generalsaas/face/certify/query" // 跳转支付宝人脸核身查询记录
77+
v3FaceSourceCertify = "/v3/datadigital/fincloud/generalsaas/face/source/certify" // 纯服务端人脸核身
78+
v3FaceCheckInitialize = "/v3/datadigital/fincloud/generalsaas/face/check/initialize" // 活体检测初始化
79+
v3FaceCheckQuery = "/v3/datadigital/fincloud/generalsaas/face/check/query" // 活体检测结果查询
80+
v3IdCardTwoMetaCheck = "/v3/datadigital/fincloud/generalsaas/twometa/check" // 身份证二要素核验
81+
v3BankCardCheck = "/v3/datadigital/fincloud/generalsaas/bankcard/check" // 银行卡核验
82+
v3OcrServerDetect = "/v3/datadigital/fincloud/generalsaas/ocr/server/detect" // 服务端OCR
83+
v3OcrMobileInitialize = "/v3/datadigital/fincloud/generalsaas/ocr/mobile/initialize" // App端OCR初始化
6584
)

alipay/v3/fund_auth_api.go

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package alipay
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"net/http"
8+
9+
"github.com/go-pay/gopay"
10+
)
11+
12+
// 资金授权操作查询接口
13+
// StatusCode = 200 is success
14+
func (a *ClientV3) FundAuthOperationDetailQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *FundAuthOperationDetailQueryRsp, err error) {
15+
authorization, err := a.authorization(MethodPost, v3FundAuthOperationDetailQuery, bm)
16+
if err != nil {
17+
return nil, err
18+
}
19+
res, bs, err := a.doPost(ctx, bm, v3FundAuthOperationDetailQuery, authorization)
20+
if err != nil {
21+
return nil, err
22+
}
23+
aliRsp = &FundAuthOperationDetailQueryRsp{StatusCode: res.StatusCode}
24+
if res.StatusCode != http.StatusOK {
25+
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
26+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
27+
}
28+
return aliRsp, nil
29+
}
30+
if err = json.Unmarshal(bs, aliRsp); err != nil {
31+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
32+
}
33+
return aliRsp, a.autoVerifySignByCert(res, bs)
34+
}
35+
36+
// 资金授权冻结接口
37+
// StatusCode = 200 is success
38+
func (a *ClientV3) FundAuthOrderFreeze(ctx context.Context, bm gopay.BodyMap) (aliRsp *FundAuthOrderFreezeRsp, err error) {
39+
err = bm.CheckEmptyError("auth_code", "auth_code_type", "out_order_no", "out_request_no", "order_title", "product_code", "amount")
40+
if err != nil {
41+
return nil, err
42+
}
43+
authorization, err := a.authorization(MethodPost, v3FundAuthOrderFreeze, bm)
44+
if err != nil {
45+
return nil, err
46+
}
47+
res, bs, err := a.doPost(ctx, bm, v3FundAuthOrderFreeze, authorization)
48+
if err != nil {
49+
return nil, err
50+
}
51+
aliRsp = &FundAuthOrderFreezeRsp{StatusCode: res.StatusCode}
52+
if res.StatusCode != http.StatusOK {
53+
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
54+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
55+
}
56+
return aliRsp, nil
57+
}
58+
if err = json.Unmarshal(bs, aliRsp); err != nil {
59+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
60+
}
61+
return aliRsp, a.autoVerifySignByCert(res, bs)
62+
}
63+
64+
// 资金授权解冻接口
65+
// StatusCode = 200 is success
66+
func (a *ClientV3) FundAuthOrderUnfreeze(ctx context.Context, bm gopay.BodyMap) (aliRsp *FundAuthOrderUnfreezeRsp, err error) {
67+
err = bm.CheckEmptyError("auth_no", "out_request_no", "amount", "remark")
68+
if err != nil {
69+
return nil, err
70+
}
71+
authorization, err := a.authorization(MethodPost, v3FundAuthOrderUnfreeze, bm)
72+
if err != nil {
73+
return nil, err
74+
}
75+
res, bs, err := a.doPost(ctx, bm, v3FundAuthOrderUnfreeze, authorization)
76+
if err != nil {
77+
return nil, err
78+
}
79+
aliRsp = &FundAuthOrderUnfreezeRsp{StatusCode: res.StatusCode}
80+
if res.StatusCode != http.StatusOK {
81+
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
82+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
83+
}
84+
return aliRsp, nil
85+
}
86+
if err = json.Unmarshal(bs, aliRsp); err != nil {
87+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
88+
}
89+
return aliRsp, a.autoVerifySignByCert(res, bs)
90+
}
91+
92+
// 资金授权发码接口
93+
// StatusCode = 200 is success
94+
func (a *ClientV3) FundAuthOrderVoucherCreate(ctx context.Context, bm gopay.BodyMap) (aliRsp *FundAuthOrderVoucherCreateRsp, err error) {
95+
err = bm.CheckEmptyError("out_order_no", "out_request_no", "order_title", "amount", "product_code")
96+
if err != nil {
97+
return nil, err
98+
}
99+
authorization, err := a.authorization(MethodPost, v3FundAuthOrderVoucherCreate, bm)
100+
if err != nil {
101+
return nil, err
102+
}
103+
res, bs, err := a.doPost(ctx, bm, v3FundAuthOrderVoucherCreate, authorization)
104+
if err != nil {
105+
return nil, err
106+
}
107+
aliRsp = &FundAuthOrderVoucherCreateRsp{StatusCode: res.StatusCode}
108+
if res.StatusCode != http.StatusOK {
109+
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
110+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
111+
}
112+
return aliRsp, nil
113+
}
114+
if err = json.Unmarshal(bs, aliRsp); err != nil {
115+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
116+
}
117+
return aliRsp, a.autoVerifySignByCert(res, bs)
118+
}

alipay/v3/member_api.go

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
package alipay
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"net/http"
8+
9+
"github.com/go-pay/gopay"
10+
)
11+
12+
// 换取授权访问令牌
13+
// StatusCode = 200 is success
14+
func (a *ClientV3) SystemOauthToken(ctx context.Context, bm gopay.BodyMap) (aliRsp *SystemOauthTokenRsp, err error) {
15+
err = bm.CheckEmptyError("grant_type")
16+
if err != nil {
17+
return nil, err
18+
}
19+
authorization, err := a.authorization(MethodPost, v3SystemOauthToken, bm)
20+
if err != nil {
21+
return nil, err
22+
}
23+
res, bs, err := a.doPost(ctx, bm, v3SystemOauthToken, authorization)
24+
if err != nil {
25+
return nil, err
26+
}
27+
aliRsp = &SystemOauthTokenRsp{StatusCode: res.StatusCode}
28+
if res.StatusCode != http.StatusOK {
29+
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
30+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
31+
}
32+
return aliRsp, nil
33+
}
34+
if err = json.Unmarshal(bs, aliRsp); err != nil {
35+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
36+
}
37+
return aliRsp, a.autoVerifySignByCert(res, bs)
38+
}
39+
40+
// 身份认证记录查询
41+
// StatusCode = 200 is success
42+
func (a *ClientV3) UserCertifyOpenQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserCertifyOpenQueryRsp, err error) {
43+
err = bm.CheckEmptyError("certify_id")
44+
if err != nil {
45+
return nil, err
46+
}
47+
uri := v3UserCertifyOpenQuery + "?" + bm.EncodeURLParams()
48+
authorization, err := a.authorization(MethodGet, uri, nil)
49+
if err != nil {
50+
return nil, err
51+
}
52+
res, bs, err := a.doGet(ctx, uri, authorization)
53+
if err != nil {
54+
return nil, err
55+
}
56+
aliRsp = &UserCertifyOpenQueryRsp{StatusCode: res.StatusCode}
57+
if res.StatusCode != http.StatusOK {
58+
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
59+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
60+
}
61+
return aliRsp, nil
62+
}
63+
if err = json.Unmarshal(bs, aliRsp); err != nil {
64+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
65+
}
66+
return aliRsp, a.autoVerifySignByCert(res, bs)
67+
}
68+
69+
// 身份认证初始化服务
70+
// StatusCode = 200 is success
71+
func (a *ClientV3) UserCertifyOpenInitialize(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserCertifyOpenInitializeRsp, err error) {
72+
err = bm.CheckEmptyError("outer_order_no", "biz_code", "identity_param")
73+
if err != nil {
74+
return nil, err
75+
}
76+
authorization, err := a.authorization(MethodPost, v3UserCertifyOpenInitialize, bm)
77+
if err != nil {
78+
return nil, err
79+
}
80+
res, bs, err := a.doPost(ctx, bm, v3UserCertifyOpenInitialize, authorization)
81+
if err != nil {
82+
return nil, err
83+
}
84+
aliRsp = &UserCertifyOpenInitializeRsp{StatusCode: res.StatusCode}
85+
if res.StatusCode != http.StatusOK {
86+
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
87+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
88+
}
89+
return aliRsp, nil
90+
}
91+
if err = json.Unmarshal(bs, aliRsp); err != nil {
92+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
93+
}
94+
return aliRsp, a.autoVerifySignByCert(res, bs)
95+
}
96+
97+
// 支付宝会员授权信息查询接口
98+
// StatusCode = 200 is success
99+
func (a *ClientV3) UserInfoShare(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserInfoShareRsp, err error) {
100+
err = bm.CheckEmptyError("avatar", "city", "nick_name", "province")
101+
if err != nil {
102+
return nil, err
103+
}
104+
authorization, err := a.authorization(MethodPost, v3UserInfoShare, bm)
105+
if err != nil {
106+
return nil, err
107+
}
108+
res, bs, err := a.doPost(ctx, bm, v3UserInfoShare, authorization)
109+
if err != nil {
110+
return nil, err
111+
}
112+
aliRsp = &UserInfoShareRsp{StatusCode: res.StatusCode}
113+
if res.StatusCode != http.StatusOK {
114+
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
115+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
116+
}
117+
return aliRsp, nil
118+
}
119+
if err = json.Unmarshal(bs, aliRsp); err != nil {
120+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
121+
}
122+
return aliRsp, a.autoVerifySignByCert(res, bs)
123+
}
124+
125+
// 用户授权关系查询
126+
// StatusCode = 200 is success
127+
func (a *ClientV3) UserAuthRelationshipQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserAuthRelationshipQueryRsp, err error) {
128+
err = bm.CheckEmptyError("scopes")
129+
if err != nil {
130+
return nil, err
131+
}
132+
uri := v3UserAuthRelationshipQuery + "?" + bm.EncodeURLParams()
133+
authorization, err := a.authorization(MethodGet, uri, nil)
134+
if err != nil {
135+
return nil, err
136+
}
137+
res, bs, err := a.doGet(ctx, uri, authorization)
138+
if err != nil {
139+
return nil, err
140+
}
141+
aliRsp = &UserAuthRelationshipQueryRsp{StatusCode: res.StatusCode}
142+
if res.StatusCode != http.StatusOK {
143+
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
144+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
145+
}
146+
return aliRsp, nil
147+
}
148+
if err = json.Unmarshal(bs, aliRsp); err != nil {
149+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
150+
}
151+
return aliRsp, a.autoVerifySignByCert(res, bs)
152+
}
153+
154+
// 查询解除授权明细
155+
// StatusCode = 200 is success
156+
func (a *ClientV3) UserDelOauthDetailQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserDelOauthDetailQueryRsp, err error) {
157+
err = bm.CheckEmptyError("date", "limit", "offset")
158+
if err != nil {
159+
return nil, err
160+
}
161+
authorization, err := a.authorization(MethodPost, v3UserDelOauthDetailQuery, bm)
162+
if err != nil {
163+
return nil, err
164+
}
165+
res, bs, err := a.doPost(ctx, bm, v3UserDelOauthDetailQuery, authorization)
166+
if err != nil {
167+
return nil, err
168+
}
169+
aliRsp = &UserDelOauthDetailQueryRsp{StatusCode: res.StatusCode}
170+
if res.StatusCode != http.StatusOK {
171+
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
172+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
173+
}
174+
return aliRsp, nil
175+
}
176+
if err = json.Unmarshal(bs, aliRsp); err != nil {
177+
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
178+
}
179+
return aliRsp, a.autoVerifySignByCert(res, bs)
180+
}

0 commit comments

Comments
 (0)