-
Notifications
You must be signed in to change notification settings - Fork 36
/
notify.go
48 lines (39 loc) · 1.02 KB
/
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
42
43
44
45
46
47
48
package wxpay
import (
"encoding/xml"
"errors"
"io/ioutil"
"net/http"
"net/url"
)
// GetTradeNotification https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_7&index=3
func (this *Client) GetTradeNotification(req *http.Request) (*TradeNotification, error) {
key, err := this.getKey()
if err != nil {
return nil, err
}
return GetTradeNotification(req, key)
}
func GetTradeNotification(req *http.Request, key string) (noti *TradeNotification, err error) {
if req == nil {
return nil, errors.New("request 参数不能为空")
}
var data, _ = ioutil.ReadAll(req.Body)
if _, err := VerifyResponseData(data, key); err != nil {
return nil, err
}
if err = xml.Unmarshal(data, ¬i); err != nil {
return nil, err
}
return noti, err
}
func (this *Client) AckNotification(w http.ResponseWriter) {
AckNotification(w)
}
func AckNotification(w http.ResponseWriter) {
var v = url.Values{}
v.Set("return_code", "SUCCESS")
v.Set("return_msg", "OK")
w.WriteHeader(http.StatusOK)
w.Write([]byte(URLValueToXML(v)))
}