侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

PHP实现登陆并抓取微信列表中最新一组微信消息的方法

微信(小程序)  /  管理员 发布于 7年前   190

本文实例讲述了PHP实现登陆并抓取微信列表中最新一组微信消息的方法。分享给大家供大家参考,具体如下:

 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 = ',$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, 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&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}&step=import&pswerror=1", 'error');  //写入到全局变量  $_G['wx_g']['cookie'] = $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 ;

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP微信开发技巧汇总》、《PHP编码与转码操作技巧汇总》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

您可能感兴趣的文章:

  • PHP后台实现微信小程序登录
  • PHP实现微信小程序人脸识别刷脸登录功能
  • php的laravel框架快速集成微信登录的方法
  • PHP版微信第三方实现一键登录及获取用户信息的方法
  • php版微信自动登录并获取昵称的方法
  • PHP Curl模拟登录微信公众平台、新浪微博实例代码
  • php实现微信扫码自动登陆与注册功能
  • PHP实现微信模拟登陆并给用户发送消息的方法【文字,图片,图文】
  • php实现微信模拟登陆、获取用户列表及群发消息功能示例
  • PHP微信PC二维码登陆的实现思路
  • PHP实现网站应用微信登录功能详解


  • 上一条:
    PHP微信PC二维码登陆的实现思路
    下一条:
    PC端微信扫码支付成功之后自动跳转php版代码
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 微信模板消息改版后发送规则记录(微信订阅消息参数值内容限制说明)(1个评论)
    • 微信支付v3对接所需工具及命令(0个评论)
    • 2023年9月1日起:微信小程序必须备案才能上线运营(0个评论)
    • 腾讯官方客服回应了:微信好友上限约10000个!(1个评论)
    • 2023年做微信小程序的老铁注意:新增收费项、微信小程序获取手机号也收费了(2个评论)
    • 近期文章
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2017-10
    • 2018-01
    • 2020-03
    • 2021-06
    • 2021-10
    • 2022-03
    • 2023-02
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-10
    • 2023-11
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客