Jerry 6 лет назад
Родитель
Сommit
f593d05c50
7 измененных файлов с 20 добавлено и 34 удалено
  1. 2 1
      README.md
  2. 1 1
      alipay_client_test.go
  3. 2 2
      alipay_params.go
  4. 7 17
      alipay_service_api.go
  5. 1 1
      constant.go
  6. 7 0
      release_note.txt
  7. 0 12
      wechat_client_test.go

+ 2 - 1
README.md

@@ -85,7 +85,8 @@
 
 ### 支付宝公共API
 
-* gopay.GetCertSN() => 获取证书SN号(app_cert_sn、alipay_cert_sn、alipay_root_cert_sn<支付宝root根证书的sn获取通过 gopay.GetRootCertSN() 获取>)
+* gopay.GetCertSN() => 获取应用公钥证书SN(app_cert_sn、alipay_cert_sn)
+* gopay.GetRootCertSN() => 获取支付宝根证书SN(alipay_root_cert_sn)
 * gopay.AliPaySystemOauthToken() => 换取授权访问令牌(得到access_token,user_id等信息)
 * gopay.FormatPrivateKey() => 格式化应用私钥
 * gopay.FormatAliPayPublicKey() => 格式化支付宝公钥

+ 1 - 1
alipay_client_test.go

@@ -71,7 +71,7 @@ func TestSubString(t *testing.T) {
 }
 
 func TestGetCertSN(t *testing.T) {
-	sn, err := GetCertSN("alipay_cert/alipayRootCert.crt")
+	sn, err := GetCertSN("alipay_cert/appCertPublicKey.crt")
 	if err != nil {
 		fmt.Println("err:", err)
 		return

+ 2 - 2
alipay_params.go

@@ -36,14 +36,14 @@ type OpenApiRoyaltyDetailInfoPojo struct {
 	Desc         string `json:"desc,omitempty"`
 }
 
-//设置 应用公钥证书SN
+// 设置 应用公钥证书SN
 //    appCertSN:应用公钥证书SN,通过 gopay.GetCertSN() 获取
 func (a *AliPayClient) SetAppCertSN(appCertSN string) (client *AliPayClient) {
 	a.AppCertSN = appCertSN
 	return a
 }
 
-//设置 支付宝根证书SN
+// 设置 支付宝根证书SN
 //    alipayRootCertSN:支付宝根证书SN,通过 gopay.GetRootCertSN() 获取
 func (a *AliPayClient) SetAliPayRootCertSN(alipayRootCertSN string) (client *AliPayClient) {
 	a.AlipayRootCertSN = alipayRootCertSN

+ 7 - 17
alipay_service_api.go

@@ -243,16 +243,15 @@ func FormatAliPayPublicKey(publicKey string) (pKey string) {
 	return
 }
 
-//获取证书序列号SN
-//    certPath:X.509证书文件路径(appCertPublicKey.crt、alipayRootCert.crt、alipayCertPublicKey_RSA2)
-//    返回 sn:证书序列号(app_cert_sn、alipay_root_cert_sn、alipay_cert_sn)
+// 获取Public证书序列号SN
+//    certPath:X.509证书文件路径(appCertPublicKey.crt、alipayCertPublicKey_RSA2)
+//    返回 sn:证书序列号(app_cert_sn、alipay_cert_sn)
 //    返回 err:error 信息
 func GetCertSN(certPath string) (sn string, err error) {
 	var (
 		certData           []byte
 		block              *pem.Block
 		certs              []*x509.Certificate
-		sm2Certs           []*sm2.Certificate
 		name, serialNumber string
 		h                  hash.Hash
 	)
@@ -263,19 +262,10 @@ func GetCertSN(certPath string) (sn string, err error) {
 		return null, errors.New("pem.Decode:pem Decode error,block is null")
 	}
 	if certs, err = x509.ParseCertificates(block.Bytes); err != nil {
-		if sm2Certs, err = sm2.ParseCertificates(block.Bytes); err != nil {
-			return null, fmt.Errorf("sm2.ParseCertificates:%v", err.Error())
-		}
-		name = sm2Certs[0].Issuer.String()
-		serialNumber = sm2Certs[0].SerialNumber.String()
-		goto Sign
-	}
-	if certs == nil {
-		return null, fmt.Errorf("x509.ParseCertificates:certs is null")
+		return null, fmt.Errorf("x509.ParseCertificates:error is %v", err.Error())
 	}
 	name = certs[0].Issuer.String()
 	serialNumber = certs[0].SerialNumber.String()
-Sign:
 	h = md5.New()
 	h.Write([]byte(name))
 	h.Write([]byte(serialNumber))
@@ -284,8 +274,8 @@ Sign:
 }
 
 // GetRootCertSN 阿里根证书 sn 提取
-//    certPath:X.509证书文件路径(appCertPublicKey.crt、alipayRootCert.crt、alipayCertPublicKey_RSA2)
-//    返回 sn:证书序列号(app_cert_sn、alipay_root_cert_sn、alipay_cert_sn)
+//    certPath:X.509证书文件路径(alipayRootCert.crt)
+//    返回 sn:证书序列号(alipay_root_cert_sn)
 //    返回 err:error 信息
 func GetRootCertSN(certPath string) (sn string, err error) {
 	certData, err := ioutil.ReadFile(certPath)
@@ -318,7 +308,7 @@ func GetRootCertSN(certPath string) (sn string, err error) {
 	return cert.String(), nil
 }
 
-//解密支付宝开放数据到 结构体
+// 解密支付宝开放数据到 结构体
 //    encryptedData:包括敏感数据在内的完整用户信息的加密数据
 //    secretKey:AES密钥,支付宝管理平台配置
 //    beanPtr:需要解析到的结构体指针

+ 1 - 1
constant.go

@@ -4,7 +4,7 @@ const (
 	null       string = ""
 	TimeLayout string = "2006-01-02 15:04:05"
 	DateLayout string = "2006-01-02"
-	Version    string = "1.4.0"
+	Version    string = "1.4.1"
 	//微信
 	//===========================================================================================
 

+ 7 - 0
release_note.txt

@@ -1,3 +1,10 @@
+版本号:Release 1.4.1
+发布时间:2019/11/04 14:28
+修改记录:
+   (1) 支付宝:新增公共API方法:GetRootCertSN(),修复获取支付宝根证书获取 sn 的问题(wziww)
+   (2) 支付宝:新增Client方法:client.SetAppCertSN(),可自行获取公钥 sn 并赋值
+   (2) 支付宝:新增Client方法:client.SetAliPayRootCertSN(),可自行获取根证书 sn 并赋值
+
 版本号:Release 1.4.0
 发布时间:2019/10/10 13:51
 修改记录:

+ 0 - 12
wechat_client_test.go

@@ -1,23 +1,11 @@
 package gopay
 
 import (
-	"crypto/md5"
-	"encoding/hex"
 	"encoding/json"
 	"fmt"
-	"strings"
 	"testing"
 )
 
-func TestMd5(t *testing.T) {
-	st := "appid=wxdaa2ab9ef87b5497&nonceStr=9k20rM66parD2U49&package=prepay_id=wx29164301554772fbc70d1d793335446010&signType=MD5&timeStamp=1548751382&key=GFDS8j98rewnmgl45wHTt980jg543wmg"
-	hash := md5.New()
-	hash.Write([]byte(st))
-	sum := hash.Sum(nil)
-	upper := strings.ToUpper(hex.EncodeToString(sum))
-	fmt.Println(" ssad  ", upper)
-}
-
 type Student struct {
 	Name  string `json:"name,omitempty"`
 	Age   int    `json:"age,omitempty"`