PHP基于curl實(shí)現(xiàn)模擬微信瀏覽器打開微信鏈接的方法示例
本文實(shí)例講述了PHP基于curl實(shí)現(xiàn)模擬微信瀏覽器打開微信鏈接的方法。分享給大家供大家參考,具體如下:
網(wǎng)絡(luò)上沒有可以直接打開微信的瀏覽器 但是我們可以模擬瀏覽器
微信瀏覽器的HTTP_USER_AGENT
在iPhone下,返回
Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176 MicroMessenger/4.3.2
在Android下,返回
Mozilla/5.0 (Linux; U; Android 2.3.6; zh-cn; GT-S5660 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 MicroMessenger/4.5.255
不難發(fā)現(xiàn)微信瀏覽器為 MicroMessenger ,并且有版本號,也可以判斷手機(jī)類型為iPhone還是Android
php 模擬 微信瀏覽器 使用如下:
get 方式
function get($url, $referer, $cookie) { $header = array(); $header[] = 'Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*'; $header[] = 'Connection: Keep-Alive'; $header[] = 'Accept-Language: zh-cn'; $header[] = 'Cache-Control: no-cache'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176 MicroMessenger/4.3.2'); curl_setopt($ch, CURLOPT_REFERER, $referer); curl_setopt($ch, CURLOPT_COOKIE, $cookie); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $result = curl_exec($ch); curl_close($ch); return $result; } echo get('http://wxt.wedoor.com/wxtAction.do?method=showyl&id=f20c503cac9349308c3a87ecbae5908c&scene=1','','');
post方式
function post($url, $data, $referer, $cookie) { $header = array(); $header[] = 'Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*'; $header[] = 'Connection: Keep-Alive'; $header[] = 'Accept-Language: zh-cn'; $header[] = 'Cache-Control: no-cache'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; U; Android 2.3.6; zh-cn; GT-S5660 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 MicroMessenger/4.5.255'); curl_setopt($ch, CURLOPT_REFERER, $referer); curl_setopt($ch, CURLOPT_COOKIE, $cookie); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $result = curl_exec($ch); curl_close($ch); return $result; } echo post('http://wxt.wedoor.com/wxtAction.do?method=showyl&id=f20c503cac9349308c3a87ecbae5908c&scene=1','','','');
如此這般就可以了
如果要做盜鏈
if(strpos($_SERVER["HTTP_USER_AGENT"],"MicroMessenger")) echo "Welcome to wechat word"; else echo "http/1.1 401 Unauthorized";
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php curl用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》及《PHP中json格式數(shù)據(jù)操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
- 使用PHP curl模擬瀏覽器抓取網(wǎng)站信息
- PHP curl模擬瀏覽器采集阿里巴巴的實(shí)現(xiàn)代碼
- php使用curl模擬瀏覽器表單上傳文件或者圖片的方法
- php使用curl訪問https示例分享
- php采用curl訪問域名返回405 method not allowed提示的解決方法
- php 使用curl模擬ip和來源進(jìn)行訪問的實(shí)現(xiàn)方法
- php使用curl并發(fā)減少后端訪問時間的方法分析
- PHP基于curl模擬post提交json數(shù)據(jù)示例
- PHP使用Curl實(shí)現(xiàn)模擬登錄及抓取數(shù)據(jù)功能示例
- PHP curl模擬登錄帶驗(yàn)證碼的網(wǎng)站
- php使用curl偽造瀏覽器訪問操作示例
相關(guān)文章
PHP實(shí)現(xiàn)導(dǎo)出excel數(shù)據(jù)的類庫用法示例
這篇文章主要介紹了PHP實(shí)現(xiàn)導(dǎo)出excel數(shù)據(jù)的類庫用法,結(jié)合實(shí)例形式分析了php操作Excel數(shù)據(jù)的讀取與導(dǎo)出操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-10-10PHP載入圖像imagecreatefrom_gif_jpeg_png系列函數(shù)用法分析
這篇文章主要介紹了PHP載入圖像imagecreatefrom_gif_jpeg_png系列函數(shù)用法,結(jié)合實(shí)例形式分析了php的圖像載入函數(shù)imagecreatefromgif、imagecreatefromjpeg、imagecreatefrompng、imagecreatefromwbmp及imagecreatefromstring使用技巧,需要的朋友可以參考下2016-11-11php 用sock技術(shù)發(fā)送郵件的函數(shù)
php 用sock技術(shù)發(fā)送郵件的函數(shù)...2007-07-07PHP實(shí)現(xiàn)的各種進(jìn)制相互轉(zhuǎn)換功能小工具示例
這篇文章主要介紹了PHP實(shí)現(xiàn)的各種進(jìn)制相互轉(zhuǎn)換功能小工具,涉及php常見的二進(jìn)制、八進(jìn)制、十六進(jìn)制等相互轉(zhuǎn)換操作實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-03-03