智盟项目
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.

svc_kuaishou_auth.go 1.9 KiB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package svc
  2. import (
  3. "applet/app/db"
  4. offical "applet/app/db/official"
  5. "applet/app/utils"
  6. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/kuaishou"
  7. "github.com/tidwall/gjson"
  8. "strings"
  9. "time"
  10. )
  11. func KuaishouAuth() {
  12. kuaishouAppkey := offical.MasterListCfgGetOneData("0", "kuaishou_kfx_appkey")
  13. kuaishouAppSecret := offical.MasterListCfgGetOneData("0", "kuaishou_kfx_app_secret")
  14. kuaishou_official_expires_in := db.MasterListCfgGetOneData("0", "kuaishou_official_expires_in")
  15. kuaishou_official_refresh_token := db.MasterListCfgGetOneData("0", "kuaishou_official_refresh_token")
  16. if utils.StrToInt64(kuaishou_official_expires_in) < time.Now().Unix() {
  17. args := map[string]string{
  18. "app_id": kuaishouAppkey,
  19. "grant_type": "refresh_token",
  20. "refresh_token": kuaishou_official_refresh_token,
  21. "app_secret": kuaishouAppSecret,
  22. }
  23. token, _ := kuaishou.GetKuaishouRefreshToken(args)
  24. if token == "" {
  25. return
  26. }
  27. accessToken := gjson.Get(token, "access_token").String()
  28. if accessToken == "" {
  29. return
  30. }
  31. teamAccessRefreshToken := gjson.Get(token, "refresh_token").String()
  32. teamAccessTime := time.Now().Unix() + gjson.Get(token, "expires_in").Int() - 60
  33. db.MasterListCfgSave("0", "kuaishou_official_access_token", accessToken)
  34. db.MasterListCfgSave("0", "kuaishou_official_expires_in", utils.Int64ToStr(teamAccessTime))
  35. db.MasterListCfgSave("0", "kuaishou_official_refresh_token", teamAccessRefreshToken)
  36. url := "http://izhim.com/?mod=api&act=kuaishou&ctrl=auth"
  37. args1 := map[string]string{
  38. "accessToken": accessToken,
  39. "teamAccessTime": utils.Int64ToStr(teamAccessTime),
  40. "teamAccessRefreshToken": teamAccessRefreshToken,
  41. }
  42. for k, v := range args1 {
  43. if strings.Contains(url, "?") == false {
  44. url += "?" + k + "=" + v
  45. } else {
  46. url += "&" + k + "=" + v
  47. }
  48. }
  49. utils.CurlGet(url, nil)
  50. }
  51. }