第三方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 2.2 KiB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package jd_union
  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. "sort"
  6. "strings"
  7. "time"
  8. )
  9. func Send(keyArr map[string]string, method, paramJson, version string) (string, error) {
  10. args := map[string]interface{}{
  11. "method": method,
  12. "app_key": keyArr["app_key"],
  13. "timestamp": time.Now().Format("2006-01-02 15:04:05"),
  14. "format": "json",
  15. "v": version,
  16. "param_json": paramJson,
  17. "sign_method": "md5",
  18. }
  19. if keyArr["access_token"] != "" {
  20. args["access_token"] = keyArr["access_token"]
  21. }
  22. // 获取Key
  23. var keys []string
  24. for k := range args {
  25. keys = append(keys, k)
  26. }
  27. // 排序asc
  28. sort.Strings(keys)
  29. str := ""
  30. for _, v := range keys {
  31. if args[v] == "" {
  32. continue
  33. }
  34. str += v + zhios_third_party_utils.AnyToString(args[v])
  35. }
  36. args["sign"] = strings.ToUpper(php2go.Md5(keyArr["app_secret"] + str + keyArr["app_secret"]))
  37. url := "https://api.jd.com/routerjson"
  38. post, err := zhios_third_party_utils.CurlPost(url, args, nil)
  39. return string(post), err
  40. }
  41. func SendGet(keyArr map[string]string, method, paramJson, version string) (string, error) {
  42. args := map[string]interface{}{
  43. "method": method,
  44. "app_key": keyArr["app_key"],
  45. "timestamp": time.Now().Format("2006-01-02 15:04:05"),
  46. "format": "json",
  47. "v": version,
  48. "360buy_param_json": paramJson,
  49. "sign_method": "md5",
  50. }
  51. if keyArr["access_token"] != "" {
  52. args["access_token"] = keyArr["access_token"]
  53. }
  54. // 获取Key
  55. var keys []string
  56. for k := range args {
  57. keys = append(keys, k)
  58. }
  59. // 排序asc
  60. sort.Strings(keys)
  61. str := ""
  62. for _, v := range keys {
  63. if args[v] == "" {
  64. continue
  65. }
  66. str += v + zhios_third_party_utils.AnyToString(args[v])
  67. }
  68. args["sign"] = strings.ToUpper(php2go.Md5(keyArr["app_secret"] + str + keyArr["app_secret"]))
  69. url := "https://api.jd.com/routerjson"
  70. for k, v := range args {
  71. if strings.Contains(url, "?") == false {
  72. url += "?" + k + "=" + php2go.URLEncode(zhios_third_party_utils.AnyToString(v))
  73. } else {
  74. url += "&" + k + "=" + php2go.URLEncode(zhios_third_party_utils.AnyToString(v))
  75. }
  76. }
  77. post, err := zhios_third_party_utils.CurlGet(url, nil)
  78. return string(post), err
  79. }