/
curl.go
38 lines (36 loc) · 979 Bytes
/
curl.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
package until
import (
"bytes"
"crypto/tls"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"net/url"
"strings"
)
func PostData(post_data interface{}, sinapay_url string) (result map[string]interface{}, err error) {
excludeSlice := []string{"sign", "sign_type", "sign_version"}
splice := QueryStr(post_data, true, excludeSlice)
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
res, err := client.Post(sinapay_url, "application/x-www-form-urlencoded;charset=utf-8", strings.NewReader(splice))
if err != nil {
log.Fatal(err)
return
}
defer res.Body.Close()
ret, rerr := ioutil.ReadAll(res.Body)
if rerr != nil {
log.Fatal(err)
return
}
encodeStr, err := url.QueryUnescape(string(ret))
result = make(map[string]interface{})
decoder := json.NewDecoder(bytes.NewBuffer([]byte(encodeStr)))
decoder.UseNumber() // 此处能够保证bigint的精度
decoder.Decode(&result)
return
}