第三方api接口
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

api.go 2.7 KiB

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