您好,登錄后才能下訂單哦!
小編給大家分享一下PHP基于curl如何實現模擬微信瀏覽器打開微信鏈接,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
本文實例講述了PHP基于curl實現模擬微信瀏覽器打開微信鏈接的方法。分享給大家供大家參考,具體如下:
網絡上沒有可以直接打開微信的瀏覽器 但是我們可以模擬瀏覽器
微信瀏覽器的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
不難發現微信瀏覽器為 MicroMessenger ,并且有版本號,也可以判斷手機類型為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";
以上是“PHP基于curl如何實現模擬微信瀏覽器打開微信鏈接”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。