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

api.go 1.5 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. }