-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
397 additions
and
253 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
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,82 @@ | ||
package alipay | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/go-pay/gopay" | ||
"github.com/go-pay/gopay/pkg/util" | ||
) | ||
|
||
// alipay.open.auth.token.app(换取应用授权令牌) | ||
// 文档地址:https://opendocs.alipay.com/isv/04h3uf | ||
func (a *Client) OpenAuthTokenApp(ctx context.Context, bm gopay.BodyMap) (aliRsp *OpenAuthTokenAppResponse, err error) { | ||
if bm.GetString("code") == util.NULL && bm.GetString("refresh_token") == util.NULL { | ||
return nil, errors.New("code and refresh_token are not allowed to be null at the same time") | ||
} | ||
err = bm.CheckEmptyError("grant_type") | ||
if err != nil { | ||
return nil, err | ||
} | ||
var bs []byte | ||
if bs, err = a.doAliPay(ctx, bm, "alipay.open.auth.token.app"); err != nil { | ||
return nil, err | ||
} | ||
aliRsp = new(OpenAuthTokenAppResponse) | ||
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil { | ||
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs)) | ||
} | ||
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil { | ||
return aliRsp, err | ||
} | ||
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn) | ||
aliRsp.SignData = signData | ||
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr) | ||
} | ||
|
||
// alipay.open.auth.token.app.query(查询某个应用授权AppAuthToken的授权信息) | ||
// 文档地址:https://opendocs.alipay.com/isv/04hgcp | ||
func (a *Client) OpenAuthTokenAppQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *OpenAuthTokenAppQueryResponse, err error) { | ||
err = bm.CheckEmptyError("app_auth_token") | ||
if err != nil { | ||
return nil, err | ||
} | ||
var bs []byte | ||
if bs, err = a.doAliPay(ctx, bm, "alipay.open.auth.token.app.query"); err != nil { | ||
return nil, err | ||
} | ||
aliRsp = new(OpenAuthTokenAppQueryResponse) | ||
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil { | ||
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs)) | ||
} | ||
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil { | ||
return aliRsp, err | ||
} | ||
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn) | ||
aliRsp.SignData = signData | ||
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr) | ||
} | ||
|
||
// alipay.open.auth.appauth.invite.create(ISV向商户发起应用授权邀约) | ||
// 文档地址:https://opendocs.alipay.com/isv/06evao | ||
func (a *Client) OpenAuthTokenAppInviteCreate(ctx context.Context, bm gopay.BodyMap) (aliRsp *OpenAuthTokenAppInviteCreateResponse, err error) { | ||
if err = bm.CheckEmptyError("auth_app_id"); err != nil { | ||
return nil, err | ||
} | ||
var bs []byte | ||
if bs, err = a.doAliPay(ctx, bm, "alipay.open.auth.appauth.invite.create"); err != nil { | ||
return nil, err | ||
} | ||
aliRsp = new(OpenAuthTokenAppInviteCreateResponse) | ||
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil { | ||
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs)) | ||
} | ||
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil { | ||
return aliRsp, err | ||
} | ||
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn) | ||
aliRsp.SignData = signData | ||
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr) | ||
} |
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,32 @@ | ||
package alipay | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/go-pay/gopay" | ||
) | ||
|
||
// alipay.open.app.api.query(查询应用可申请的接口出参敏感字段列表) | ||
// 文档地址:https://opendocs.alipay.com/isv/04f74n | ||
func (a *Client) OpenAppApiQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *OpenAppApiQueryResponse, err error) { | ||
err = bm.CheckEmptyError("app_auth_token") | ||
if err != nil { | ||
return nil, err | ||
} | ||
var bs []byte | ||
if bs, err = a.doAliPay(ctx, bm, "alipay.open.app.api.query"); err != nil { | ||
return nil, err | ||
} | ||
aliRsp = new(OpenAppApiQueryResponse) | ||
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil { | ||
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs)) | ||
} | ||
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil { | ||
return aliRsp, err | ||
} | ||
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn) | ||
aliRsp.SignData = signData | ||
return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr) | ||
} |
Oops, something went wrong.