Просмотр исходного кода

add return wechat notify result

Jerry 7 лет назад
Родитель
Сommit
ec7e68efdc
2 измененных файлов с 22 добавлено и 3 удалено
  1. 21 2
      wechat_notify.go
  2. 1 1
      wechat_rsp.go

+ 21 - 2
wechat_notify.go

@@ -6,12 +6,13 @@
 package gopay
 
 import (
+	"bytes"
 	"encoding/xml"
 	"net/http"
 )
 
-func ParseNotifyResult(req *http.Request) (notifyRsp *WeChatNotifyResponse, err error) {
-	notifyRsp = new(WeChatNotifyResponse)
+func ParseNotifyResult(req *http.Request) (notifyRsp *WeChatNotifyRequest, err error) {
+	notifyRsp = new(WeChatNotifyRequest)
 	defer req.Body.Close()
 	err = xml.NewDecoder(req.Body).Decode(notifyRsp)
 	if err != nil {
@@ -19,3 +20,21 @@ func ParseNotifyResult(req *http.Request) (notifyRsp *WeChatNotifyResponse, err
 	}
 	return
 }
+
+type WeChatNotifyResponse struct {
+	ReturnCode string `xml:"return_code"`
+	ReturnMsg  string `xml:"return_msg"`
+}
+
+func (this *WeChatNotifyResponse) ToXmlString() (xmlStr string) {
+	buffer := new(bytes.Buffer)
+	buffer.WriteString("<xml><return_code><![CDATA[")
+	buffer.WriteString(this.ReturnCode)
+	buffer.WriteString("]]></return_code>")
+
+	buffer.WriteString("<return_msg><![CDATA[")
+	buffer.WriteString(this.ReturnMsg)
+	buffer.WriteString("]]></return_msg></xml>")
+	xmlStr = buffer.String()
+	return
+}

+ 1 - 1
wechat_rsp.go

@@ -140,7 +140,7 @@ type getSignKeyResponse struct {
 	SandboxSignkey string `xml:"sandbox_signkey"`
 }
 
-type WeChatNotifyResponse struct {
+type WeChatNotifyRequest struct {
 	ReturnCode         string `xml:"return_code"`
 	ReturnMsg          string `xml:"return_msg"`
 	ResultCode         string `xml:"result_code"`