verify_driver_no.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package thirdparty
  2. import (
  3. "bytes"
  4. "gd_management/common.in/config"
  5. "gd_management/common.in/utils"
  6. "encoding/json"
  7. "fmt"
  8. "go.uber.org/zap"
  9. "io/ioutil"
  10. "net/http"
  11. "net/url"
  12. "strconv"
  13. "time"
  14. )
  15. func VerifyHttpPost(api string, data map[string]string) (result []byte, err error) {
  16. defer func() {
  17. l.Info("thirdparty",
  18. zap.String("api", api),
  19. zap.String("request", utils.MarshalJsonString(data)),
  20. zap.String("response", utils.MarshalJsonString(result)))
  21. }()
  22. if data == nil {
  23. data = make(map[string]string)
  24. }
  25. data["dwkey"] = config.Conf.ThirdPart.Dwkey
  26. data["to_ken"] = config.Conf.ThirdPart.Token
  27. data["sjc"] = strconv.FormatInt(time.Now().Unix(), 10)
  28. v, err := json.Marshal(data)
  29. if err != nil {
  30. return nil, err
  31. }
  32. encrypt, err := utils.DesEncrypt(verifyEncryptkey(), verifyEncryptIv(), v)
  33. if err != nil {
  34. return nil, err
  35. }
  36. values := url.Values{}
  37. values.Set("data", string(utils.Base64Encode(encrypt)))
  38. client := &http.Client{}
  39. client.Timeout = 60 * time.Second
  40. req, err := http.NewRequest("POST", api, bytes.NewBufferString(values.Encode()))
  41. if err != nil {
  42. return nil, err
  43. }
  44. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  45. resp, err := client.Do(req)
  46. if err != nil {
  47. return nil, err
  48. }
  49. defer resp.Body.Close()
  50. body, err := ioutil.ReadAll(resp.Body)
  51. if err != nil {
  52. return nil, err
  53. }
  54. unBase64, err := utils.Base64Decode(body)
  55. if err != nil {
  56. return nil, err
  57. }
  58. result, err = utils.DesDecrypt(verifyEncryptkey(), verifyEncryptIv(), unBase64)
  59. fmt.Println(string(result))
  60. return result, err
  61. }
  62. func verifyEncryptkey() []byte {
  63. return []byte(config.Conf.ThirdPart.EncKey)
  64. }
  65. func verifyEncryptIv() []byte {
  66. return []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
  67. }