diff --git a/alipay/service_api.go b/alipay/service_api.go index 2d596c0f..2dc63ff4 100644 --- a/alipay/service_api.go +++ b/alipay/service_api.go @@ -526,8 +526,9 @@ func DecryptOpenDataToBodyMap(encryptedData, secretKey string) (bm gopay.BodyMap // PrivateKey:应用私钥 // grantType:值为 authorization_code 时,代表用code换取;值为 refresh_token 时,代表用refresh_token换取,传空默认code换取 // codeOrToken:支付宝授权码或refresh_token +// signType:签名方式 RSA 或 RSA2,默认 RSA2 // 文档:https://docs.open.alipay.com/api_9/alipay.system.oauth.token -func SystemOauthToken(appId, privateKey, grantType, codeOrToken string) (rsp *SystemOauthTokenResponse, err error) { +func SystemOauthToken(appId, privateKey, grantType, codeOrToken, signType string) (rsp *SystemOauthTokenResponse, err error) { var bs []byte bm := make(gopay.BodyMap) if "authorization_code" == grantType { @@ -540,7 +541,7 @@ func SystemOauthToken(appId, privateKey, grantType, codeOrToken string) (rsp *Sy bm.Set("grant_type", "authorization_code") bm.Set("code", codeOrToken) } - if bs, err = systemOauthToken(appId, privateKey, bm, "alipay.system.oauth.token", true, "RSA2"); err != nil { + if bs, err = systemOauthToken(appId, privateKey, bm, "alipay.system.oauth.token", true, signType); err != nil { return } rsp = new(SystemOauthTokenResponse) @@ -559,6 +560,11 @@ func systemOauthToken(appId, privateKey string, body gopay.BodyMap, method strin body.Set("method", method) body.Set("format", "JSON") body.Set("charset", "utf-8") + if signType == gopay.NULL { + body.Set("sign_type", "RSA2") + } else { + body.Set("sign_type", signType) + } body.Set("sign_type", signType) body.Set("timestamp", time.Now().Format(gopay.TimeLayout)) body.Set("version", "1.0") diff --git a/examples/alipay/alipay_ServiceApi.go b/examples/alipay/alipay_ServiceApi.go index e0e090c4..9949ad9b 100644 --- a/examples/alipay/alipay_ServiceApi.go +++ b/examples/alipay/alipay_ServiceApi.go @@ -24,7 +24,7 @@ func FormatPublicKey() { func SystemOauthToken2() { privateKey := "MIIEogIBAAKCAQEAy+CRzKw4krA2RzCDTqg5KJg92XkOY0RN3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yhmLxM4aZxNA9I+boVrlFWDAchzg+8VuunBwIslgLHx0/4EoUWLzd1/OGtco6oU1HXhI9J9pRGjqfO1iiIifN/ujwqx7AFNknayG/YkQKBgD6yNgA/ak12rovYzXKdp14Axn+39k2dPp6J6R8MnyLlB3yruwW6NSbNhtzTD1GZ+wCQepQvYvlPPc8zm+t3tl1r+Rtx3ORf5XBZc3iPkGdPOLubTssrrAnA+U9vph61W+OjqwLJ9sHUNK9pSHhHSIS4k6ycM2YAHyIC9NGTgB0PAoGAJjwd1DgMaQldtWnuXjvohPOo8cQudxXYcs6zVRbx6vtjKe2v7e+eK1SSVrR5qFV9AqxDfGwq8THenRa0LC3vNNplqostuehLhkWCKE7Y75vXMR7N6KU1kdoVWgN4BhXSwuRxmHMQfSY7q3HG3rDGz7mzXo1FVMr/uE4iDGm0IXY=" - rsp, err := alipay.SystemOauthToken("2016091200494382", privateKey, "", "06e8961891d647c0ac99bb1cebe7SE69") + rsp, err := alipay.SystemOauthToken("2016091200494382", privateKey, "", "06e8961891d647c0ac99bb1cebe7SE69", "RSA2") if err != nil { fmt.Println("SystemOauthToken:", err) return diff --git a/release_note.txt b/release_note.txt index 5e5be664..12aa1964 100644 --- a/release_note.txt +++ b/release_note.txt @@ -1,3 +1,8 @@ +版本号:Release 1.5.3 +发布时间:2020/02/19 11:32 +修改记录: + (1) 支付宝:修改公共方法:SystemOauthToken(),添加参数 signType + 版本号:Release 1.5.2 发布时间:2020/02/14 13:32 修改记录: