forked from smartwalle/alipay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.go
52 lines (47 loc) · 1012 Bytes
/
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
49
50
51
52
package alipay
import (
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
func NewRequest(method, url string, params url.Values) (*http.Request, error) {
var m = strings.ToUpper(method)
var body io.Reader
if m == "GET" || m == "HEAD" {
if len(params) > 0 {
if strings.Contains(url, "?") {
url = url + "&" + params.Encode()
} else {
url = url + "?" + params.Encode()
}
}
} else {
body = strings.NewReader(params.Encode())
}
return http.NewRequest(m, url, body)
}
func (this *AliPay) NotifyVerify(notifyId string) bool {
var param = url.Values{}
param.Add("service", "notify_verify")
param.Add("partner", this.partnerId)
param.Add("notify_id", notifyId)
req, err := NewRequest("GET", this.apiDomain, param)
if err != nil {
return false
}
rep, err := this.client.Do(req)
if err != nil {
return false
}
defer rep.Body.Close()
data, err := ioutil.ReadAll(rep.Body)
if err != nil {
return false
}
if string(data) == "true" {
return true
}
return false
}