php判断token有效期
Posted cnn2017
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php判断token有效期相关的知识,希望对你有一定的参考价值。
/*判断token文件是否存在*/ if (file_exists("access_token.json")) $result = json_decode(file_get_contents("access_token.json"),true); //file_get_content()读取文件可以使用 //$fp = fopen($filename, ‘r‘) //$content = fread($fp, filesize($filename)); // fclose($fp); $token = $result[‘token‘]; else $result[‘token‘] = ‘‘; $result[‘expires_in‘] = ‘‘; /*判断token是否过期*/ if( $result[‘token‘] == ‘‘ || $result[‘expires_in‘] < time() ) $str = $this->AppID.$this->AppSecret.$this->SignKey; $Sign= MD5($str);/*签名*/ $data = array( ‘AppID‘ => $this->AppID, ‘AppSecret‘ => $this->AppSecret, ‘Sign‘ =>$Sign, ); $token_json = $this->http_request($this->tokeurl,$data); $token = json_decode($token_json,true)[‘token‘]; $reflesh = []; $reflesh[‘expires_in‘] = time()+3600; $reflesh[‘token‘] = $token; $fp = fopen("access_token.json", "w"); fwrite($fp, json_encode($reflesh)); fclose($fp); return $this->token =$token;
以上是关于php判断token有效期的主要内容,如果未能解决你的问题,请参考以下文章