From 352bb1563617b0d49b1e2d90f3bc218d12563a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 31 Mar 2023 09:33:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=94=AF=E4=BB=98=E5=AE=9D?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=8E=88=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/alipayapi/alipayapi.go | 4 ++-- platformapi/alipayapi/utils.go | 32 +++++++++++------------------ platformapi/alipayapi/utils_test.go | 2 +- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/platformapi/alipayapi/alipayapi.go b/platformapi/alipayapi/alipayapi.go index a4af3231..883d3f4f 100644 --- a/platformapi/alipayapi/alipayapi.go +++ b/platformapi/alipayapi/alipayapi.go @@ -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) } diff --git a/platformapi/alipayapi/utils.go b/platformapi/alipayapi/utils.go index 2cf0a34b..634186bf 100644 --- a/platformapi/alipayapi/utils.go +++ b/platformapi/alipayapi/utils.go @@ -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) } diff --git a/platformapi/alipayapi/utils_test.go b/platformapi/alipayapi/utils_test.go index b3878143..2d7222e7 100644 --- a/platformapi/alipayapi/utils_test.go +++ b/platformapi/alipayapi/utils_test.go @@ -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) }