123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package thirdparty
- import (
- "bytes"
- "gd_management/common.in/config"
- "encoding/json"
- "go.uber.org/zap"
- "io/ioutil"
- "net/http"
- "net/url"
- "strconv"
- "time"
- "gd_management/common.in/utils"
- )
- func UtimesHttpPost(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", utils.MarshalJsonString(result)))
- }()
- if data == nil {
- data = make(map[string]string)
- }
- data["dwkey"] = config.Conf.ThirdPart.DbDwkey
- data["to_ken"] = config.Conf.ThirdPart.DbToken
- data["sjc"] = strconv.FormatInt(time.Now().Unix(), 10)
- v, err := json.Marshal(data)
- if err != nil {
- return nil, err
- }
- encrypt, err := utils.DesEncrypt(utimesEncryptkey(), utimesEncryptIv(), v)
- if err != nil {
- return nil, err
- }
- values := url.Values{}
- values.Set("data", string(utils.Base64Encode(encrypt)))
- client := &http.Client{}
- client.Timeout = 60 * time.Second
- req, err := http.NewRequest("POST", api, bytes.NewBufferString(values.Encode()))
- if err != nil {
- return nil, err
- }
- req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
- resp, err := client.Do(req)
- if err != nil {
- return nil, err
- }
- defer resp.Body.Close()
- body, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- return nil, err
- }
- unBase64, err := utils.Base64Decode(body)
- if err != nil {
- return nil, err
- }
- result, err = utils.DesDecrypt(utimesEncryptkey(), utimesEncryptIv(), unBase64)
- return result, err
- }
- func utimesEncryptkey() []byte {
- return []byte(config.Conf.ThirdPart.DbEncKey)
- }
- func utimesEncryptIv() []byte {
- return []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
- }
|