首頁 後端開發 php教程 php 抓取微信列表中的最新的一组微信消息

php 抓取微信列表中的最新的一组微信消息

Jun 23, 2016 pm 01:51 PM
php 清單 抓取 最新 訊息

<?php $_G['wx_g'] = array('init' => array(					"wx_content" =&gt; array("weixin_user" =&gt; "微信号码", "weixin_pass" =&gt; "微信密码")			));wx_login();$messge_list = get_message_list();$file_id=$messge_list['item'][0]['multi_item'][0]['file_id'];//print_r($messge_list);exit;if(!DB::result_first("select count(weiyi_id) from test.yangang_jiaojing where weiyi_id={$file_id} ")){	DB::query("delete from  test.yangang_jiaojing");	foreach ($messge_list['item'][0]['multi_item'] as $key =&gt; $val){			$val['title']=mb_convert_encoding($val['title'], 'GBK','UTF-8');			$val['weiyi_id']=mb_convert_encoding($val['file_id'], 'GBK','UTF-8');			$val['des']=mb_convert_encoding($val['digest'], 'GBK','UTF-8');			$val['picurl']=$val['cover'];			$val['detail']=$val['content_url'];			$query_cheng = "INSERT INTO test.yangang_jiaojing(weiyi_id,title,pic_url,detail_url,des)VALUES ({$val['weiyi_id']},'{$val['title']}','{$val['picurl']}','{$val['detail']}','{$val['des']}')";			$count1=DB::query($query_cheng);	}}function get_message_list(){		global $_G;		$cookie=$_G['wx_g']['cookie'];		$url = "https://mp.weixin.qq.com/cgi-bin/appmsg?begin=0&amp;count=2&amp;t=media/appmsg_list&amp;type=10&amp;action=list&amp;token=".$_G['wx_g']['token']."&amp;lang=zh_CN";	$ch = curl_init();		curl_setopt($ch, CURLOPT_URL, $url);	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);	curl_setopt($ch, CURLOPT_COOKIE, $cookie);	curl_setopt($ch, CURLOPT_REFERER, "https://mp.weixin.qq.com/cgi-bin/appmsg?begin=0&amp;count=2&amp;t=media/appmsg_list&amp;type=10&amp;action=list&amp;token=".$_G['wx_g']['token']."&amp;lang=zh_CN");	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:18.0) Gecko/20100101 Firefox/18.0");	curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);	curl_setopt($ch, CURLOPT_SSLVERSION, 3);	$output2 = curl_exec($ch);	curl_close($ch);	//echo $output2;exit;	$output1=explode('wx.cgiData = ',$output2);	$output1=$output1[1];	$output1=explode(',"file_cnt":',$output1);	$output1=$output1[0];	$output1.='}';	$message_list=json_decode($output1,true);	//$message_list=mb_convert_encoding($message_list, "GBK","UTF-8");	//print_r($message_list);exit;		return $message_list;	}function wx_login(){		global $_G;	//echo $_G['wx_g']['init']['wx_content']['weixin_user'];exit;	$username = $_G['wx_g']['init']['wx_content']['weixin_user'];	$pwd = md5($_G['wx_g']['init']['wx_content']['weixin_pass']);		$url = "https://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN";	$post_data = "username=".$username."&amp;pwd=".$pwd."&amp;imgcode=&amp;f=json";	$cookie = "pgv_pvid=2067516646";	$ch = curl_init();	curl_setopt($ch, CURLOPT_URL, $url);	curl_setopt($ch, CURLOPT_HEADER, 1);	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);	curl_setopt($ch, CURLOPT_POST, 1);	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);	curl_setopt($ch, CURLOPT_COOKIE, $cookie);	curl_setopt($ch, CURLOPT_REFERER, "https://mp.weixin.qq.com/cgi-bin/loginpage?t=wxm2-login&amp;lang=zh_CN");	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:18.0) Gecko/20100101 Firefox/18.0");	curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);	curl_setopt($ch, CURLOPT_SSLVERSION, 3);	$output = curl_exec($ch);	curl_close($ch);	//echo $output;exit;		list($header, $body) = explode("\r\n\r\n", $output);		preg_match_all("/set\-cookie:([^\r\n]*)/i", $header, $matches);		if(!empty($matches[1][2])){		$cookie = $matches[1][0].$matches[1][1].$matches[1][2].$matches[1][3];	}else{		$cookie = $matches[1][0].$matches[1][1];	}		$cookie = str_replace(array('Path=/',' ; Secure; HttpOnly','=;'),array('','','='), $cookie);	$cookie = 'pgv_pvid=6648492946;'.$cookie;		$data = json_decode($body,true);	$result = explode('token=',$data['redirect_url']);	$token = $result[1];	if(!$token) cpmsg($installlang['import_error_password'], "{$request_url}&amp;step=import&amp;pswerror=1", 'error');			//写入到全局变量	$_G['wx_g']['cookie'] = $cookie;	$_G['wx_g']['token'] = $token;	}?&gt;
登入後複製

CREATE TABLE IF NOT EXISTS `yangang_jiaojing` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `title` varchar(100) NOT NULL,  `des` varchar(300) NOT NULL,  `detail_url` varchar(300) NOT NULL,  `pic_url` varchar(300) NOT NULL,  `note` varchar(50) NOT NULL,  `weiyi_id` int(11) NOT NULL,  PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ; 
登入後複製




本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱門文章

倉庫:如何復興隊友
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章

倉庫:如何復興隊友
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章標籤

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

適用於 Ubuntu 和 Debian 的 PHP 8.4 安裝和升級指南 適用於 Ubuntu 和 Debian 的 PHP 8.4 安裝和升級指南 Dec 24, 2024 pm 04:42 PM

適用於 Ubuntu 和 Debian 的 PHP 8.4 安裝和升級指南

CakePHP 日期和時間 CakePHP 日期和時間 Sep 10, 2024 pm 05:27 PM

CakePHP 日期和時間

CakePHP 檔案上傳 CakePHP 檔案上傳 Sep 10, 2024 pm 05:27 PM

CakePHP 檔案上傳

CakePHP 路由 CakePHP 路由 Sep 10, 2024 pm 05:25 PM

CakePHP 路由

CakePHP 專案配置 CakePHP 專案配置 Sep 10, 2024 pm 05:25 PM

CakePHP 專案配置

討論 CakePHP 討論 CakePHP Sep 10, 2024 pm 05:28 PM

討論 CakePHP

CakePHP 快速指南 CakePHP 快速指南 Sep 10, 2024 pm 05:27 PM

CakePHP 快速指南

如何設定 Visual Studio Code (VS Code) 進行 PHP 開發 如何設定 Visual Studio Code (VS Code) 進行 PHP 開發 Dec 20, 2024 am 11:31 AM

如何設定 Visual Studio Code (VS Code) 進行 PHP 開發

See all articles