标签:his exist pre 签名 过期 sig sha nts fopen
/*判断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;
标签:his exist pre 签名 过期 sig sha nts fopen
原文地址:https://www.cnblogs.com/cnn2017/p/11369411.html