sanfangcx.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package thirdparty
  2. import (
  3. "bytes"
  4. "gd_management/common.in/config"
  5. "encoding/base64"
  6. "encoding/json"
  7. "io/ioutil"
  8. "net/http"
  9. "net/url"
  10. "time"
  11. "gd_management/common.in/utils"
  12. "go.uber.org/zap"
  13. )
  14. const (
  15. //sanfangcxHost = "http://sanfangcx.xmxing.net"
  16. sanfangcxDESKey = "33725169"
  17. dwKey = "be2hjdeii1f90c5c55bfa0af7"
  18. )
  19. func SanfangcxHttpPost(api string, data map[string]string) (result []byte, err error) {
  20. //fullApi := sanfangcxFullURL(api, host)
  21. defer func() {
  22. l.Info("thirdparty",
  23. zap.String("api", api),
  24. zap.String("request", utils.MarshalJsonString(data)),
  25. zap.String("response", utils.MarshalJsonString(result)))
  26. }()
  27. if data == nil {
  28. data = make(map[string]string)
  29. }
  30. data["dwkey"] = config.Conf.ThirdPart.ScViolationDwkey
  31. v, err := json.Marshal(data)
  32. if err != nil {
  33. return nil, err
  34. }
  35. encrypt, err := utils.CBCDesEncrypt(sanfangcxEncryptkey(), sanfangcxEncryptIv(), v)
  36. if err != nil {
  37. return nil, err
  38. }
  39. values := url.Values{}
  40. values.Set("data", base64.StdEncoding.EncodeToString(encrypt))
  41. client := &http.Client{}
  42. client.Timeout = 30 * time.Second
  43. req, err := http.NewRequest("POST", api, bytes.NewBufferString(values.Encode()))
  44. if err != nil {
  45. return nil, err
  46. }
  47. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  48. resp, err := client.Do(req)
  49. if err != nil {
  50. return nil, err
  51. }
  52. defer resp.Body.Close()
  53. body, err := ioutil.ReadAll(resp.Body)
  54. if err != nil {
  55. return nil, err
  56. }
  57. unBase64, err := base64.StdEncoding.DecodeString(string(body))
  58. if err != nil {
  59. return nil, err
  60. }
  61. result, err = utils.CBCDesDecrypt(sanfangcxEncryptkey(), sanfangcxEncryptIv(), unBase64)
  62. return
  63. }
  64. /*func sanfangcxFullURL(api string, host string) string {
  65. return host + "/" + api
  66. }*/
  67. func sanfangcxEncryptkey() []byte {
  68. return []byte(config.Conf.ThirdPart.ScViolationEncKey)
  69. }
  70. func sanfangcxEncryptIv() []byte {
  71. return []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
  72. }