第三方api接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.1 KiB

  1. package csjplatform
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/comm"
  4. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  5. "crypto/md5"
  6. "fmt"
  7. "strings"
  8. "time"
  9. )
  10. func Send(appkey, appSecret, method string, params map[string]interface{}) (string, error) {
  11. url := "https://ecom.pangolin-sdk-toutiao.com/" + method
  12. paramJson := comm.GetSortJson(params)
  13. paramJson = strings.ReplaceAll(paramJson, "\n", "")
  14. param := map[string]interface{}{
  15. "app_id": appkey,
  16. "data": paramJson,
  17. "timestamp": time.Now().Unix(),
  18. "version": "1",
  19. "req_id": zhios_third_party_utils.UUIDString(),
  20. }
  21. sign := GetSign(appSecret, param)
  22. param["sign"] = sign
  23. param["sign_type"] = "MD5"
  24. data, err := zhios_third_party_utils.CurlPost(url, zhios_third_party_utils.SerializeStr(param), nil)
  25. return string(data), err
  26. }
  27. func GetSign(secureKey string, m map[string]interface{}) string {
  28. var signStr = fmt.Sprintf("app_id=%v&data=%v&req_id=%v&timestamp=%v%s", m["app_id"], m["data"], m["req_id"], m["timestamp"], secureKey)
  29. return fmt.Sprintf("%x", md5.Sum([]byte(signStr)))
  30. }