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

96 lines
2.7 KiB

  1. package tik_tok
  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. "crypto/hmac"
  6. "crypto/sha256"
  7. "encoding/hex"
  8. "fmt"
  9. "github.com/syyongx/php2go"
  10. "strings"
  11. "time"
  12. )
  13. func Send(appkey, appSecret, method string, params map[string]interface{}, acctoken string) (string, error) {
  14. methodPath := strings.ReplaceAll(method, ".", "/")
  15. url := "https://openapi-fxg.jinritemai.com/" + methodPath
  16. paramJson := comm.GetSortJson(params)
  17. paramJson = strings.ReplaceAll(paramJson, "\n", "")
  18. param := map[string]string{
  19. "app_key": appkey,
  20. "method": method,
  21. "param_json": paramJson,
  22. "timestamp": time.Now().Format("2006-01-02 15:04:05"),
  23. "v": "2",
  24. }
  25. sign := GetSign(appSecret, param)
  26. if acctoken != "" {
  27. param["access_token"] = acctoken
  28. }
  29. param["sign"] = sign
  30. param["sign_method"] = "hmac-sha256"
  31. for k, v := range param {
  32. if strings.Contains(url, "?") {
  33. url += "&" + k + "=" + php2go.URLEncode(v)
  34. } else {
  35. url += "?" + k + "=" + php2go.URLEncode(v)
  36. }
  37. }
  38. fmt.Println(url)
  39. fmt.Println(paramJson)
  40. data, err := zhios_third_party_utils.CurlPost(url, paramJson, nil)
  41. return string(data), err
  42. }
  43. func GetSign(appSecret string, param map[string]string) string {
  44. str := ""
  45. keys := comm.KsortToStr(param)
  46. for _, k := range keys {
  47. str += k + param[k]
  48. }
  49. signStr := appSecret + str + appSecret
  50. h := hmac.New(sha256.New, []byte(appSecret))
  51. _, _ = h.Write([]byte(signStr))
  52. return hex.EncodeToString(h.Sum(nil))
  53. }
  54. func OpenSend(appkey, appSecret, method string, params map[string]string, acctoken string) (string, error) {
  55. url := "https://open.douyin.com/" + method + "/"
  56. param := map[string]string{
  57. "client_key": appkey,
  58. "client_secret": appSecret,
  59. }
  60. if acctoken != "" {
  61. param["access_token"] = acctoken
  62. }
  63. for k, v := range params {
  64. param[k] = v
  65. }
  66. data, err := zhios_third_party_utils.CurlPost(url, param, nil)
  67. return string(data), err
  68. }
  69. func OpenSendApi(method string, params map[string]interface{}, acctoken string) (string, error) {
  70. url := "https://open.douyinec.com/" + method
  71. param := params
  72. headers := map[string]string{
  73. "Content-Type": "application/json",
  74. }
  75. if acctoken != "" {
  76. headers["access-token"] = acctoken
  77. }
  78. paramStr := zhios_third_party_utils.SerializeStr(param)
  79. data, err := zhios_third_party_utils.CurlPost(url, paramStr, headers)
  80. return string(data), err
  81. }
  82. func OpenSendApiGet(method string, acctoken string) (string, error) {
  83. url := "https://open.douyin.com/" + method
  84. headers := map[string]string{
  85. "Content-Type": "application/json",
  86. }
  87. if acctoken != "" {
  88. headers["access-token"] = acctoken
  89. }
  90. data, err := zhios_third_party_utils.CurlGet(url, headers)
  91. return string(data), err
  92. }