第三方api接口
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

60 行
1.5 KiB

  1. package hw
  2. import (
  3. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  4. "github.com/syyongx/php2go"
  5. "github.com/tidwall/gjson"
  6. "strings"
  7. )
  8. func HwSend(url string, param map[string]string, secret string) string {
  9. sign := getSign(param, secret)
  10. param["sign"] = sign
  11. for k, v := range param {
  12. if v == "" {
  13. continue
  14. }
  15. if strings.Contains(url, "?") == false {
  16. url += "?" + k + "=" + php2go.URLEncode(v)
  17. } else {
  18. url += "&" + k + "=" + php2go.URLEncode(v)
  19. }
  20. }
  21. return url
  22. }
  23. func HwSendOrder(url string, param map[string]string, secret string) (string, string) {
  24. sign := getSign(param, secret)
  25. param["sign"] = sign
  26. for k, v := range param {
  27. if v == "" {
  28. continue
  29. }
  30. if strings.Contains(url, "?") == false {
  31. url += "?" + k + "=" + php2go.URLEncode(v)
  32. } else {
  33. url += "&" + k + "=" + php2go.URLEncode(v)
  34. }
  35. }
  36. data, _ := zhios_third_party_utils.CurlGet(url, nil)
  37. list := gjson.Get(string(data), "data.list").String()
  38. if list == "" {
  39. list = gjson.Get(string(data), "data.order").String()
  40. }
  41. taskList := gjson.Get(string(data), "data.take_list").String()
  42. return list, taskList
  43. }
  44. func getSign(param map[string]string, secret string) string {
  45. strMap := zhios_third_party_utils.KsortToStr(param)
  46. str := ""
  47. for _, v := range strMap {
  48. if v == "sign" || param[v] == "" {
  49. continue
  50. }
  51. str += zhios_third_party_utils.UderscoreToUpperCamelCase(v) + "=" + param[v] + "&"
  52. }
  53. str += "secretKey=" + secret
  54. return strings.ToUpper(php2go.Md5(str))
  55. }