|
@@ -6,12 +6,13 @@
|
|
|
package gopay
|
|
package gopay
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "bytes"
|
|
|
"encoding/xml"
|
|
"encoding/xml"
|
|
|
"net/http"
|
|
"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()
|
|
defer req.Body.Close()
|
|
|
err = xml.NewDecoder(req.Body).Decode(notifyRsp)
|
|
err = xml.NewDecoder(req.Body).Decode(notifyRsp)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -19,3 +20,21 @@ func ParseNotifyResult(req *http.Request) (notifyRsp *WeChatNotifyResponse, err
|
|
|
}
|
|
}
|
|
|
return
|
|
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
|
|
|
|
|
+}
|