36 lines
738 B
Go
36 lines
738 B
Go
package weixinpay
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/tls"
|
|
"io/ioutil"
|
|
"net/http"
|
|
)
|
|
|
|
// doRequest post the order in xml format with a sign
|
|
func doHttpPost(targetUrl string, body []byte) ([]byte, error) {
|
|
req, err := http.NewRequest("POST", targetUrl, bytes.NewReader(body))
|
|
if err != nil {
|
|
return []byte(""), err
|
|
}
|
|
req.Header.Add("Content-type", "application/x-www-form-urlencoded;charset=UTF-8")
|
|
|
|
tr := &http.Transport{
|
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: false},
|
|
}
|
|
client := &http.Client{Transport: tr}
|
|
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
return []byte(""), err
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
respData, err := ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return []byte(""), err
|
|
}
|
|
|
|
return respData, nil
|
|
}
|