forked from go-pay/gopay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wechat_notify.go
41 lines (36 loc) · 1005 Bytes
/
wechat_notify.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//==================================
// * Name:Jerry
// * Tel:18017448610
// * DateTime:2019/1/28 20:16
//==================================
package gopay
import (
"bytes"
"encoding/xml"
"net/http"
)
//解析支付完成后的回调信息
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 {
return nil, 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
}