Jerry 6 years ago
parent
commit
fcc3d28fbd
3 changed files with 52 additions and 17 deletions
  1. 6 6
      README.md
  2. 28 0
      wechat_rsp.go
  3. 18 11
      wechat_servier_api.go

+ 6 - 6
README.md

@@ -29,10 +29,10 @@
 * gopay.GetMiniPaySign() => 获取微信小程序支付所需要的paySign
 * gopay.GetH5PaySign() => 获取微信内H5支付所需要的paySign
 * gopay.GetAppPaySign() => 获取APP支付所需要的paySign
-* gopay.ParseWeChatNotifyResult() => 解析并返回微信支付异步通知的结果
+* gopay.ParseWeChatNotifyResultToBodyMap() => 解析微信支付异步通知的结果到BodyMap
+* gopay.ParseWeChatNotifyResult() => 解析微信支付异步通知的参数
+* gopay.VerifyWeChatResultSignByBodyMap() => 通过BodyMap验证微信支付异步通知的Sign值
 * gopay.VerifyWeChatResultSign() => 验证微信支付异步通知的Sign值
-* (已过时)gopay.ParseNotifyResult() => 解析并返回微信支付异步通知的参数
-* (已过时)gopay.VerifyPayResultSign() => 微信支付异步通知的签名验证和返回参数验签后的Sign
 * gopay.Code2Session() => 登录凭证校验:获取微信用户OpenId、UnionId、SessionKey
 * gopay.GetAccessToken() => 获取小程序全局唯一后台接口调用凭据
 * gopay.GetPaidUnionId() => 用户支付完成后,获取该用户的 UnionId,无需用户授权
@@ -189,7 +189,7 @@ fmt.Println("paySign:", paySign)
 //    req:*http.Request
 //    返回参数bm:Notify请求的参数
 //    返回参数err:错误信息
-bm, err := gopay.ParseWeChatNotifyResult(c.Request())
+bm, err := gopay.ParseWeChatNotifyResultToBodyMap(c.Request())
 if err != nil {
     fmt.Println("err:", err)
     return
@@ -198,10 +198,10 @@ if err != nil {
 //验证微信支付异步通知的Sign值
 //    apiKey:API秘钥值
 //    signType:签名类型 MD5 或 HMAC-SHA256(默认请填写 MD5)
-//    bm:通过 gopay.ParseWeChatNotifyResult() 得到的BodyMap
+//    bm:通过 gopay.ParseWeChatNotifyResultToBodyMap() 得到的BodyMap
 //    返回参数ok:是否验证通过
 //    返回参数sign:计算出的sign值,非微信返回参数中的Sign
-ok, sign := gopay.VerifyWeChatResultSign("192006250b4c09247ec02edce69f6a2d", gopay.SignType_MD5, bm)
+ok, sign := gopay.VerifyWeChatResultSignByBodyMap("192006250b4c09247ec02edce69f6a2d", gopay.SignType_MD5, bm)
 fmt.Println("ok:", ok)
 fmt.Println("sign:", sign)
 ```

+ 28 - 0
wechat_rsp.go

@@ -109,8 +109,12 @@ type WeChatRefundResponse struct {
 	CouponType2         string `xml:"coupon_type_2,omitempty"`
 	CouponRefundFee     int    `xml:"coupon_refund_fee,omitempty"`
 	CouponRefundFee0    int    `xml:"coupon_refund_fee_0,omitempty"`
+	CouponRefundFee1    int    `xml:"coupon_refund_fee_1,omitempty"`
+	CouponRefundFee2    int    `xml:"coupon_refund_fee_2,omitempty"`
 	CouponRefundCount   int    `xml:"coupon_refund_count,omitempty"`
 	CouponRefundId0     string `xml:"coupon_refund_id_0,omitempty"`
+	CouponRefundId1     string `xml:"coupon_refund_id_1,omitempty"`
+	CouponRefundId2     string `xml:"coupon_refund_id_2,omitempty"`
 }
 
 type WeChatQueryRefundResponse struct {
@@ -138,17 +142,41 @@ type WeChatQueryRefundResponse struct {
 	RefundId1            string `xml:"refund_id_1,omitempty"`
 	RefundId2            string `xml:"refund_id_2,omitempty"`
 	RefundChannel0       string `xml:"refund_channel_0,omitempty"`
+	RefundChannel1       string `xml:"refund_channel_1,omitempty"`
+	RefundChannel2       string `xml:"refund_channel_2,omitempty"`
 	RefundFee0           int    `xml:"refund_fee_0,omitempty"`
+	RefundFee1           int    `xml:"refund_fee_1,omitempty"`
+	RefundFee2           int    `xml:"refund_fee_2,omitempty"`
 	SettlementRefundFee0 int    `xml:"settlement_refund_fee_0,omitempty"`
+	SettlementRefundFee1 int    `xml:"settlement_refund_fee_1,omitempty"`
+	SettlementRefundFee2 int    `xml:"settlement_refund_fee_2,omitempty"`
 	CouponType00         string `xml:"coupon_type_0_0,omitempty"`
+	CouponType01         string `xml:"coupon_type_0_1,omitempty"`
+	CouponType02         string `xml:"coupon_type_0_2,omitempty"`
 	CouponRefundFee0     int    `xml:"coupon_refund_fee_0,omitempty"`
+	CouponRefundFee1     int    `xml:"coupon_refund_fee_1,omitempty"`
+	CouponRefundFee2     int    `xml:"coupon_refund_fee_2,omitempty"`
 	CouponRefundCount0   int    `xml:"coupon_refund_count_0,omitempty"`
+	CouponRefundCount1   int    `xml:"coupon_refund_count_1,omitempty"`
+	CouponRefundCount2   int    `xml:"coupon_refund_count_2,omitempty"`
 	CouponRefundId00     string `xml:"coupon_refund_id_0_0,omitempty"`
+	CouponRefundId01     string `xml:"coupon_refund_id_0_1,omitempty"`
+	CouponRefundId02     string `xml:"coupon_refund_id_0_2,omitempty"`
 	CouponRefundFee00    int    `xml:"coupon_refund_fee_0_0,omitempty"`
+	CouponRefundFee01    int    `xml:"coupon_refund_fee_0_1,omitempty"`
+	CouponRefundFee02    int    `xml:"coupon_refund_fee_0_2,omitempty"`
 	RefundStatus0        string `xml:"refund_status_0,omitempty"`
+	RefundStatus1        string `xml:"refund_status_1,omitempty"`
+	RefundStatus2        string `xml:"refund_status_2,omitempty"`
 	RefundAccount0       string `xml:"refund_account_0,omitempty"`
+	RefundAccount1       string `xml:"refund_account_1,omitempty"`
+	RefundAccount2       string `xml:"refund_account_2,omitempty"`
 	RefundRecvAccout0    string `xml:"refund_recv_accout_0,omitempty"`
+	RefundRecvAccout1    string `xml:"refund_recv_accout_1,omitempty"`
+	RefundRecvAccout2    string `xml:"refund_recv_accout_2,omitempty"`
 	RefundSuccessTime0   string `xml:"refund_success_time_0,omitempty"`
+	RefundSuccessTime1   string `xml:"refund_success_time_1,omitempty"`
+	RefundSuccessTime2   string `xml:"refund_success_time_2,omitempty"`
 }
 
 type WeChatMicropayResponse struct {

+ 18 - 11
wechat_servier_api.go

@@ -19,11 +19,11 @@ import (
 	"strings"
 )
 
-//解析并返回微信支付异步通知的结果
+//解析微信支付异步通知的结果到BodyMap
 //    req:*http.Request
 //    返回参数bm:Notify请求的参数
 //    返回参数err:错误信息
-func ParseWeChatNotifyResult(req *http.Request) (bm BodyMap, err error) {
+func ParseWeChatNotifyResultToBodyMap(req *http.Request) (bm BodyMap, err error) {
 	bs, err := ioutil.ReadAll(req.Body)
 	defer req.Body.Close()
 	if err != nil {
@@ -39,13 +39,13 @@ func ParseWeChatNotifyResult(req *http.Request) (bm BodyMap, err error) {
 	return
 }
 
-//验证微信支付异步通知的Sign值
+//通过BodyMap验证微信支付异步通知的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) {
+func VerifyWeChatResultSignByBodyMap(apiKey string, signType string, bm BodyMap) (ok bool, sign string) {
 	//验证Sign值的BodyMap
 	bmNew := make(BodyMap)
 	for key := range bm {
@@ -60,9 +60,11 @@ func VerifyWeChatResultSign(apiKey string, signType string, bm BodyMap) (ok bool
 	return
 }
 
-//解析并返回微信支付异步通知的参数
-//    已废弃,请使用新方法替换:ParseWeChatNotifyParamAndVerifySign
-func ParseNotifyResult(req *http.Request) (notifyRsp *WeChatNotifyRequest, err error) {
+//解析微信支付异步通知的参数
+//    req:*http.Request
+//    返回参数notifyRsp:Notify请求的参数
+//    返回参数err:错误信息
+func ParseWeChatNotifyResult(req *http.Request) (notifyRsp *WeChatNotifyRequest, err error) {
 	notifyRsp = new(WeChatNotifyRequest)
 	defer req.Body.Close()
 	err = xml.NewDecoder(req.Body).Decode(notifyRsp)
@@ -72,14 +74,13 @@ func ParseNotifyResult(req *http.Request) (notifyRsp *WeChatNotifyRequest, err e
 	return
 }
 
-//支付通知的签名验证和参数签名后的Sign
-//    已废弃,请使用新方法替换:ParseWeChatNotifyParamAndVerifySign
+//验证微信支付异步通知的Sign值
 //    apiKey:API秘钥值
 //    signType:签名类型 MD5 或 HMAC-SHA256(默认请填写 MD5)
-//    notifyRsp:利用 gopay.ParseNotifyResult() 得到的结构体
+//    notifyRsp:利用 gopay.ParseWeChatNotifyResult() 得到的结构体
 //    返回参数ok:是否验证通过
 //    返回参数sign:根据参数计算的sign值,非微信返回参数中的Sign
-func VerifyPayResultSign(apiKey string, signType string, notifyRsp *WeChatNotifyRequest) (ok bool, sign string) {
+func VerifyWeChatResultSign(apiKey string, signType string, notifyRsp *WeChatNotifyRequest) (ok bool, sign string) {
 	body := make(BodyMap)
 	body.Set("return_code", notifyRsp.ReturnCode)
 	body.Set("return_msg", notifyRsp.ReturnMsg)
@@ -103,8 +104,14 @@ func VerifyPayResultSign(apiKey string, signType string, notifyRsp *WeChatNotify
 	body.Set("coupon_fee", notifyRsp.CouponFee)
 	body.Set("coupon_count", notifyRsp.CouponCount)
 	body.Set("coupon_type_0", notifyRsp.CouponType0)
+	body.Set("coupon_type_1", notifyRsp.CouponType1)
+	body.Set("coupon_type_2", notifyRsp.CouponType2)
 	body.Set("coupon_id_0", notifyRsp.CouponId0)
+	body.Set("coupon_id_1", notifyRsp.CouponId1)
+	body.Set("coupon_id_2", notifyRsp.CouponId2)
 	body.Set("coupon_fee_0", notifyRsp.CouponFee0)
+	body.Set("coupon_fee_1", notifyRsp.CouponFee1)
+	body.Set("coupon_fee_2", notifyRsp.CouponFee2)
 	body.Set("transaction_id", notifyRsp.TransactionId)
 	body.Set("out_trade_no", notifyRsp.OutTradeNo)
 	body.Set("attach", notifyRsp.Attach)