1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package thirdparty
- import (
- "bytes"
- "gd_management/common.in/config"
- "gd_management/common.in/utils"
- "encoding/json"
- "fmt"
- "go.uber.org/zap"
- "io/ioutil"
- "net/http"
- "net/url"
- "strconv"
- "time"
- )
- func VerifyHttpPost(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.Dwkey
- data["to_ken"] = config.Conf.ThirdPart.Token
- data["sjc"] = strconv.FormatInt(time.Now().Unix(), 10)
- v, err := json.Marshal(data)
- if err != nil {
- return nil, err
- }
- encrypt, err := utils.DesEncrypt(verifyEncryptkey(), verifyEncryptIv(), 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(verifyEncryptkey(), verifyEncryptIv(), unBase64)
- fmt.Println(string(result))
- return result, err
- }
- func verifyEncryptkey() []byte {
- return []byte(config.Conf.ThirdPart.EncKey)
- }
- func verifyEncryptIv() []byte {
- return []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
- }
|