Php captures the latest group of messages in the list.
Array ("wx_content" => array ("weixin_user" => "number", "weixin_pass" => "password"); 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, success, false); curl_setopt ($ ch, success, 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. "& pwd = ". $ pwd. "& imgcode = & f = json"; $ cookie = "pgv_pvid = 2067516646"; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url ); curl_setopt ($ ch, CURLOPT_HEADER, 1); curl_setopt ($ ch, batch, 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&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", $ 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} & step = import & pswerror = 1", 'error '); // write to the global variable $ _ G ['wx _ G'] ['cookies'] = $ cookie; $ _ G ['wx _ G'] ['token'] = $ token;}?>
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 ;