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

46 regels
1.7 KiB

  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. "time"
  9. )
  10. func KuaishouAuth() {
  11. kuaishouAppkey := offical.MasterListCfgGetOneData("0", "kuaishou_kfx_appkey")
  12. kuaishouAppSecret := offical.MasterListCfgGetOneData("0", "kuaishou_kfx_app_secret")
  13. kuaishou_official_expires_in := db.MasterListCfgGetOneData("0", "kuaishou_official_expires_in")
  14. kuaishou_official_refresh_token := db.MasterListCfgGetOneData("0", "kuaishou_official_refresh_token")
  15. if utils.StrToInt64(kuaishou_official_expires_in) < time.Now().Unix() {
  16. args := map[string]string{
  17. "app_id": kuaishouAppkey,
  18. "grant_type": "refresh_token",
  19. "refresh_token": kuaishou_official_refresh_token,
  20. "app_secret": kuaishouAppSecret,
  21. }
  22. token, _ := kuaishou.GetKuaishouRefreshToken(args)
  23. if token == "" {
  24. return
  25. }
  26. accessToken := gjson.Get(token, "access_token").String()
  27. if accessToken == "" {
  28. return
  29. }
  30. teamAccessRefreshToken := gjson.Get(token, "refresh_token").String()
  31. teamAccessTime := time.Now().Unix() + gjson.Get(token, "expires_in").Int() - 60
  32. db.MasterListCfgSave("0", "kuaishou_official_access_token", accessToken)
  33. db.MasterListCfgSave("0", "kuaishou_official_expires_in", utils.Int64ToStr(teamAccessTime))
  34. db.MasterListCfgSave("0", "kuaishou_official_refresh_token", teamAccessRefreshToken)
  35. args1 := map[string]interface{}{
  36. "accessToken": accessToken,
  37. "teamAccessTime": utils.Int64ToStr(teamAccessTime),
  38. "teamAccessRefreshToken": teamAccessRefreshToken,
  39. }
  40. utils.CurlPost("http://izhim.com/?mod=api&act=kuaishou&ctrl=auth", args1, nil)
  41. }
  42. }