Jerry 6 anni fa
parent
commit
275e0e0809
4 ha cambiato i file con 49 aggiunte e 38 eliminazioni
  1. 15 11
      README.md
  2. 0 18
      util.go
  3. 18 0
      wechat_rsp.go
  4. 16 9
      wechat_servier_api.go

+ 15 - 11
README.md

@@ -29,9 +29,10 @@
 * gopay.GetMiniPaySign() => 获取微信小程序支付所需要的paySign
 * gopay.GetH5PaySign() => 获取微信内H5支付所需要的paySign
 * gopay.GetAppPaySign() => 获取APP支付所需要的paySign
-* gopay.ParseWeChatNotifyParamAndVerifySign() => 解析并返回微信支付异步通知的参数,并验证Sign值
-* (已废弃)gopay.ParseNotifyResult() => 解析并返回微信支付异步通知的参数
-* (已废弃)gopay.VerifyPayResultSign() => 微信支付异步通知的签名验证和返回参数验签后的Sign
+* gopay.ParseWeChatNotifyResult() => 解析并返回微信支付异步通知的结果
+* gopay.VerifyWeChatResultSign() => 验证微信支付异步通知的Sign值
+* (已过时)gopay.ParseNotifyResult() => 解析并返回微信支付异步通知的参数
+* (已过时)gopay.VerifyPayResultSign() => 微信支付异步通知的签名验证和返回参数验签后的Sign
 * gopay.Code2Session() => 登录凭证校验:获取微信用户OpenId、UnionId、SessionKey
 * gopay.GetAccessToken() => 获取小程序全局唯一后台接口调用凭据
 * gopay.GetPaidUnionId() => 用户支付完成后,获取该用户的 UnionId,无需用户授权
@@ -179,25 +180,28 @@ paySign := gopay.GetAppPaySign(appid, partnerid, wxRsp.NonceStr, prepayid, gopay
 fmt.Println("paySign:", paySign)
 ```
 
-### 解析并返回微信支付异步通知的参数,验证Sign值
+### 1、解析并返回微信支付异步通知的参数,2、验证Sign值
 
 > 微信支付后的异步通知文档:[支付结果通知](https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_7&index=8)
 
 ```go
-//解析并返回微信支付异步通知的参数,并验证Sign值
+//解析并返回微信支付异步通知的结果
 //    req:*http.Request
-//    apiKey:API秘钥值
-//    signType:签名类型 MD5 或 HMAC-SHA256(默认请填写 MD5)
 //    返回参数bm:Notify请求的参数
-//    返回参数ok:是否验证通过
-//    返回参数sign:根据参数计算的sign值,非微信返回参数中的Sign
 //    返回参数err:错误信息
-bm, ok, sign, err := gopay.ParseWeChatNotifyParamAndVerifySign(c.Request(), "192006250b4c09247ec02edce69f6a2d", gopay.SignType_MD5)
+bm, err := gopay.ParseWeChatNotifyResult(c.Request())
 if err != nil {
     fmt.Println("err:", err)
     return
 }
-fmt.Println("bm:", bm)
+
+//验证微信支付异步通知的Sign值
+//    apiKey:API秘钥值
+//    signType:签名类型 MD5 或 HMAC-SHA256(默认请填写 MD5)
+//    bm:通过 gopay.ParseWeChatNotifyResult() 得到的BodyMap
+//    返回参数ok:是否验证通过
+//    返回参数sign:计算出的sign值,非微信返回参数中的Sign
+ok, sign := gopay.VerifyWeChatResultSign("192006250b4c09247ec02edce69f6a2d", gopay.SignType_MD5, bm)
 fmt.Println("ok:", ok)
 fmt.Println("sign:", sign)
 ```

+ 0 - 18
util.go

@@ -141,24 +141,6 @@ func GetRandomString(length int) string {
 	return string(result)
 }
 
-//func convert2String(value interface{}) (valueStr string) {
-//	switch v := value.(type) {
-//	case int:
-//		valueStr = Int2String(v)
-//	case int64:
-//		valueStr = Int642String(v)
-//	case float64:
-//		valueStr = Float64ToString(v)
-//	case float32:
-//		valueStr = Float32ToString(v)
-//	case string:
-//		valueStr = v
-//	default:
-//		valueStr = null
-//	}
-//	return
-//}
-
 //解析时间
 func ParseDateTime(timeStr string) (datetime time.Time) {
 	datetime, _ = time.ParseInLocation(TimeLayout, timeStr, time.Local)

+ 18 - 0
wechat_rsp.go

@@ -41,8 +41,14 @@ type WeChatQueryOrderResponse struct {
 	CouponFee          int    `xml:"coupon_fee,omitempty"`
 	CouponCount        int    `xml:"coupon_count,omitempty"`
 	CouponType0        string `xml:"coupon_type_0,omitempty"`
+	CouponType1        string `xml:"coupon_type_1,omitempty"`
+	CouponType2        string `xml:"coupon_type_2,omitempty"`
 	CouponId0          string `xml:"coupon_id_0,omitempty"`
+	CouponId1          string `xml:"coupon_id_1,omitempty"`
+	CouponId2          string `xml:"coupon_id_2,omitempty"`
 	CouponFee0         int    `xml:"coupon_fee_0,omitempty"`
+	CouponFee1         int    `xml:"coupon_fee_1,omitempty"`
+	CouponFee2         int    `xml:"coupon_fee_2,omitempty"`
 	TransactionId      string `xml:"transaction_id,omitempty"`
 	OutTradeNo         string `xml:"out_trade_no,omitempty"`
 	Attach             string `xml:"attach,omitempty"`
@@ -99,6 +105,8 @@ type WeChatRefundResponse struct {
 	CashFeeType         string `xml:"cash_fee_type,omitempty"`
 	CashRefundFee       int    `xml:"cash_refund_fee,omitempty"`
 	CouponType0         string `xml:"coupon_type_0,omitempty"`
+	CouponType1         string `xml:"coupon_type_1,omitempty"`
+	CouponType2         string `xml:"coupon_type_2,omitempty"`
 	CouponRefundFee     int    `xml:"coupon_refund_fee,omitempty"`
 	CouponRefundFee0    int    `xml:"coupon_refund_fee_0,omitempty"`
 	CouponRefundCount   int    `xml:"coupon_refund_count,omitempty"`
@@ -124,7 +132,11 @@ type WeChatQueryRefundResponse struct {
 	CashFee              int    `xml:"cash_fee,omitempty"`
 	RefundCount          int    `xml:"refund_count,omitempty"`
 	OutRefundNo0         string `xml:"out_refund_no_0,omitempty"`
+	OutRefundNo1         string `xml:"out_refund_no_1,omitempty"`
+	OutRefundNo2         string `xml:"out_refund_no_2,omitempty"`
 	RefundId0            string `xml:"refund_id_0,omitempty"`
+	RefundId1            string `xml:"refund_id_1,omitempty"`
+	RefundId2            string `xml:"refund_id_2,omitempty"`
 	RefundChannel0       string `xml:"refund_channel_0,omitempty"`
 	RefundFee0           int    `xml:"refund_fee_0,omitempty"`
 	SettlementRefundFee0 int    `xml:"settlement_refund_fee_0,omitempty"`
@@ -200,8 +212,14 @@ type WeChatNotifyRequest struct {
 	CouponFee          int    `xml:"coupon_fee,omitempty"`
 	CouponCount        int    `xml:"coupon_count,omitempty"`
 	CouponType0        string `xml:"coupon_type_0,omitempty"`
+	CouponType1        string `xml:"coupon_type_1,omitempty"`
+	CouponType2        string `xml:"coupon_type_2,omitempty"`
 	CouponId0          string `xml:"coupon_id_0,omitempty"`
+	CouponId1          string `xml:"coupon_id_1,omitempty"`
+	CouponId2          string `xml:"coupon_id_2,omitempty"`
 	CouponFee0         int    `xml:"coupon_fee_0,omitempty"`
+	CouponFee1         int    `xml:"coupon_fee_1,omitempty"`
+	CouponFee2         int    `xml:"coupon_fee_2,omitempty"`
 	TransactionId      string `xml:"transaction_id,omitempty"`
 	OutTradeNo         string `xml:"out_trade_no,omitempty"`
 	Attach             string `xml:"attach,omitempty"`

+ 16 - 9
wechat_servier_api.go

@@ -19,27 +19,34 @@ import (
 	"strings"
 )
 
-//解析并返回微信支付异步通知的参数,并验证Sign值
+//解析并返回微信支付异步通知的结果
 //    req:*http.Request
-//    apiKey:API秘钥值
-//    signType:签名类型 MD5 或 HMAC-SHA256(默认请填写 MD5)
 //    返回参数bm:Notify请求的参数
-//    返回参数ok:是否验证通过
-//    返回参数sign:根据参数计算的sign值,非微信返回参数中的Sign
 //    返回参数err:错误信息
-func ParseWeChatNotifyParamAndVerifySign(req *http.Request, apiKey string, signType string) (bm BodyMap, ok bool, sign string, err error) {
+func ParseWeChatNotifyResult(req *http.Request) (bm BodyMap, err error) {
 	bs, err := ioutil.ReadAll(req.Body)
 	defer req.Body.Close()
 	if err != nil {
-		return nil, false, null, err
+		return nil, err
 	}
 	//获取Notify请求参数
 	bm = make(BodyMap)
 	err = xml.Unmarshal(bs, &bm)
 	if err != nil {
-		return nil, false, null, err
+		return nil, err
 	}
-	//新BodyMap
+
+	return
+}
+
+//验证微信支付异步通知的Sign值
+//    apiKey:API秘钥值
+//    signType:签名类型 MD5 或 HMAC-SHA256(默认请填写 MD5)
+//    bm:通过 gopay.ParseWeChatNotifyResult() 得到的BodyMap
+//    返回参数ok:是否验证通过
+//    返回参数sign:计算出的sign值,非微信返回参数中的Sign
+func VerifyWeChatResultSign(apiKey string, signType string, bm BodyMap) (ok bool, sign string) {
+	//验证Sign值的BodyMap
 	bmNew := make(BodyMap)
 	for key := range bm {
 		if key != "sign" {