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

84 lines
2.3 KiB

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