第三方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.

58 lines
1.4 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 {
  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. return list
  42. }
  43. func getSign(param map[string]string, secret string) string {
  44. strMap := zhios_third_party_utils.KsortToStr(param)
  45. str := ""
  46. for _, v := range strMap {
  47. if v == "sign" || param[v] == "" {
  48. continue
  49. }
  50. str += zhios_third_party_utils.UderscoreToUpperCamelCase(v) + "=" + param[v] + "&"
  51. }
  52. str += "secretKey=" + secret
  53. return strings.ToUpper(php2go.Md5(str))
  54. }