1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package thirdparty
- import (
- "bytes"
- "gd_management/common.in/config"
- "gd_management/common.in/utils"
- "go.uber.org/zap"
- "io/ioutil"
- "net/http"
- "net/url"
- "time"
- )
- /*const (
- TOKEN = "81ed9993bcad8cd0d1f55f9565104b76"
- )
- */
- func msConcatPostURL(api string) string {
- return api + "?token=" + config.Conf.ThirdPart.MsToken
- }
- func MsHttpClient(api string, values url.Values) (result []byte, err error) {
- client := &http.Client{}
- client.Timeout = 30 * time.Second
- defer func() {
- l.Info("thirdparty",
- zap.String("api", api),
- zap.String("request", utils.MarshalJsonString(values)),
- zap.String("response", utils.MarshalJsonString(result)))
- }()
- req, err := http.NewRequest("POST", msConcatPostURL(api), bytes.NewBufferString(values.Encode()))
- if err != nil {
- return nil, err
- }
- req.Header.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
- resp, err := client.Do(req)
- if err != nil {
- return nil, err
- }
- defer resp.Body.Close()
- result, err = ioutil.ReadAll(resp.Body)
- if err != nil {
- return nil, err
- }
- return result, nil
- }
|