checheHttpClient.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package thirdparty
  2. import (
  3. "gd_management/common.in/config"
  4. "gd_management/common.in/httpClient"
  5. "gd_management/common.in/utils"
  6. "encoding/base64"
  7. "encoding/json"
  8. "fmt"
  9. "go.uber.org/zap"
  10. hurl "net/url"
  11. "strings"
  12. )
  13. /*var CheCheMd5Key = "e10adc3949ba59abbe56e057f20f883e"
  14. var CheCheAID = "78900"
  15. var CheCheMid = "78900"
  16. */
  17. func CheCheHttpPost(url string, action string, param map[string]string) (result []byte, err error) {
  18. defer func() {
  19. l.Info("thirdparty",
  20. zap.String("api", url),
  21. zap.String("request", utils.MarshalJsonString(param)),
  22. zap.String("response", utils.MarshalJsonString(result)))
  23. }()
  24. param["aId"] = config.Conf.ThirdPart.CheCheAid
  25. param["mId"] = config.Conf.ThirdPart.CheCheMid
  26. param["action"] = action
  27. urlValue := hurl.Values{}
  28. for k, v := range param {
  29. urlValue.Add(k, v)
  30. }
  31. signText := urlValue.Encode()
  32. signText = fmt.Sprintf("%s&%s", signText, config.Conf.ThirdPart.CheCheMd5Key)
  33. sign := utils.MD5(signText)
  34. sign = strings.ToUpper(sign)
  35. param["sign"] = sign
  36. for k, v := range param {
  37. param[k] = hurl.QueryEscape(v)
  38. }
  39. bytes, _ := json.Marshal(param)
  40. b64 := base64.StdEncoding.EncodeToString(bytes)
  41. var query = map[string]string{
  42. "Base64": b64,
  43. }
  44. return httpClient.HttpPostWithHead(url, nil, query, nil)
  45. }