Skip to content

Commit dc2edbd

Browse files
authored
v1.5.105 (#420)
1 parent 5066128 commit dc2edbd

File tree

10 files changed

+814
-59
lines changed

10 files changed

+814
-59
lines changed

alipay/client.go

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ func (a *Client) RequestParam(bm gopay.BodyMap, method string) (string, error) {
122122
err error
123123
sign string
124124
)
125+
if bm == nil {
126+
return "", gopay.BodyMapNilErr
127+
}
125128
// check if there is biz_content
126129
bz := bm.GetInterface("biz_content")
127130
if bzBody, ok := bz.(gopay.BodyMap); ok {
@@ -161,40 +164,42 @@ func (a *Client) pubParamsHandle(bm gopay.BodyMap, method, bizContent string, au
161164
Set("version", "1.0").
162165
Set("timestamp", time.Now().Format(xtime.TimeLayout))
163166

164-
// version
165-
if version := bm.GetString("version"); version != gopay.NULL {
166-
pubBody.Set("version", version)
167-
}
168-
if a.AppCertSN != gopay.NULL {
169-
pubBody.Set("app_cert_sn", a.AppCertSN)
170-
}
171-
if a.AliPayRootCertSN != gopay.NULL {
172-
pubBody.Set("alipay_root_cert_sn", a.AliPayRootCertSN)
173-
}
174-
// return_url
175-
if a.ReturnUrl != gopay.NULL {
176-
pubBody.Set("return_url", a.ReturnUrl)
177-
}
178-
if returnUrl := bm.GetString("return_url"); returnUrl != gopay.NULL {
179-
pubBody.Set("return_url", returnUrl)
180-
}
181-
if a.location != nil {
182-
pubBody.Set("timestamp", time.Now().In(a.location).Format(xtime.TimeLayout))
183-
}
184-
// notify_url
185-
if a.NotifyUrl != gopay.NULL {
186-
pubBody.Set("notify_url", a.NotifyUrl)
187-
}
188-
if notifyUrl := bm.GetString("notify_url"); notifyUrl != gopay.NULL {
189-
pubBody.Set("notify_url", notifyUrl)
190-
}
191-
// default use app_auth_token
192-
if a.AppAuthToken != gopay.NULL {
193-
pubBody.Set("app_auth_token", a.AppAuthToken)
194-
}
195-
// if user set app_auth_token in body_map, use this
196-
if aat := bm.GetString("app_auth_token"); aat != gopay.NULL {
197-
pubBody.Set("app_auth_token", aat)
167+
if bm != nil {
168+
// version
169+
if version := bm.GetString("version"); version != gopay.NULL {
170+
pubBody.Set("version", version)
171+
}
172+
if a.AppCertSN != gopay.NULL {
173+
pubBody.Set("app_cert_sn", a.AppCertSN)
174+
}
175+
if a.AliPayRootCertSN != gopay.NULL {
176+
pubBody.Set("alipay_root_cert_sn", a.AliPayRootCertSN)
177+
}
178+
// return_url
179+
if a.ReturnUrl != gopay.NULL {
180+
pubBody.Set("return_url", a.ReturnUrl)
181+
}
182+
if returnUrl := bm.GetString("return_url"); returnUrl != gopay.NULL {
183+
pubBody.Set("return_url", returnUrl)
184+
}
185+
if a.location != nil {
186+
pubBody.Set("timestamp", time.Now().In(a.location).Format(xtime.TimeLayout))
187+
}
188+
// notify_url
189+
if a.NotifyUrl != gopay.NULL {
190+
pubBody.Set("notify_url", a.NotifyUrl)
191+
}
192+
if notifyUrl := bm.GetString("notify_url"); notifyUrl != gopay.NULL {
193+
pubBody.Set("notify_url", notifyUrl)
194+
}
195+
// default use app_auth_token
196+
if a.AppAuthToken != gopay.NULL {
197+
pubBody.Set("app_auth_token", a.AppAuthToken)
198+
}
199+
// if user set app_auth_token in body_map, use this
200+
if aat := bm.GetString("app_auth_token"); aat != gopay.NULL {
201+
pubBody.Set("app_auth_token", aat)
202+
}
198203
}
199204
if len(authToken) > 0 {
200205
pubBody.Set("auth_token", authToken[0])

alipay/client_request.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func (a *Client) PostAliPayAPISelfV2(ctx context.Context, bodyMap gopay.BodyMap,
2626
}
2727
bodyMap.Set("biz_content", string(bodyBs))
2828
}
29-
3029
if bs, err = a.doAliPaySelf(ctx, bodyMap, method); err != nil {
3130
return err
3231
}
@@ -146,7 +145,9 @@ func (a *Client) doAliPay(ctx context.Context, bm gopay.BodyMap, method string,
146145
return nil, fmt.Errorf("json.Marshal:%w", err)
147146
}
148147
bizContent = string(bodyBs)
149-
bm.Set("app_auth_token", aat)
148+
if aat != "" {
149+
bm.Set("app_auth_token", aat)
150+
}
150151
} else {
151152
if bodyBs, err = json.Marshal(bm); err != nil {
152153
return nil, fmt.Errorf("json.Marshal:%w", err)

0 commit comments

Comments
 (0)