-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01dfc8e
commit d5d11fa
Showing
7 changed files
with
484 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.