@@ -115,9 +115,14 @@ func DecryptOpenDataToBodyMap(encryptedData, secretKey string) (bm gopay.BodyMap
115
115
// grantType:值为 authorization_code 时,代表用code换取;值为 refresh_token 时,代表用refresh_token换取,传空默认code换取
116
116
// codeOrToken:支付宝授权码或refresh_token
117
117
// signType:签名方式 RSA 或 RSA2,默认 RSA2
118
+ // appAuthToken:可选参数,三方授权令牌
118
119
// 文档: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 ) {
120
121
key := xrsa .FormatAlipayPrivateKey (privateKey )
122
+ aat := ""
123
+ if len (appAuthToken ) > 0 {
124
+ aat = appAuthToken [0 ]
125
+ }
121
126
priKey , err := xpem .DecodePrivateKey ([]byte (key ))
122
127
if err != nil {
123
128
return nil , err
@@ -135,7 +140,7 @@ func SystemOauthToken(ctx context.Context, appId string, privateKey, grantType,
135
140
bm .Set ("grant_type" , "authorization_code" )
136
141
bm .Set ("code" , codeOrToken )
137
142
}
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 {
139
144
return
140
145
}
141
146
rsp = new (SystemOauthTokenResponse )
@@ -149,7 +154,7 @@ func SystemOauthToken(ctx context.Context, appId string, privateKey, grantType,
149
154
}
150
155
151
156
// 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 ) {
153
158
bm .Set ("app_id" , appId )
154
159
bm .Set ("method" , method )
155
160
bm .Set ("format" , "JSON" )
@@ -161,6 +166,9 @@ func systemOauthToken(ctx context.Context, appId string, privateKey *rsa.Private
161
166
}
162
167
bm .Set ("timestamp" , time .Now ().Format (util .TimeLayout ))
163
168
bm .Set ("version" , "1.0" )
169
+ if appAuthToken != util .NULL {
170
+ bm .Set ("app_auth_token" , appAuthToken )
171
+ }
164
172
var (
165
173
sign string
166
174
baseUrl = baseUrlUtf8
0 commit comments