修改支付宝小程序授权
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"sort"
|
||||
@@ -16,7 +17,6 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -131,7 +131,7 @@ func (a *API) AccessAPI(method string, params, bizContent map[string]interface{}
|
||||
|
||||
fullURL := utils.GenerateGetURL(prodURL, "", params)
|
||||
if isPost {
|
||||
request, _ = http.NewRequest(http.MethodPost, prodURL, strings.NewReader(utils.Map2URLValues(params).Encode()))
|
||||
request, _ = http.NewRequest(http.MethodPost, prodURL, strings.NewReader(utils.Map2URLValues(bizContent).Encode()))
|
||||
} else {
|
||||
request, _ = http.NewRequest(http.MethodGet, fullURL, nil)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestSystemAuthToken(t *testing.T) {
|
||||
result, err := api.SystemAuthToken(GrantTypeCode, "f18d4a91c42e4803a8018db2620fUX91", "")
|
||||
result, err := api.SystemAuthToken(GrantTypeCode, "85636904854946afa6890299e0a1VX17", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user