Przeglądaj źródła

Merge pull request #20 from iGoogle-ink/gopay/fix

Gopay/fix
Jerry 6 lat temu
rodzic
commit
cde434ae07
8 zmienionych plików z 32 dodań i 12 usunięć
  1. 0 1
      README.md
  2. 12 1
      alipay/service_api.go
  3. 1 6
      constant.go
  4. 0 2
      go.mod
  5. 0 2
      go.sum
  6. 3 0
      qq/service_api.go
  7. 7 0
      release_note.txt
  8. 9 0
      wechat/service_api.go

+ 0 - 1
README.md

@@ -19,7 +19,6 @@ $ go get github.com/iGoogle-ink/gopay/v2
 
 * #### 查看 GoPay 版本
     * [版本更新记录](https://github.com/iGoogle-ink/gopay/blob/master/release_note.txt)
-    * 2.+ 版本未经严格测试,如若有问题,请使用 1.+ 版本,兼容老版本
 ```go
 import (
     "fmt"

+ 12 - 1
alipay/service_api.go

@@ -145,7 +145,6 @@ A:开发者上传自己的应用公钥证书后,开放平台会为开发者
 //    返回参数err:错误信息
 //    验签文档:https://docs.open.alipay.com/200/106120
 func VerifySyncSign(aliPayPublicKey, signData, sign string) (ok bool, err error) {
-
 	// 支付宝公钥验签
 	pKey := FormatPublicKey(aliPayPublicKey)
 	if err = verifySign(signData, sign, "RSA2", pKey); err != nil {
@@ -162,6 +161,9 @@ func VerifySyncSign(aliPayPublicKey, signData, sign string) (ok bool, err error)
 //    返回参数err:错误信息
 //    验签文档:https://docs.open.alipay.com/200/106120
 func VerifySign(aliPayPublicKey string, bean interface{}) (ok bool, err error) {
+	if aliPayPublicKey == gopay.NULL {
+		return false, errors.New("aliPayPublicKey is null")
+	}
 	if bean == nil {
 		return false, errors.New("bean is nil")
 	}
@@ -240,6 +242,9 @@ func verifySign(signData, sign, signType, aliPayPublicKey string) (err error) {
 //    返回参数err:错误信息
 //    验签文档:https://docs.open.alipay.com/200/106120
 func VerifySignWithCert(aliPayPublicKeyPath string, bean interface{}) (ok bool, err error) {
+	if aliPayPublicKeyPath == gopay.NULL {
+		return false, errors.New("aliPayPublicKeyPath is null")
+	}
 	if bean == nil {
 		return false, errors.New("bean is nil")
 	}
@@ -444,6 +449,9 @@ func GetRootCertSN(rootCertPath string) (sn string, err error) {
 //    文档:https://docs.alipay.com/mini/introduce/aes
 //    文档:https://docs.open.alipay.com/common/104567
 func DecryptOpenDataToStruct(encryptedData, secretKey string, beanPtr interface{}) (err error) {
+	if encryptedData == gopay.NULL || secretKey == gopay.NULL {
+		return errors.New("encryptedData or secretKey is null")
+	}
 	beanValue := reflect.ValueOf(beanPtr)
 	if beanValue.Kind() != reflect.Ptr {
 		return errors.New("传入参数类型必须是以指针形式")
@@ -483,6 +491,9 @@ func DecryptOpenDataToStruct(encryptedData, secretKey string, beanPtr interface{
 //    文档:https://docs.alipay.com/mini/introduce/aes
 //    文档:https://docs.open.alipay.com/common/104567
 func DecryptOpenDataToBodyMap(encryptedData, secretKey string) (bm gopay.BodyMap, err error) {
+	if encryptedData == gopay.NULL || secretKey == gopay.NULL {
+		return nil, errors.New("encryptedData or secretKey is null")
+	}
 	var (
 		aesKey, originData []byte
 		ivKey              = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

+ 1 - 6
model.go → constant.go

@@ -7,10 +7,5 @@ const (
 	SUCCESS    = "SUCCESS"
 	FAIL       = "FAIL"
 	OK         = "OK"
-	Version    = "2.0.4"
+	Version    = "2.0.5"
 )
-
-type ReturnMessage struct {
-	ReturnCode string `json:"return_code"`
-	ReturnMsg  string `json:"return_msg"`
-}

+ 0 - 2
go.mod

@@ -1,5 +1,3 @@
 module github.com/iGoogle-ink/gopay/v2
 
 go 1.13
-
-require github.com/iGoogle-ink/gopay v1.4.8 // indirect

+ 0 - 2
go.sum

@@ -1,2 +0,0 @@
-github.com/iGoogle-ink/gopay v1.4.8 h1:c98uztaUODTJuV8vsJQUswN6G+TxVqn6cl/DYv5kHxg=
-github.com/iGoogle-ink/gopay v1.4.8/go.mod h1:/A7M5Ts6OUEaQD+88stwhPtFV1AxOCL+CAtjreZlGGQ=

+ 3 - 0
qq/service_api.go

@@ -49,6 +49,9 @@ func ParseNotifyResult(req *http.Request) (notifyReq *NotifyRequest, err error)
 //    返回参数ok:是否验签通过
 //    返回参数err:错误信息
 func VerifySign(apiKey, signType string, bean interface{}) (ok bool, err error) {
+	if apiKey == gopay.NULL || signType == gopay.NULL {
+		return false, errors.New("apiKey or signType can not null")
+	}
 	if bean == nil {
 		return false, errors.New("bean is nil")
 	}

+ 7 - 0
release_note.txt

@@ -1,3 +1,10 @@
+版本号:Release 2.0.5
+发布时间:2020/01/01 22:55
+修改记录:
+   (1) 添加一些函数参数判空操作,避免Panic
+   (2) 去掉不用的结构体 ReturnMessage
+   (3) 去掉 go mod v1.4.8版本的依赖
+
 版本号:Release 2.0.4
 发布时间:2019/12/24 14:29
 修改记录:

+ 9 - 0
wechat/service_api.go

@@ -120,6 +120,9 @@ func ParseRefundNotifyResult(req *http.Request) (notifyReq *RefundNotifyRequest,
 //    返回参数err:错误信息
 //    文档:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_16&index=10
 func DecryptRefundNotifyReqInfo(reqInfo, apiKey string) (refundNotify *RefundNotify, err error) {
+	if reqInfo == gopay.NULL || apiKey == gopay.NULL {
+		return nil, errors.New("reqInfo or apiKey is null")
+	}
 	var (
 		encryptionB, bs []byte
 		block           cipher.Block
@@ -324,6 +327,9 @@ func GetAppPaySign(appid, partnerid, noncestr, prepayid, signType, timestamp, ap
 //    beanPtr:需要解析到的结构体指针,操作完后,声明的结构体会被赋值
 //    文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html
 func DecryptOpenDataToStruct(encryptedData, iv, sessionKey string, beanPtr interface{}) (err error) {
+	if encryptedData == gopay.NULL || iv == gopay.NULL || sessionKey == gopay.NULL {
+		return errors.New("input params can not null")
+	}
 	var (
 		cipherText, aesKey, ivKey, plainText []byte
 		block                                cipher.Block
@@ -363,6 +369,9 @@ func DecryptOpenDataToStruct(encryptedData, iv, sessionKey string, beanPtr inter
 //    sessionKey:会话密钥,通过  gopay.Code2Session() 方法获取到
 //    文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html
 func DecryptOpenDataToBodyMap(encryptedData, iv, sessionKey string) (bm gopay.BodyMap, err error) {
+	if encryptedData == gopay.NULL || iv == gopay.NULL || sessionKey == gopay.NULL {
+		return nil, errors.New("input params can not null")
+	}
 	var (
 		cipherText, aesKey, ivKey, plainText []byte
 		block                                cipher.Block