$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, crontab command PHP execution in CLI mode, does not correctly identify the relative path, 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);}
Use PHP to get Access_token