@@ -140,20 +140,20 @@ func (a *Client) doAliPay(ctx context.Context, bm gopay.BodyMap, method string,
140
140
)
141
141
if bm != nil {
142
142
_ , has := appAuthTokenInBizContent [method ]
143
- if has {
143
+ if ! has {
144
+ aat := bm .GetString ("app_auth_token" )
145
+ bm .Remove ("app_auth_token" )
144
146
if bodyBs , err = json .Marshal (bm ); err != nil {
145
147
return nil , fmt .Errorf ("json.Marshal:%w" , err )
146
148
}
147
149
bizContent = string (bodyBs )
148
- bm .Remove ("app_auth_token" )
150
+ bm .Set ("app_auth_token" , aat )
149
151
} else {
150
- aat := bm .GetString ("app_auth_token" )
151
- bm .Remove ("app_auth_token" )
152
152
if bodyBs , err = json .Marshal (bm ); err != nil {
153
153
return nil , fmt .Errorf ("json.Marshal:%w" , err )
154
154
}
155
155
bizContent = string (bodyBs )
156
- bm .Set ("app_auth_token" , aat )
156
+ bm .Remove ("app_auth_token" )
157
157
}
158
158
}
159
159
// 处理公共参数
@@ -196,20 +196,20 @@ func (a *Client) DoAliPay(ctx context.Context, bm gopay.BodyMap, method string,
196
196
)
197
197
if bm != nil {
198
198
_ , has := appAuthTokenInBizContent [method ]
199
- if has {
199
+ if ! has {
200
+ aat := bm .GetString ("app_auth_token" )
201
+ bm .Remove ("app_auth_token" )
200
202
if bodyBs , err = json .Marshal (bm ); err != nil {
201
203
return nil , fmt .Errorf ("json.Marshal:%w" , err )
202
204
}
203
205
bizContent = string (bodyBs )
204
- bm .Remove ("app_auth_token" )
206
+ bm .Set ("app_auth_token" , aat )
205
207
} else {
206
- aat := bm .GetString ("app_auth_token" )
207
- bm .Remove ("app_auth_token" )
208
208
if bodyBs , err = json .Marshal (bm ); err != nil {
209
209
return nil , fmt .Errorf ("json.Marshal:%w" , err )
210
210
}
211
211
bizContent = string (bodyBs )
212
- bm .Set ("app_auth_token" , aat )
212
+ bm .Remove ("app_auth_token" )
213
213
}
214
214
}
215
215
// 处理公共参数
@@ -252,20 +252,20 @@ func (a *Client) PageExecute(ctx context.Context, bm gopay.BodyMap, method strin
252
252
)
253
253
if bm != nil {
254
254
_ , has := appAuthTokenInBizContent [method ]
255
- if has {
255
+ if ! has {
256
+ aat := bm .GetString ("app_auth_token" )
257
+ bm .Remove ("app_auth_token" )
256
258
if bodyBs , err = json .Marshal (bm ); err != nil {
257
259
return "" , fmt .Errorf ("json.Marshal:%w" , err )
258
260
}
259
261
bizContent = string (bodyBs )
260
- bm .Remove ("app_auth_token" )
262
+ bm .Set ("app_auth_token" , aat )
261
263
} else {
262
- aat := bm .GetString ("app_auth_token" )
263
- bm .Remove ("app_auth_token" )
264
264
if bodyBs , err = json .Marshal (bm ); err != nil {
265
265
return "" , fmt .Errorf ("json.Marshal:%w" , err )
266
266
}
267
267
bizContent = string (bodyBs )
268
- bm .Set ("app_auth_token" , aat )
268
+ bm .Remove ("app_auth_token" )
269
269
}
270
270
}
271
271
// 处理公共参数
@@ -281,19 +281,13 @@ func (a *Client) PageExecute(ctx context.Context, bm gopay.BodyMap, method strin
281
281
}
282
282
283
283
// 文件上传
284
- func (a * Client ) FileRequest (ctx context.Context , bm gopay.BodyMap , file * gopay.File , method string ) (bs []byte , err error ) {
284
+ func (a * Client ) FileUploadRequest (ctx context.Context , bm gopay.BodyMap , file * gopay.File , method string ) (bs []byte , err error ) {
285
285
var (
286
- bodyStr string
287
- bodyBs []byte
288
- aat string
286
+ aat string
289
287
)
290
288
if bm != nil {
291
289
aat = bm .GetString ("app_auth_token" )
292
290
bm .Remove ("app_auth_token" )
293
- if bodyBs , err = json .Marshal (bm ); err != nil {
294
- return nil , fmt .Errorf ("json.Marshal:%w" , err )
295
- }
296
- bodyStr = string (bodyBs )
297
291
}
298
292
pubBody := make (gopay.BodyMap )
299
293
pubBody .Set ("app_id" , a .AppId ).
@@ -302,7 +296,6 @@ func (a *Client) FileRequest(ctx context.Context, bm gopay.BodyMap, file *gopay.
302
296
Set ("charset" , a .Charset ).
303
297
Set ("sign_type" , a .SignType ).
304
298
Set ("version" , "1.0" ).
305
- Set ("scene" , "SYNC_ORDER" ).
306
299
Set ("timestamp" , time .Now ().Format (xtime .TimeLayout ))
307
300
308
301
if a .AppCertSN != gopay .NULL {
@@ -320,15 +313,15 @@ func (a *Client) FileRequest(ctx context.Context, bm gopay.BodyMap, file *gopay.
320
313
if a .NotifyUrl != gopay .NULL {
321
314
pubBody .Set ("notify_url" , a .NotifyUrl )
322
315
}
316
+ // default use app_auth_token
323
317
if a .AppAuthToken != gopay .NULL {
324
318
pubBody .Set ("app_auth_token" , a .AppAuthToken )
325
319
}
320
+ // if user set app_auth_token in body_map, use this
326
321
if aat != gopay .NULL {
327
322
pubBody .Set ("app_auth_token" , aat )
328
323
}
329
- if bodyStr != gopay .NULL {
330
- pubBody .Set ("biz_content" , bodyStr )
331
- }
324
+ // sign
332
325
sign , err := a .getRsaSign (pubBody , pubBody .GetString ("sign_type" ))
333
326
if err != nil {
334
327
return nil , fmt .Errorf ("GetRsaSign Error: %w" , err )
@@ -340,8 +333,7 @@ func (a *Client) FileRequest(ctx context.Context, bm gopay.BodyMap, file *gopay.
340
333
}
341
334
param := pubBody .EncodeURLParams ()
342
335
url := baseUrlUtf8 + "&" + param
343
- bm .Reset ()
344
- bm .SetFormFile ("file_content" , file )
336
+
345
337
res , bs , err := a .hc .Req (xhttp .TypeMultipartFormData ).Post (url ).
346
338
SendMultipartBodyMap (bm ).EndBytes (ctx )
347
339
if err != nil {
0 commit comments