修改支付宝小程序授权

This commit is contained in:
邹宗楠
2023-03-31 09:33:11 +08:00
parent 980fb17b1d
commit 352bb15636
3 changed files with 15 additions and 23 deletions

View File

@@ -1,16 +1,10 @@
package alipayapi
import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals"
)
import "git.rosy.net.cn/baseapi/utils"
const (
GrantTypeCode = "authorization_code"
AliPayPublicCertPath2 = "./conf/alipayCertPublicKey_RSA2.crt" // 支付宝公钥证书文件路径
AliPayRootCertPath2 = "./conf/alipayRootCert.crt" // 支付宝根证书文件路径
AppCertPath2 = "./conf/appCertPublicKey_2019110769024042.crt" // 应用公钥证书路径
GrantTypeRefresh = "refresh_token"
GrantTypeCode = "authorization_code"
GrantTypeRefresh = "refresh_token"
)
type TokenInfo struct {
@@ -48,18 +42,16 @@ func (a *API) SystemAuthToken(grantType, code, refreshToken string) (tokenInfo *
params["refresh_token"] = refreshToken
}
// 获取证书
//appCertSN, aliPayRootCertSN, aliPayPublicCertSN, err := SetCertSnByPath(AppCertPath2, AliPayRootCertPath2, AliPayPublicCertPath2)
//if err != nil {
// return nil, err
//}
//
//params["app_cert_sn"] = appCertSN
//params["alipay_public_cert_sn"] = aliPayPublicCertSN
//params["alipay_root_cert_sn"] = aliPayRootCertSN
appCertSN, aliPayRootCertSN, aliPayPublicCertSN, err := SetCertSnByPath(AppCertPath, AliPayRootCertPath, AliPayPublicCertPath)
if err != nil {
return nil, err
}
retVal, err := a.AccessAPI("alipay.system.oauth.token", nil, params, false)
globals.SugarLogger.Debugf("==========aliPay := %s", utils.Format4Output(retVal, false))
globals.SugarLogger.Debugf("==========err := %s", utils.Format4Output(err, false))
params["app_cert_sn"] = appCertSN
params["alipay_public_cert_sn"] = aliPayPublicCertSN
params["alipay_root_cert_sn"] = aliPayRootCertSN
retVal, err := a.AccessAPI("alipay.system.oauth.token", params, nil, false)
if err == nil {
err = utils.Map2StructByJson(retVal, &tokenInfo, false)
}