首页  »   Access

PHP瀹氭椂浠诲姟鑾峰彇寰俏access_token

网友分享于:2013-10-25  浏览:1次
PHP瀹氭椂浠诲姟鑾峰彇寰俊access_token
鏈€杩戠敤php璇█http://www.maiziedu.com/course/php/寮€鍙戝井淇″叕浼楀钩鍙帮紝鍏紬鍙疯皟鐢ㄥ悇鎺ュ彛鏃堕兘闇€浣跨敤access_token锛宎ccess_token鏄叕浼楀彿鐨勫叏灞€鍞竴鎺ュ彛璋冪敤鍑嵁锛屽紑鍙戞椂闇€瑕佽繘琛屽Ε鍠勪繚瀛樸€?access_token鏈夋晥鏈熶负7200绉?锛岄噸澶嶈幏鍙栧皢瀵艰嚧涓婃鑾峰彇鐨刟ccess_token澶辨晥銆?
銆€銆€鐢变簬寰俊瀵硅幏鍙朼ccess_token鐨刟pi璋冪敤娆℃暟鍋氫簡闄愬埗锛屽缓璁紑鍙戣€呭叏灞€瀛樺偍涓庢洿鏂癮ccess_token锛岄绻佸埛鏂癮ccess_token浼氬鑷碼pi璋冪敤鍙楅檺锛屽奖鍝嶈嚜韬笟鍔°€?
銆€銆€閭d箞鏈変粈涔堝ソ鐨勮В鍐砤ccess_token瀛樺偍鍜屽埛鏂扮殑鍔炴硶鍛紵 鎴戠殑鍔炴硶鏄細璁″垝浠诲姟瀹氭椂鍒锋柊鑾峰彇access_token锛岀劧鍚庡皢access_token淇濆瓨鍒版湇鍔″櫒鏈湴锛屼繚瀛樻柟寮忓彲浠ユ槸鏂囦欢銆佹暟鎹簱鎴栫紦瀛樹腑銆?
銆€銆€涓嬮潰鎴戜娇鐢≒HP鏉ヨ幏鍙朼ccess_token锛屽苟淇濆瓨鍒版湰鍦版枃浠朵腑銆傚缓绔嬩竴涓猘ccess.php锛屼唬鐮佸涓嬶細
銆€銆€$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".AppID."&secret=".AppSecret;
銆€銆€$result = http_request($url);//鐢熸垚鏂囦欢锛屼繚瀛榯oken$dir = __DIR__; //鐪熷疄璺緞锛宑rontab鍛戒护鐨刾hp鎵ц鍦╟li妯″紡涓嬶紝涓嶈兘姝g‘璇嗗埆鐩稿璺緞锛屾墍浠ヤ娇鐢╛_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;
銆€銆€}
銆€銆€//鐢熸垚鏂囦欢function create_file($filename, $content){
銆€銆€$fp = fopen($filename, "w");
銆€銆€fwrite($fp, "
銆€銆€" . $content);
銆€銆€fclose($fp);
銆€銆€}
銆€銆€浠ヤ笂浠g爜涓瑼ppID鍜孉ppSecret杩欎袱涓父閲忔槸鐢卞井淇″叕浼楀钩鍙版彁渚涳紝鍙互鐧诲綍鍒板井淇″叕浼楀钩鍙扮殑鍩烘湰閰嶇疆閲岃幏鍙栥€傝幏鍙栧埌鐨刟ccess_token琚繚瀛樺埌鏂囦欢access_token.php涓紝娉ㄦ剰杩欎釜鏂囦欢鍐呭涓嶈琚敤鎴疯闂埌銆?
銆€銆€鎺ヤ笅鏉ワ紝鎴戜滑璁剧疆瀹氭椂浠诲姟锛屾垜浠互Linux鐨凜entOS涓轰緥锛屼娇鐢╟rontab璁剧疆璁″垝浠诲姟銆?
銆€銆€5 * * * * /usr/local/bin/php -f /home/web/access.php >> /dev/null 2>&1
銆€銆€浠ヤ笂鍛戒护璁剧疆浜嗘瘡闅?灏忔椂锛屽嵆姣忓皬鏃剁殑绗?5鍒嗛挓鎵цaccess.php銆?
杩欐牱锛屾垜浠氨鍙互淇濊瘉access_token鐨勬甯歌幏鍙栧拰浣跨敤锛屼笉鐢ㄩ绻佺殑鍘诲埛鏂板井淇℃湇鍔″櫒浜嗐€?

鏂囩珷鏉ユ簮锛欻elloweba

相关解决方案

最新解决方案