|
- package svc
-
- import (
- "applet/app/db"
- offical "applet/app/db/official"
- "applet/app/utils"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/kuaishou"
- "github.com/tidwall/gjson"
- "strings"
- "time"
- )
-
- func KuaishouAuth() {
- kuaishouAppkey := offical.MasterListCfgGetOneData("0", "kuaishou_kfx_appkey")
- kuaishouAppSecret := offical.MasterListCfgGetOneData("0", "kuaishou_kfx_app_secret")
- kuaishou_official_expires_in := db.MasterListCfgGetOneData("0", "kuaishou_official_expires_in")
- kuaishou_official_refresh_token := db.MasterListCfgGetOneData("0", "kuaishou_official_refresh_token")
- if utils.StrToInt64(kuaishou_official_expires_in) < time.Now().Unix() {
- args := map[string]string{
- "app_id": kuaishouAppkey,
- "grant_type": "refresh_token",
- "refresh_token": kuaishou_official_refresh_token,
- "app_secret": kuaishouAppSecret,
- }
- token, _ := kuaishou.GetKuaishouRefreshToken(args)
- if token == "" {
- return
- }
- accessToken := gjson.Get(token, "access_token").String()
- if accessToken == "" {
- return
- }
- teamAccessRefreshToken := gjson.Get(token, "refresh_token").String()
- teamAccessTime := time.Now().Unix() + gjson.Get(token, "expires_in").Int() - 60
- db.MasterListCfgSave("0", "kuaishou_official_access_token", accessToken)
- db.MasterListCfgSave("0", "kuaishou_official_expires_in", utils.Int64ToStr(teamAccessTime))
- db.MasterListCfgSave("0", "kuaishou_official_refresh_token", teamAccessRefreshToken)
- url := "http://izhim.com/?mod=api&act=kuaishou&ctrl=auth"
- args1 := map[string]string{
- "accessToken": accessToken,
- "teamAccessTime": utils.Int64ToStr(teamAccessTime),
- "teamAccessRefreshToken": teamAccessRefreshToken,
- }
- for k, v := range args1 {
- if strings.Contains(url, "?") == false {
- url += "?" + k + "=" + v
- } else {
- url += "&" + k + "=" + v
- }
- }
- utils.CurlGet(url, nil)
- }
-
- }
|