這篇文章主要介紹PHP+fiddler是如何抓包采集微信文章的,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
創(chuàng)新互聯(lián)是專(zhuān)業(yè)的宿遷網(wǎng)站建設(shè)公司,宿遷接單;提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行宿遷網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!簡(jiǎn)介:
分析接口知道要獲取文章閱讀數(shù)和點(diǎn)贊數(shù)必須有key和uin這兩個(gè)關(guān)鍵參數(shù),不同公眾號(hào)key不一樣(據(jù)說(shuō)有萬(wàn)能微信key,不懂怎么搞到),同一個(gè)公眾號(hào)key大概半小時(shí)會(huì)過(guò)期
提交鏈接獲取文章閱讀量api
思路:
1.將客戶(hù)端請(qǐng)求閱讀量接口的請(qǐng)求攔截轉(zhuǎn)發(fā)到自己服務(wù)器,這樣就可以獲取到key ,用__biz關(guān)聯(lián)緩存半小時(shí)
2.提交文章鏈接進(jìn)行查詢(xún)時(shí),服務(wù)器從文章鏈接里獲取__biz,查詢(xún)是否緩存了當(dāng)前公眾號(hào)對(duì)應(yīng)的key,有的話(huà)進(jìn)行第3步,沒(méi)有進(jìn)行第4步。
3.curl請(qǐng)求https://mp.weixin.qq.com/mp/getappmsgext? 接口獲取數(shù)據(jù)
4.key不存在時(shí),通知客戶(hù)端重定向到該url(通知用websocket通知或者客戶(hù)端ajax輪詢(xún),需要用抓包工具修改文章詳情頁(yè)代碼讓其跳轉(zhuǎn)到中間頁(yè)面待命,打開(kāi)文章頁(yè)面后隔幾秒跳回中間頁(yè))并暫停程序幾秒等待客戶(hù)端更新key,此時(shí)客戶(hù)端提交了新的key,用其進(jìn)行查詢(xún)
實(shí)現(xiàn)
1.抓包
此接口就是獲取閱讀量的接口,參數(shù)如下圖
2.將此接口攔截轉(zhuǎn)發(fā)到自己服務(wù)器,點(diǎn)擊 rules- customize rules 在OnBeforeRequest(正式請(qǐng)求之前執(zhí)行的函數(shù))加上
if (oSession.fullUrl.Contains("mp.weixin.qq.com/mp/getappmsgext")) { oSession.oRequest["Host"]= 'ccc.aaa.com' ; }
效果,可以看到此接口已經(jīng)被轉(zhuǎn)發(fā)
3.服務(wù)端緩存key,代碼以PHP為例
public function saveKey(Request $request) { $__biz = $request->param('__biz',0); $data['uin'] = $request->param('uin',0); $data['key'] = $request->param('key',0); Cache::set($__biz,$data,30 * 60); return 'ok'; }
4.提交文章鏈接查詢(xún)API代碼
public function getReadNum(Request $request) { $url = $request->param('url'); parse_str(parse_url($url)['query'], $param); $__biz = $param['__biz']; $key_data = Cache::get($__biz); if (empty($key_data)) return 'no key'; $uin = $key_data['uin']; $key = $key_data['key']; $param['uin'] = $uin; $param['key'] = $key; $param['wxtoken'] = "777"; $wechat_url = "https://mp.weixin.qq.com/mp/getappmsgext?" . http_build_query($param); //dump($wechat_url); $data = array( 'is_only_read' => 1, 'is_temp_url' => 0, 'appmsg_type' => 9, ); $res = $this->get_url($wechat_url,$data); return $res; } function get_url($url,$data) { $ifpost = 1;//是否post請(qǐng)求 $datafields = $data;//post數(shù)據(jù) $cookiefile = '';//cookie文件 $cookie = '';//cookie變量 $v = false; //模擬http請(qǐng)求header頭 $header = array("Connection: Keep-Alive","Accept: text/html, application/xhtml+xml, */*", "Pragma: no-cache", "Accept-Language: zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.5,en;q=0.3","User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 QBCore/4.0.1278.400 QQBrowser/9.0.2524.400 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2875.116 Safari/537.36 NetType/WIFI MicroMessenger/7.0.5 WindowsWechat"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, $v); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); $ifpost && curl_setopt($ch, CURLOPT_POST, $ifpost); $ifpost && curl_setopt($ch, CURLOPT_POSTFIELDS, $datafields); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $cookie && curl_setopt($ch, CURLOPT_COOKIE, $cookie);//發(fā)送cookie變量 $cookiefile && curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);//發(fā)送cookie文件 $cookiefile && curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);//寫(xiě)入cookie到文件 curl_setopt($ch,CURLOPT_TIMEOUT,60); //允許執(zhí)行的最長(zhǎng)秒數(shù) curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $ok = curl_exec($ch); curl_close($ch); unset($ch); return $ok; }
5.通知客戶(hù)端重定向頁(yè)面(這部分沒(méi)寫(xiě),看參考我的其他關(guān)于文本socket文章)
6.用fiddler修改微信文章也jsj腳本,
在OnBeforeResponse(返回給客戶(hù)端之前執(zhí)行的方法),加上跳轉(zhuǎn)到中間頁(yè)的代碼
效果
以上是PHP+fiddler是如何抓包采集微信文章的的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!