Skip to content

Commit

Permalink
v1.5.105
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoogle-ink committed Sep 7, 2024
1 parent 5066128 commit 23e2338
Show file tree
Hide file tree
Showing 10 changed files with 814 additions and 59 deletions.
73 changes: 39 additions & 34 deletions alipay/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ func (a *Client) RequestParam(bm gopay.BodyMap, method string) (string, error) {
err error
sign string
)
if bm == nil {
return "", gopay.BodyMapNilErr
}
// check if there is biz_content
bz := bm.GetInterface("biz_content")
if bzBody, ok := bz.(gopay.BodyMap); ok {
Expand Down Expand Up @@ -161,40 +164,42 @@ func (a *Client) pubParamsHandle(bm gopay.BodyMap, method, bizContent string, au
Set("version", "1.0").
Set("timestamp", time.Now().Format(xtime.TimeLayout))

// version
if version := bm.GetString("version"); version != gopay.NULL {
pubBody.Set("version", version)
}
if a.AppCertSN != gopay.NULL {
pubBody.Set("app_cert_sn", a.AppCertSN)
}
if a.AliPayRootCertSN != gopay.NULL {
pubBody.Set("alipay_root_cert_sn", a.AliPayRootCertSN)
}
// return_url
if a.ReturnUrl != gopay.NULL {
pubBody.Set("return_url", a.ReturnUrl)
}
if returnUrl := bm.GetString("return_url"); returnUrl != gopay.NULL {
pubBody.Set("return_url", returnUrl)
}
if a.location != nil {
pubBody.Set("timestamp", time.Now().In(a.location).Format(xtime.TimeLayout))
}
// notify_url
if a.NotifyUrl != gopay.NULL {
pubBody.Set("notify_url", a.NotifyUrl)
}
if notifyUrl := bm.GetString("notify_url"); notifyUrl != gopay.NULL {
pubBody.Set("notify_url", notifyUrl)
}
// default use app_auth_token
if a.AppAuthToken != gopay.NULL {
pubBody.Set("app_auth_token", a.AppAuthToken)
}
// if user set app_auth_token in body_map, use this
if aat := bm.GetString("app_auth_token"); aat != gopay.NULL {
pubBody.Set("app_auth_token", aat)
if bm != nil {
// version
if version := bm.GetString("version"); version != gopay.NULL {
pubBody.Set("version", version)
}
if a.AppCertSN != gopay.NULL {
pubBody.Set("app_cert_sn", a.AppCertSN)
}
if a.AliPayRootCertSN != gopay.NULL {
pubBody.Set("alipay_root_cert_sn", a.AliPayRootCertSN)
}
// return_url
if a.ReturnUrl != gopay.NULL {
pubBody.Set("return_url", a.ReturnUrl)
}
if returnUrl := bm.GetString("return_url"); returnUrl != gopay.NULL {
pubBody.Set("return_url", returnUrl)
}
if a.location != nil {
pubBody.Set("timestamp", time.Now().In(a.location).Format(xtime.TimeLayout))
}
// notify_url
if a.NotifyUrl != gopay.NULL {
pubBody.Set("notify_url", a.NotifyUrl)
}
if notifyUrl := bm.GetString("notify_url"); notifyUrl != gopay.NULL {
pubBody.Set("notify_url", notifyUrl)
}
// default use app_auth_token
if a.AppAuthToken != gopay.NULL {
pubBody.Set("app_auth_token", a.AppAuthToken)
}
// if user set app_auth_token in body_map, use this
if aat := bm.GetString("app_auth_token"); aat != gopay.NULL {
pubBody.Set("app_auth_token", aat)
}
}
if len(authToken) > 0 {
pubBody.Set("auth_token", authToken[0])
Expand Down
5 changes: 3 additions & 2 deletions alipay/client_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func (a *Client) PostAliPayAPISelfV2(ctx context.Context, bodyMap gopay.BodyMap,
}
bodyMap.Set("biz_content", string(bodyBs))
}

if bs, err = a.doAliPaySelf(ctx, bodyMap, method); err != nil {
return err
}
Expand Down Expand Up @@ -146,7 +145,9 @@ func (a *Client) doAliPay(ctx context.Context, bm gopay.BodyMap, method string,
return nil, fmt.Errorf("json.Marshal:%w", err)
}
bizContent = string(bodyBs)
bm.Set("app_auth_token", aat)
if aat != "" {
bm.Set("app_auth_token", aat)
}
} else {
if bodyBs, err = json.Marshal(bm); err != nil {
return nil, fmt.Errorf("json.Marshal:%w", err)
Expand Down
Loading

0 comments on commit 23e2338

Please sign in to comment.