Explorar o código

add parse notify result and fix

Jerry %!s(int64=7) %!d(string=hai) anos
pai
achega
dbd78adb42
Modificáronse 3 ficheiros con 89 adicións e 35 borrados
  1. 10 10
      wechat_client.go
  2. 21 0
      wechat_notify.go
  3. 58 25
      wechat_rsp.go

+ 10 - 10
wechat_client.go

@@ -28,7 +28,7 @@ func NewWeChatClient(appId, mchId, secretKey string, isProd bool) *weChatClient
 
 //统一下单 ok
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1
-func (this *weChatClient) UnifiedOrder(body BodyMap) (wxRsp *weChatUnifiedOrderResponse, err error) {
+func (this *weChatClient) UnifiedOrder(body BodyMap) (wxRsp *WeChatUnifiedOrderResponse, err error) {
 	var bytes []byte
 	if this.isProd {
 		//正式环境
@@ -44,7 +44,7 @@ func (this *weChatClient) UnifiedOrder(body BodyMap) (wxRsp *weChatUnifiedOrderR
 		}
 	}
 
-	wxRsp = new(weChatUnifiedOrderResponse)
+	wxRsp = new(WeChatUnifiedOrderResponse)
 	err = xml.Unmarshal(bytes, wxRsp)
 	if err != nil {
 		return nil, err
@@ -54,7 +54,7 @@ func (this *weChatClient) UnifiedOrder(body BodyMap) (wxRsp *weChatUnifiedOrderR
 
 //查询订单 ok
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2
-func (this *weChatClient) QueryOrder(body BodyMap) (wxRsp *weChatQueryOrderResponse, err error) {
+func (this *weChatClient) QueryOrder(body BodyMap) (wxRsp *WeChatQueryOrderResponse, err error) {
 	var bytes []byte
 	if this.isProd {
 		//正式环境
@@ -69,7 +69,7 @@ func (this *weChatClient) QueryOrder(body BodyMap) (wxRsp *weChatQueryOrderRespo
 		}
 	}
 
-	wxRsp = new(weChatQueryOrderResponse)
+	wxRsp = new(WeChatQueryOrderResponse)
 	err = xml.Unmarshal(bytes, wxRsp)
 	if err != nil {
 		return nil, err
@@ -79,7 +79,7 @@ func (this *weChatClient) QueryOrder(body BodyMap) (wxRsp *weChatQueryOrderRespo
 
 //关闭订单 ok
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_3
-func (this *weChatClient) CloseOrder(body BodyMap) (wxRsp *weChatCloseOrderResponse, err error) {
+func (this *weChatClient) CloseOrder(body BodyMap) (wxRsp *WeChatCloseOrderResponse, err error) {
 	var bytes []byte
 	if this.isProd {
 		//正式环境
@@ -94,7 +94,7 @@ func (this *weChatClient) CloseOrder(body BodyMap) (wxRsp *weChatCloseOrderRespo
 		}
 	}
 
-	wxRsp = new(weChatCloseOrderResponse)
+	wxRsp = new(WeChatCloseOrderResponse)
 	err = xml.Unmarshal(bytes, wxRsp)
 	if err != nil {
 		return nil, err
@@ -104,7 +104,7 @@ func (this *weChatClient) CloseOrder(body BodyMap) (wxRsp *weChatCloseOrderRespo
 
 //申请退款 ok
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
-func (this *weChatClient) Refund(body BodyMap) (wxRsp *weChatRefundResponse, err error) {
+func (this *weChatClient) Refund(body BodyMap) (wxRsp *WeChatRefundResponse, err error) {
 	var bytes []byte
 	if this.isProd {
 		//正式环境
@@ -119,7 +119,7 @@ func (this *weChatClient) Refund(body BodyMap) (wxRsp *weChatRefundResponse, err
 		}
 	}
 
-	wxRsp = new(weChatRefundResponse)
+	wxRsp = new(WeChatRefundResponse)
 	err = xml.Unmarshal(bytes, wxRsp)
 	if err != nil {
 		return nil, err
@@ -129,7 +129,7 @@ func (this *weChatClient) Refund(body BodyMap) (wxRsp *weChatRefundResponse, err
 
 //查询退款 ok
 //    文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_5
-func (this *weChatClient) QueryRefund(body BodyMap) (wxRsp *weChatQueryRefundResponse, err error) {
+func (this *weChatClient) QueryRefund(body BodyMap) (wxRsp *WeChatQueryRefundResponse, err error) {
 	var bytes []byte
 	if this.isProd {
 		//正式环境
@@ -144,7 +144,7 @@ func (this *weChatClient) QueryRefund(body BodyMap) (wxRsp *weChatQueryRefundRes
 		}
 	}
 
-	wxRsp = new(weChatQueryRefundResponse)
+	wxRsp = new(WeChatQueryRefundResponse)
 	err = xml.Unmarshal(bytes, wxRsp)
 	if err != nil {
 		return nil, err

+ 21 - 0
wechat_notify.go

@@ -0,0 +1,21 @@
+//==================================
+//  * Name:Jerry
+//  * Tel:18017448610
+//  * DateTime:2019/1/28 20:16
+//==================================
+package gopay
+
+import (
+	"encoding/xml"
+	"net/http"
+)
+
+func ParseNotifyResult(req *http.Request) (notifyRsp *WeChatNotifyResponse, err error) {
+	notifyRsp = new(WeChatNotifyResponse)
+	defer req.Body.Close()
+	err = xml.NewDecoder(req.Body).Decode(notifyRsp)
+	if err != nil {
+		return nil, err
+	}
+	return
+}

+ 58 - 25
wechat_rsp.go

@@ -5,7 +5,7 @@
 //==================================
 package gopay
 
-type weChatUnifiedOrderResponse struct {
+type WeChatUnifiedOrderResponse struct {
 	ReturnCode string `xml:"return_code"`
 	ReturnMsg  string `xml:"return_msg"`
 	Appid      string `xml:"appid"`
@@ -22,7 +22,7 @@ type weChatUnifiedOrderResponse struct {
 	MwebUrl    string `xml:"mweb_url"`
 }
 
-type weChatQueryOrderResponse struct {
+type WeChatQueryOrderResponse struct {
 	ReturnCode         string `xml:"return_code"`
 	ReturnMsg          string `xml:"return_msg"`
 	Appid              string `xml:"appid"`
@@ -45,9 +45,9 @@ type weChatQueryOrderResponse struct {
 	CashFeeType        string `xml:"cash_fee_type"`
 	CouponFee          int    `xml:"coupon_fee"`
 	CouponCount        int    `xml:"coupon_count"`
-	CouponType0        string `xml:"coupon_type_$0"`
-	CouponId0          string `xml:"coupon_id_$0"`
-	CouponFee0         int    `xml:"coupon_fee_$0"`
+	CouponType0        string `xml:"coupon_type_0"`
+	CouponId0          string `xml:"coupon_id_0"`
+	CouponFee0         int    `xml:"coupon_fee_0"`
 	TransactionId      string `xml:"transaction_id"`
 	OutTradeNo         string `xml:"out_trade_no"`
 	Attach             string `xml:"attach"`
@@ -55,7 +55,7 @@ type weChatQueryOrderResponse struct {
 	TradeStateDesc     string `xml:"trade_state_desc"`
 }
 
-type weChatCloseOrderResponse struct {
+type WeChatCloseOrderResponse struct {
 	ReturnCode string `xml:"return_code"`
 	ReturnMsg  string `xml:"return_msg"`
 	Appid      string `xml:"appid"`
@@ -68,7 +68,7 @@ type weChatCloseOrderResponse struct {
 	ErrCodeDes string `xml:"err_code_des"`
 }
 
-type weChatRefundResponse struct {
+type WeChatRefundResponse struct {
 	ReturnCode          string `xml:"return_code"`
 	ReturnMsg           string `xml:"return_msg"`
 	ResultCode          string `xml:"result_code"`
@@ -90,14 +90,14 @@ type weChatRefundResponse struct {
 	CashFee             int    `xml:"cash_fee"`
 	CashFeeType         string `xml:"cash_fee_type"`
 	CashRefundFee       int    `xml:"cash_refund_fee"`
-	CouponType0         string `xml:"coupon_type_$0"`
+	CouponType0         string `xml:"coupon_type_0"`
 	CouponRefundFee     int    `xml:"coupon_refund_fee"`
-	CouponRefundFee0    int    `xml:"coupon_refund_fee_$0"`
+	CouponRefundFee0    int    `xml:"coupon_refund_fee_0"`
 	CouponRefundCount   int    `xml:"coupon_refund_count"`
-	CouponRefundId0     string `xml:"coupon_refund_id_$0"`
+	CouponRefundId0     string `xml:"coupon_refund_id_0"`
 }
 
-type weChatQueryRefundResponse struct {
+type WeChatQueryRefundResponse struct {
 	ReturnCode           string `xml:"return_code"`
 	ReturnMsg            string `xml:"return_msg"`
 	ResultCode           string `xml:"result_code"`
@@ -115,20 +115,20 @@ type weChatQueryRefundResponse struct {
 	FeeType              string `xml:"fee_type"`
 	CashFee              int    `xml:"cash_fee"`
 	RefundCount          int    `xml:"refund_count"`
-	OutRefundNo0         string `xml:"out_refund_no_$0"`
-	RefundId0            string `xml:"refund_id_$0"`
-	RefundChannel0       string `xml:"refund_channel_$0"`
-	RefundFee0           int    `xml:"refund_fee_$0"`
-	SettlementRefundFee0 int    `xml:"settlement_refund_fee_$0"`
-	CouponType00         string `xml:"coupon_type_$0_$0"`
-	CouponRefundFee0     int    `xml:"coupon_refund_fee_$0"`
-	CouponRefundCount0   int    `xml:"coupon_refund_count_$0"`
-	CouponRefundId00     string `xml:"coupon_refund_id_$0_$0"`
-	CouponRefundFee00    int    `xml:"coupon_refund_fee_$0_$0"`
-	RefundStatus0        string `xml:"refund_status_$0"`
-	RefundAccount0       string `xml:"refund_account_$0"`
-	RefundRecvAccout0    string `xml:"refund_recv_accout_$0"`
-	RefundSuccessTime0   string `xml:"refund_success_time_$0"`
+	OutRefundNo0         string `xml:"out_refund_no_0"`
+	RefundId0            string `xml:"refund_id_0"`
+	RefundChannel0       string `xml:"refund_channel_0"`
+	RefundFee0           int    `xml:"refund_fee_0"`
+	SettlementRefundFee0 int    `xml:"settlement_refund_fee_0"`
+	CouponType00         string `xml:"coupon_type_0_0"`
+	CouponRefundFee0     int    `xml:"coupon_refund_fee_0"`
+	CouponRefundCount0   int    `xml:"coupon_refund_count_0"`
+	CouponRefundId00     string `xml:"coupon_refund_id_0_0"`
+	CouponRefundFee00    int    `xml:"coupon_refund_fee_0_0"`
+	RefundStatus0        string `xml:"refund_status_0"`
+	RefundAccount0       string `xml:"refund_account_0"`
+	RefundRecvAccout0    string `xml:"refund_recv_accout_0"`
+	RefundSuccessTime0   string `xml:"refund_success_time_0"`
 }
 
 type getSignKeyResponse struct {
@@ -139,3 +139,36 @@ type getSignKeyResponse struct {
 	MchId          string `xml:"mch_id"`
 	SandboxSignkey string `xml:"sandbox_signkey"`
 }
+
+type WeChatNotifyResponse struct {
+	ReturnCode         string `xml:"return_code"`
+	ReturnMsg          string `xml:"return_msg"`
+	ResultCode         string `xml:"result_code"`
+	ErrCode            string `xml:"err_code"`
+	ErrCodeDes         string `xml:"err_code_des"`
+	Appid              string `xml:"appid"`
+	MchId              string `xml:"mch_id"`
+	DeviceInfo         string `xml:"device_info"`
+	NonceStr           string `xml:"nonce_str"`
+	Sign               string `xml:"sign"`
+	SignType           string `xml:"sign_type"`
+	Openid             string `xml:"openid"`
+	IsSubscribe        string `xml:"is_subscribe"`
+	TradeType          string `xml:"trade_type"`
+	TradeState         string `xml:"trade_state"`
+	BankType           string `xml:"bank_type"`
+	TotalFee           int    `xml:"total_fee"`
+	SettlementTotalFee int    `xml:"settlement_total_fee"`
+	FeeType            string `xml:"fee_type"`
+	CashFee            int    `xml:"cash_fee"`
+	CashFeeType        string `xml:"cash_fee_type"`
+	CouponFee          int    `xml:"coupon_fee"`
+	CouponCount        int    `xml:"coupon_count"`
+	CouponType0        string `xml:"coupon_type_0"`
+	CouponId0          string `xml:"coupon_id_0"`
+	CouponFee0         int    `xml:"coupon_fee_0"`
+	TransactionId      string `xml:"transaction_id"`
+	OutTradeNo         string `xml:"out_trade_no"`
+	Attach             string `xml:"attach"`
+	TimeEnd            string `xml:"time_end"`
+}