Skip to content

Commit 5b615d8

Browse files
committed
v1.5.87
1 parent d4f4f63 commit 5b615d8

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

alipay/common_api.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,14 @@ func DecryptOpenDataToBodyMap(encryptedData, secretKey string) (bm gopay.BodyMap
115115
// grantType:值为 authorization_code 时,代表用code换取;值为 refresh_token 时,代表用refresh_token换取,传空默认code换取
116116
// codeOrToken:支付宝授权码或refresh_token
117117
// signType:签名方式 RSA 或 RSA2,默认 RSA2
118+
// appAuthToken:可选参数,三方授权令牌
118119
// 文档:https://opendocs.alipay.com/apis/api_9/alipay.system.oauth.token
119-
func SystemOauthToken(ctx context.Context, appId string, privateKey, grantType, codeOrToken, signType string) (rsp *SystemOauthTokenResponse, err error) {
120+
func SystemOauthToken(ctx context.Context, appId string, privateKey, grantType, codeOrToken, signType string, appAuthToken ...string) (rsp *SystemOauthTokenResponse, err error) {
120121
key := xrsa.FormatAlipayPrivateKey(privateKey)
122+
aat := ""
123+
if len(appAuthToken) > 0 {
124+
aat = appAuthToken[0]
125+
}
121126
priKey, err := xpem.DecodePrivateKey([]byte(key))
122127
if err != nil {
123128
return nil, err
@@ -135,7 +140,7 @@ func SystemOauthToken(ctx context.Context, appId string, privateKey, grantType,
135140
bm.Set("grant_type", "authorization_code")
136141
bm.Set("code", codeOrToken)
137142
}
138-
if bs, err = systemOauthToken(ctx, appId, priKey, bm, "alipay.system.oauth.token", true, signType); err != nil {
143+
if bs, err = systemOauthToken(ctx, appId, priKey, bm, "alipay.system.oauth.token", true, signType, aat); err != nil {
139144
return
140145
}
141146
rsp = new(SystemOauthTokenResponse)
@@ -149,7 +154,7 @@ func SystemOauthToken(ctx context.Context, appId string, privateKey, grantType,
149154
}
150155

151156
// systemOauthToken 向支付宝发送请求
152-
func systemOauthToken(ctx context.Context, appId string, privateKey *rsa.PrivateKey, bm gopay.BodyMap, method string, isProd bool, signType string) (bs []byte, err error) {
157+
func systemOauthToken(ctx context.Context, appId string, privateKey *rsa.PrivateKey, bm gopay.BodyMap, method string, isProd bool, signType, appAuthToken string) (bs []byte, err error) {
153158
bm.Set("app_id", appId)
154159
bm.Set("method", method)
155160
bm.Set("format", "JSON")
@@ -161,6 +166,9 @@ func systemOauthToken(ctx context.Context, appId string, privateKey *rsa.Private
161166
}
162167
bm.Set("timestamp", time.Now().Format(util.TimeLayout))
163168
bm.Set("version", "1.0")
169+
if appAuthToken != util.NULL {
170+
bm.Set("app_auth_token", appAuthToken)
171+
}
164172
var (
165173
sign string
166174
baseUrl = baseUrlUtf8

alipay/util_api.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,28 @@ func (a *Client) SystemOauthToken(ctx context.Context, bm gopay.BodyMap) (aliRsp
4444
if bm.GetString("code") == util.NULL && bm.GetString("refresh_token") == util.NULL {
4545
return nil, errors.New("code and refresh_token are not allowed to be null at the same time")
4646
}
47-
err = bm.CheckEmptyError("grant_type")
48-
if err != nil {
47+
if err = bm.CheckEmptyError("grant_type"); err != nil {
4948
return nil, err
5049
}
51-
50+
var (
51+
bs []byte
52+
aat string
53+
)
5254
if a.AppCertSN != util.NULL {
5355
bm.Set("app_cert_sn", a.AppCertSN)
5456
}
5557
if a.AliPayRootCertSN != util.NULL {
5658
bm.Set("alipay_root_cert_sn", a.AliPayRootCertSN)
5759
}
58-
59-
var bs []byte
60-
if bs, err = systemOauthToken(ctx, a.AppId, a.privateKey, bm, "alipay.system.oauth.token", a.IsProd, a.SignType); err != nil {
60+
// default use app_auth_token
61+
if a.AppAuthToken != util.NULL {
62+
aat = a.AppAuthToken
63+
}
64+
// if user set app_auth_token in body_map, use this
65+
if bmAt := bm.GetString("app_auth_token"); bmAt != util.NULL {
66+
aat = bmAt
67+
}
68+
if bs, err = systemOauthToken(ctx, a.AppId, a.privateKey, bm, "alipay.system.oauth.token", a.IsProd, a.SignType, aat); err != nil {
6169
return nil, err
6270
}
6371
aliRsp = new(SystemOauthTokenResponse)

release_note.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(1) 微信V3:新增小程序调起支付分所需要的支付参数方法:client.PaySignOfAppletScore()。
44
(2) 微信V3:异步通知解析方法接收BodySize大小调至5MB。
55
(3) 支付宝:统一收单交易退款接口,response补充接收字段。
6+
(4) 支付宝:alipay.SystemOauthToken() 接口增加可变参数 AppAuthToken 字段,如需要时可传。
67

78
版本号:Release 1.5.86
89
修改记录:

0 commit comments

Comments
 (0)