Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alipay v3 add api #429

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions alipay/v3/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,23 @@ const (
v3FundAuthOrderUnfreeze = "/v3/alipay/fund/auth/order/unfreeze" // 资金授权解冻接口
v3FundAuthOrderVoucherCreate = "/v3/alipay/fund/auth/order/voucher/create" // 资金授权发码接口

// 会员
v3UserCertifyOpenQuery = "/v3/alipay/user/certify/open/query" // 身份认证记录查询
v3UserCertifyOpenInitialize = "/v3/alipay/user/certify/open/initialize" // 身份认证初始化服务
v3SystemOauthToken = "/v3/alipay/system/oauth/token" // 换取授权访问令牌
v3UserInfoShare = "/v3/alipay/user/info/share" // 支付宝会员授权信息查询接口
v3UserAuthRelationshipQuery = "/v3/alipay/open/auth/userauth/relationship/query" // 用户授权关系查询
v3UserDelOauthDetailQuery = "/v3/alipay/user/deloauth/detail/query" // 查询解除授权明细
v3FaceVerificationInitialize = "/v3/datadigital/fincloud/generalsaas/face/verification/initialize" // 人脸核身初始化
v3FaceVerificationQuery = "/v3/datadigital/fincloud/generalsaas/face/verification/query" // 人脸核身结果查询
v3FaceCertifyInitialize = "/v3/datadigital/fincloud/generalsaas/face/certify/initialize" // 跳转支付宝人脸核身初始化
v3FaceCertifyVerify = "/v3/datadigital/fincloud/generalsaas/face/certify/verify" // 跳转支付宝人脸核身开始认证
v3FaceCertifyQuery = "/v3/datadigital/fincloud/generalsaas/face/certify/query" // 跳转支付宝人脸核身查询记录
v3FaceSourceCertify = "/v3/datadigital/fincloud/generalsaas/face/source/certify" // 纯服务端人脸核身
v3FaceCheckInitialize = "/v3/datadigital/fincloud/generalsaas/face/check/initialize" // 活体检测初始化
v3FaceCheckQuery = "/v3/datadigital/fincloud/generalsaas/face/check/query" // 活体检测结果查询
v3IdCardTwoMetaCheck = "/v3/datadigital/fincloud/generalsaas/twometa/check" // 身份证二要素核验
v3BankCardCheck = "/v3/datadigital/fincloud/generalsaas/bankcard/check" // 银行卡核验
v3OcrServerDetect = "/v3/datadigital/fincloud/generalsaas/ocr/server/detect" // 服务端OCR
v3OcrMobileInitialize = "/v3/datadigital/fincloud/generalsaas/ocr/mobile/initialize" // App端OCR初始化
)
118 changes: 118 additions & 0 deletions alipay/v3/fund_auth_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package alipay

import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/go-pay/gopay"
)

// 资金授权操作查询接口
// StatusCode = 200 is success
func (a *ClientV3) FundAuthOperationDetailQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *FundAuthOperationDetailQueryRsp, err error) {
authorization, err := a.authorization(MethodPost, v3FundAuthOperationDetailQuery, bm)
if err != nil {
return nil, err
}
res, bs, err := a.doPost(ctx, bm, v3FundAuthOperationDetailQuery, authorization)
if err != nil {
return nil, err
}
aliRsp = &FundAuthOperationDetailQueryRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 资金授权冻结接口
// StatusCode = 200 is success
func (a *ClientV3) FundAuthOrderFreeze(ctx context.Context, bm gopay.BodyMap) (aliRsp *FundAuthOrderFreezeRsp, err error) {
err = bm.CheckEmptyError("auth_code", "auth_code_type", "out_order_no", "out_request_no", "order_title", "product_code", "amount")
if err != nil {
return nil, err
}
authorization, err := a.authorization(MethodPost, v3FundAuthOrderFreeze, bm)
if err != nil {
return nil, err
}
res, bs, err := a.doPost(ctx, bm, v3FundAuthOrderFreeze, authorization)
if err != nil {
return nil, err
}
aliRsp = &FundAuthOrderFreezeRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 资金授权解冻接口
// StatusCode = 200 is success
func (a *ClientV3) FundAuthOrderUnfreeze(ctx context.Context, bm gopay.BodyMap) (aliRsp *FundAuthOrderUnfreezeRsp, err error) {
err = bm.CheckEmptyError("auth_no", "out_request_no", "amount", "remark")
if err != nil {
return nil, err
}
authorization, err := a.authorization(MethodPost, v3FundAuthOrderUnfreeze, bm)
if err != nil {
return nil, err
}
res, bs, err := a.doPost(ctx, bm, v3FundAuthOrderUnfreeze, authorization)
if err != nil {
return nil, err
}
aliRsp = &FundAuthOrderUnfreezeRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 资金授权发码接口
// StatusCode = 200 is success
func (a *ClientV3) FundAuthOrderVoucherCreate(ctx context.Context, bm gopay.BodyMap) (aliRsp *FundAuthOrderVoucherCreateRsp, err error) {
err = bm.CheckEmptyError("out_order_no", "out_request_no", "order_title", "amount", "product_code")
if err != nil {
return nil, err
}
authorization, err := a.authorization(MethodPost, v3FundAuthOrderVoucherCreate, bm)
if err != nil {
return nil, err
}
res, bs, err := a.doPost(ctx, bm, v3FundAuthOrderVoucherCreate, authorization)
if err != nil {
return nil, err
}
aliRsp = &FundAuthOrderVoucherCreateRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}
180 changes: 180 additions & 0 deletions alipay/v3/member_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
package alipay

import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/go-pay/gopay"
)

// 换取授权访问令牌
// StatusCode = 200 is success
func (a *ClientV3) SystemOauthToken(ctx context.Context, bm gopay.BodyMap) (aliRsp *SystemOauthTokenRsp, err error) {
err = bm.CheckEmptyError("grant_type")
if err != nil {
return nil, err
}
authorization, err := a.authorization(MethodPost, v3SystemOauthToken, bm)
if err != nil {
return nil, err
}
res, bs, err := a.doPost(ctx, bm, v3SystemOauthToken, authorization)
if err != nil {
return nil, err
}
aliRsp = &SystemOauthTokenRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 身份认证记录查询
// StatusCode = 200 is success
func (a *ClientV3) UserCertifyOpenQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserCertifyOpenQueryRsp, err error) {
err = bm.CheckEmptyError("certify_id")
if err != nil {
return nil, err
}
uri := v3UserCertifyOpenQuery + "?" + bm.EncodeURLParams()
authorization, err := a.authorization(MethodGet, uri, nil)
if err != nil {
return nil, err
}
res, bs, err := a.doGet(ctx, uri, authorization)
if err != nil {
return nil, err
}
aliRsp = &UserCertifyOpenQueryRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 身份认证初始化服务
// StatusCode = 200 is success
func (a *ClientV3) UserCertifyOpenInitialize(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserCertifyOpenInitializeRsp, err error) {
err = bm.CheckEmptyError("outer_order_no", "biz_code", "identity_param")
if err != nil {
return nil, err
}
authorization, err := a.authorization(MethodPost, v3UserCertifyOpenInitialize, bm)
if err != nil {
return nil, err
}
res, bs, err := a.doPost(ctx, bm, v3UserCertifyOpenInitialize, authorization)
if err != nil {
return nil, err
}
aliRsp = &UserCertifyOpenInitializeRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 支付宝会员授权信息查询接口
// StatusCode = 200 is success
func (a *ClientV3) UserInfoShare(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserInfoShareRsp, err error) {
err = bm.CheckEmptyError("avatar", "city", "nick_name", "province")
if err != nil {
return nil, err
}
authorization, err := a.authorization(MethodPost, v3UserInfoShare, bm)
if err != nil {
return nil, err
}
res, bs, err := a.doPost(ctx, bm, v3UserInfoShare, authorization)
if err != nil {
return nil, err
}
aliRsp = &UserInfoShareRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 用户授权关系查询
// StatusCode = 200 is success
func (a *ClientV3) UserAuthRelationshipQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserAuthRelationshipQueryRsp, err error) {
err = bm.CheckEmptyError("scopes")
if err != nil {
return nil, err
}
uri := v3UserAuthRelationshipQuery + "?" + bm.EncodeURLParams()
authorization, err := a.authorization(MethodGet, uri, nil)
if err != nil {
return nil, err
}
res, bs, err := a.doGet(ctx, uri, authorization)
if err != nil {
return nil, err
}
aliRsp = &UserAuthRelationshipQueryRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}

// 查询解除授权明细
// StatusCode = 200 is success
func (a *ClientV3) UserDelOauthDetailQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserDelOauthDetailQueryRsp, err error) {
err = bm.CheckEmptyError("date", "limit", "offset")
if err != nil {
return nil, err
}
authorization, err := a.authorization(MethodPost, v3UserDelOauthDetailQuery, bm)
if err != nil {
return nil, err
}
res, bs, err := a.doPost(ctx, bm, v3UserDelOauthDetailQuery, authorization)
if err != nil {
return nil, err
}
aliRsp = &UserDelOauthDetailQueryRsp{StatusCode: res.StatusCode}
if res.StatusCode != http.StatusOK {
if err = json.Unmarshal(bs, &aliRsp.ErrResponse); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, nil
}
if err = json.Unmarshal(bs, aliRsp); err != nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
return aliRsp, a.autoVerifySignByCert(res, bs)
}
Loading