修改支付宝小程序授权

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

@@ -9,6 +9,7 @@ import (
"encoding/base64" "encoding/base64"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"git.rosy.net.cn/baseapi/utils"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"sort" "sort"
@@ -16,7 +17,6 @@ import (
"git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/platformapi" "git.rosy.net.cn/baseapi/platformapi"
"git.rosy.net.cn/baseapi/utils"
) )
const ( const (
@@ -131,7 +131,7 @@ func (a *API) AccessAPI(method string, params, bizContent map[string]interface{}
fullURL := utils.GenerateGetURL(prodURL, "", params) fullURL := utils.GenerateGetURL(prodURL, "", params)
if isPost { 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 { } else {
request, _ = http.NewRequest(http.MethodGet, fullURL, nil) request, _ = http.NewRequest(http.MethodGet, fullURL, nil)
} }

View File

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

View File

@@ -8,7 +8,7 @@ import (
) )
func TestSystemAuthToken(t *testing.T) { func TestSystemAuthToken(t *testing.T) {
result, err := api.SystemAuthToken(GrantTypeCode, "f18d4a91c42e4803a8018db2620fUX91", "") result, err := api.SystemAuthToken(GrantTypeCode, "85636904854946afa6890299e0a1VX17", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }