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相关内容感兴趣的读者可查看本站专题:《php curl用法总结》、《php网络编程技巧总结》、《php数组(array)操作技巧大全》、《php字符串(string)用法总结》、《php数据结构与算法教程》及《php中json格式数据操作技巧汇总》
希望本文所述对大家php程序设计有所帮助。
上一篇: 终于了解了下.net 和 j2ee的区别
下一篇: jQuery 事件的命名空间简单了解