首页 > 代码库 > php 抓取微信列表中的最新的一组微信消息

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

<?php 

$_G['wx_g'] = array('init' => array(	
				"wx_content" => array("weixin_user" => "微信号码", "weixin_pass" => "微信密码")
			)
);

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 => $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&count=2&t=media/appmsg_list&type=10&action=list&token=".$_G['wx_g']['token']."&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&count=2&t=media/appmsg_list&type=10&action=list&token=".$_G['wx_g']['token']."&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 = http://www.mamicode.com/',$output2);>
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 ;