$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".AppID."&secret=".AppSecret; $result = http_request($url); //Generate file, save token $dir = __DIR__; //The real path, the php execution of the crontab command is in cli mode, the relative path cannot be recognized correctly, so use __DIR__ $filename = $dir."/access_token.php"; create_file($filename, $result); function http_request($url,$data = null){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); if (!empty($data)){ curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output; } //generate file function create_file($filename, $content){ $fp = fopen($filename, "w"); fwrite($fp, "" . $content); fclose($fp); }