第三方api接口
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

62 linhas
1.8 KiB

  1. package kuaishou
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/comm"
  4. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  5. "fmt"
  6. "github.com/syyongx/php2go"
  7. "strings"
  8. "time"
  9. )
  10. func SendGet(method string, signSecret string, param map[string]string) (string, error) {
  11. url := "https://openapi.kwaixiaodian.com/" + strings.ReplaceAll(method, ".", "/")
  12. param["signMethod"] = "MD5"
  13. param["method"] = method
  14. param["version"] = "1"
  15. param["timestamp"] = zhios_third_party_utils.Int64ToStr(time.Now().UnixNano() / 1e6)
  16. param["sign"] = GetSign(param, signSecret)
  17. for k, v := range param {
  18. if strings.Contains(url, "?") {
  19. url += "&" + k + "=" + php2go.URLEncode(v)
  20. } else {
  21. url += "?" + k + "=" + php2go.URLEncode(v)
  22. }
  23. }
  24. get, err := zhios_third_party_utils.CurlGet(url, nil)
  25. fmt.Println(string(get))
  26. fmt.Println(url)
  27. fmt.Println(err)
  28. return string(get), err
  29. }
  30. func SendPost(method string, signSecret string, param map[string]string) (string, error) {
  31. url := "https://openapi.kwaixiaodian.com/" + strings.ReplaceAll(method, ".", "/")
  32. param["signMethod"] = "MD5"
  33. param["method"] = method
  34. param["sign"] = GetSign(param, signSecret)
  35. for k, v := range param {
  36. if strings.Contains(url, "?") {
  37. url += "&" + k + "=" + php2go.URLEncode(v)
  38. } else {
  39. url += "?" + k + "=" + php2go.URLEncode(v)
  40. }
  41. }
  42. get, err := zhios_third_party_utils.CurlPost(url, param["param"], nil)
  43. fmt.Println(string(get))
  44. fmt.Println(err)
  45. return string(get), err
  46. }
  47. func GetSign(param map[string]string, signSecret string) string {
  48. str := ""
  49. keys := comm.KsortToStr(param)
  50. for _, k := range keys {
  51. if str != "" {
  52. str += "&" + k + "=" + param[k]
  53. } else {
  54. str += k + "=" + param[k]
  55. }
  56. }
  57. str += "&signSecret=" + signSecret
  58. return php2go.Md5(str)
  59. }