1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package thirdparty
- import (
- "gd_management/common.in/config"
- "gd_management/common.in/utils"
- "fmt"
- "go.uber.org/zap"
- "io/ioutil"
- "net/http"
- "strings"
- "time"
- )
- const (
- zxHost = "http://vip.98zhengxin.com"
- //zxAppKey = "001061808271603202J1I3Q1H0T2L"
- //zxAppCode = "65db6e13ecef31a54642df747986472a"
- zxAppKey = "002131812131656325G1J8O8E2Z7E"
- zxAppCode = "2b7a2390dabe846437c74a51244fee4c"
- )
- func zxFullUrl(api string) string {
- return fmt.Sprintf("%s/%s", zxHost, api)
- }
- func ZxHttpGet(api string, data map[string]string) (result []byte, err error) {
- //url := zxFullUrl(api)
- defer func() {
- l.Info("thirdparty",
- zap.String("api", api),
- zap.String("request", utils.MarshalJsonString(data)),
- zap.String("response", string(result)))
- }()
- req, err := http.NewRequest("GET", zxConcatGetURL(api, data), nil)
- req.Header.Set("COMPANY_KEY", config.Conf.ThirdPart.ZxCompanyKey)
- req.Header.Set("COMPANY_CODE", config.Conf.ThirdPart.ZxCompanyCode)
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
- client := &http.Client{}
- client.Timeout = 60 * time.Second
- resp, err := client.Do(req)
- if err != nil {
- return nil, err
- }
- defer resp.Body.Close()
- result, err = ioutil.ReadAll(resp.Body)
- return result, err
- }
- func zxConcatGetURL(url string, data map[string]string) string {
- if data == nil {
- return url
- }
- for k, v := range data {
- url = url + "&" + k + "=" + v
- }
- url = strings.Replace(url, "&", "?", 1)
- return url
- }
|