12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 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"
- )
- func MojiWeatherPost(api string, data map[string]string) (result []byte, err error) {
- defer func() {
- l.Info("thirdparty",
- zap.String("api", api),
- zap.String("request", utils.MarshalJsonString(data)),
- zap.String("response", string(result)))
- }()
- values := url.Values{}
- values.Set("cityId", data["cityId"])
- //values.Set("token", data["token"])
- req, err := http.NewRequest("POST", api, bytes.NewBufferString(values.Encode()))
- req.Header.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
- req.Header.Add("Authorization", "APPCODE "+config.Conf.ThirdPart.MojiAppCode)
- client := &http.Client{}
- client.Timeout = 30 * time.Second
- 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
- }
|