在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
/** * 获取accesstoken * * @param int $id * @return \think\Response */ public function AccessToken($appid) { //获取url $file = $this->accesstoken_url; if(!file_exists($file)){ $token = $this->get_accesstoken($appid); }else{ $fileInfo = explode(",",file_get_contents($file)); if(!empty(trim($fileInfo[0])) && $fileInfo[1] >= time()){ $token = $fileInfo[0]; }else{ $token = $this->get_accesstoken($appid); } } return $token; } /** * 获取token */ private function get_accesstoken($appid) { $data = [ "grant_type"=>"client_credential", "appid"=>$appid, "secret"=>$this->AppSecret ]; $url = $this->url_token; $tokeninfo = $this->jsonDecode(https_request($url,$data),"access_token"); if($tokeninfo){ $text = $tokeninfo.",".(time()+7000); //写入文件中 $file = $this->accesstoken_url; if(!file_exists($file)){ fopen($file,"wb"); } //把值存入文件中 $myfile = fopen($file,"w"); fwrite($myfile, $text);//写入文件 fclose($myfile);//关闭文件 } return $tokeninfo; } /** * json数据处理 */ private function jsonDecode($data,$key) { $new_data = json_decode($data,true); if(array_key_exists($key,$new_data)){ return $new_data[$key]; } return $data; }
|
2022-08-18
2022-08-15
2022-08-17
2022-11-06
2022-08-17
请发表评论