12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package thirdparty
- import (
- "bytes"
- "gd_management/common.in/config"
- "encoding/base64"
- "encoding/json"
- "io/ioutil"
- "net/http"
- "net/url"
- "time"
- "gd_management/common.in/utils"
- "go.uber.org/zap"
- )
- const (
- //sanfangcxHost = "http://sanfangcx.xmxing.net"
- sanfangcxDESKey = "33725169"
- dwKey = "be2hjdeii1f90c5c55bfa0af7"
- )
- func SanfangcxHttpPost(api string, data map[string]string) (result []byte, err error) {
- //fullApi := sanfangcxFullURL(api, host)
- 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.ScViolationDwkey
- v, err := json.Marshal(data)
- if err != nil {
- return nil, err
- }
- encrypt, err := utils.CBCDesEncrypt(sanfangcxEncryptkey(), sanfangcxEncryptIv(), v)
- if err != nil {
- return nil, err
- }
- values := url.Values{}
- values.Set("data", base64.StdEncoding.EncodeToString(encrypt))
- client := &http.Client{}
- client.Timeout = 30 * 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 := base64.StdEncoding.DecodeString(string(body))
- if err != nil {
- return nil, err
- }
- result, err = utils.CBCDesDecrypt(sanfangcxEncryptkey(), sanfangcxEncryptIv(), unBase64)
- return
- }
- /*func sanfangcxFullURL(api string, host string) string {
- return host + "/" + api
- }*/
- func sanfangcxEncryptkey() []byte {
- return []byte(config.Conf.ThirdPart.ScViolationEncKey)
- }
- func sanfangcxEncryptIv() []byte {
- return []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
- }
|