//用refresh_token刷新用户的access_token 服务器用定时来调用这个方法 (暂未优化)publicfunctionaccess_token_refresh(){//先查询所有授权的用户$tiktok_account=db('tiktok_account')->where('auth_status',1)->field('account_id,access_token_time')->select();foreach($tiktok_accountas$k=>$v){// month 月// day 天// hours 小时// seconds 秒// next 下一个 next month 下一个月// last 上一个 last day 上一天//现在的时间大于access_token_time时间的14天后更新acccess_token值 因为15天就过期了 但是好像不过期就不会刷新还得用15天if(time()>=strtotime("+15 day",$v['access_token_time'])){$account=db('tiktok_account')->where('account_id',$v['account_id'])->field('account_id,refresh_token')->find();//换取用户 acccess_token$get_access_token_url="https://open.douyin.com/oauth/refresh_token?client_key={$this::$dyClientKey}&grant_type=refresh_token&refresh_token={$account['refresh_token']}";$access_token_info=$this->getJson($get_access_token_url);$data=['access_token_time'=>time(),'access_token'=>$access_token_info['data']['access_token'],];db('tiktok_account')->where('account_id',$account['account_id'])->update($data);}}}//用refresh_token刷新用户本身的refresh_token 服务器用定时来调用这个方法 (暂未优化)publicfunctionrefresh_token_refresh(){$tiktok_account=db('tiktok_account')->where('auth_status',1)->field('account_id,refresh_token_time')->select();foreach($tiktok_accountas$k=>$v){// month 月// day 天// hours 小时// seconds 秒// next 下一个 next month 下一个月// last 上一个 last day 上一天//现在的时间大于refresh_token_time时间29天后更新refresh_token值 因为refresh_token一个月到期就不能用了if(time()>=strtotime("+29 day",$v['refresh_token_time'])){$account=db('tiktok_account')->where('account_id',$v['account_id'])->field('account_id,refresh_token')->find();//换取用户 acccess_token$get_refresh_token_url="https://open.douyin.com/oauth/renew_refresh_token?client_key={$this::$dyClientKey}&refresh_token={$account['refresh_token']}";$refresh_token_info=$this->getJson($get_refresh_token_url);dump($refresh_token_info);$data=['refresh_token_time'=>time(),'refresh_token'=>$refresh_token_info['data']['refresh_token'],];db('tiktok_account')->where('account_id',$account['account_id'])->update($data);}}}