[微信公众号]php版模拟登录,向指定用户推送消息目前
[微信公众号]php版模拟登录,向指定用户推送消息
目前微信公众号没有开放推送接口。模拟登录即模拟用户登录,可以查看用户消息,回复消息等。微信官方未表态是否禁止,大量使用可能会导致封号等,谨慎使用!
以下代码由网络搜集,找不到原文,暂时不贴出处。
模拟登录代码:
<code><span><span><?php </span><span>/* 调用方式简单说明: $arr = array( 'account' => '公众平台帐号', 'password' => '密码' ); $postMsg = new postMsg($arr); $postMsg->getAllUserInfo();//获取所有用户信息 $postMsg->getUserInfo($groupid, $fakeid);//获取所有用户信息,如果默认分组,则$groupid传0 $postMsg->sendMessage('群发内容'); //群发给所有用户 $postMsg->sendMessage('群发内容',$userId); //群发给特定用户,这里的$userId就是用户的fakeid,数组方式传递 */</span><span><span>class</span><span>postMsg</span> {</span><span>public</span><span>$userFakeid</span>;<span>//所有粉丝的fakeid</span><span>private</span><span>$_account</span>;<span>//用户名</span><span>private</span><span>$_password</span>;<span>//密码</span><span>private</span><span>$url</span>;<span>//请求的网址</span><span>private</span><span>$send_data</span>;<span>//提交的数据</span><span>private</span><span>$getHeader</span> = <span>0</span>;<span>//是否显示Header信息</span><span>private</span><span>$token</span>;<span>//公共帐号TOKEN</span><span>private</span><span>$host</span> = <span>'mp.weixin.qq.com'</span>;<span>//主机</span><span>private</span><span>$origin</span> = <span>'https://mp.weixin.qq.com'</span>; <span>private</span><span>$referer</span>;<span>//引用地址</span><span>private</span><span>$cookie</span>; <span>private</span><span>$pageSize</span> = <span>100000</span>;<span>//每页用户数(用于读取所有用户)</span><span>private</span><span>$userAgent</span> = <span>'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'</span>; <span>public</span><span><span>function</span><span>__construct</span><span>(<span>$options</span>)</span>{</span><span>$this</span>->_account = <span>isset</span>(<span>$options</span>[<span>'account'</span>])?<span>$options</span>[<span>'account'</span>]:<span>''</span>; <span>$this</span>->_password = <span>isset</span>(<span>$options</span>[<span>'password'</span>])?<span>$options</span>[<span>'password'</span>]:<span>''</span>; <span>$this</span>->login(); } <span>//登录</span><span>private</span><span><span>function</span><span>login</span><span>()</span>{</span><span>$url</span> = <span>'https://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN'</span>; <span>$this</span>->send_data = <span>array</span>( <span>'username'</span> => <span>$this</span>->_account, <span>'pwd'</span> => md5(<span>$this</span>->_password), <span>'f'</span> => <span>'json'</span> ); <span>$this</span>->referer = <span>"https://mp.weixin.qq.com/"</span>; <span>$this</span>->getHeader = <span>1</span>; <span>$result</span> = explode(<span>"\n"</span>,<span>$this</span>->curlPost(<span>$url</span>)); <span>echo</span><span>'result'</span>; <span>echo</span><span>$result</span>; <span>foreach</span> (<span>$result</span><span>as</span><span>$key</span> => <span>$value</span>) { <span>$value</span> = trim(<span>$value</span>); <span>if</span> (preg_match(<span>'/token=(\d+)/i'</span>, <span>$value</span>,<span>$match</span>)) { <span>//获取token</span><span>$this</span>->token = trim(<span>$match</span>[<span>1</span>]); } <span>if</span> (preg_match(<span>'/"ret":(.*)/i'</span>, <span>$value</span>,<span>$match</span>)){<span>//获取token</span><span>switch</span> (<span>$match</span>[<span>1</span>]) { <span>case</span> -<span>1</span>: <span>die</span>(json_encode(<span>array</span>(<span>'status'</span>=><span>1</span>,<span>'errCode'</span>=><span>$match</span>[<span>1</span>],<span>'msg'</span>=><span>"系统错误"</span>))); <span>case</span> -<span>2</span>: <span>die</span>(json_encode(<span>array</span>(<span>'status'</span>=><span>1</span>,<span>'errCode'</span>=><span>$match</span>[<span>1</span>],<span>'msg'</span>=><span>"帐号或密码错误"</span>))); <span>case</span> -<span>3</span>: <span>die</span>(urldecode(json_encode(<span>array</span>(<span>'status'</span>=><span>1</span>,<span>'errCode'</span>=><span>$match</span>[<span>1</span>],<span>'msg'</span>=>urlencode(<span>"密码错误"</span>))))); <span>case</span> -<span>4</span>: <span>die</span>(json_encode(<span>array</span>(<span>'status'</span>=><span>1</span>,<span>'errCode'</span>=><span>$match</span>[<span>1</span>],<span>'msg'</span>=><span>"不存在该帐户"</span>))); <span>case</span> -<span>5</span>: <span>die</span>(json_encode(<span>array</span>(<span>'status'</span>=><span>1</span>,<span>'errCode'</span>=><span>$match</span>[<span>1</span>],<span>'msg'</span>=><span>"访问受限"</span>))); <span>case</span> -<span>6</span>: <span>die</span>(json_encode(<span>array</span>(<span>'status'</span>=><span>1</span>,<span>'errCode'</span>=><span>$match</span>[<span>1</span>],<span>'msg'</span>=><span>"需要输入验证码"</span>))); <span>case</span> -<span>7</span>: <span>die</span>(json_encode(<span>array</span>(<span>'status'</span>=><span>1</span>,<span>'errCode'</span>=><span>$match</span>[<span>1</span>],<span>'msg'</span>=><span>"此帐号已绑定私人微信号,不可用于公众平台登录"</span>))); <span>case</span> -<span>8</span>: <span>die</span>(json_encode(<span>array</span>(<span>'status'</span>=><span>1</span>,<span>'errCode'</span>=><span>$match</span>[<span>1</span>],<span>'msg'</span>=><span>"邮箱已存在"</span>))); <span>case</span> -<span>32</span>: <span>die</span>(json_encode(<span>array</span>(<span>'status'</span>=><span>1</span>,<span>'errCode'</span>=><span>$match</span>[<span>1</span>],<span>'msg'</span>=><span>"验证码输入错误"</span>))); <span>case</span> -<span>200</span>: <span>die</span>(json_encode(<span>array</span>(<span>'status'</span>=><span>1</span>,<span>'errCode'</span>=><span>$match</span>[<span>1</span>],<span>'msg'</span>=><span>"因频繁提交虚假资料,该帐号被拒绝登录"</span>))); <span>case</span> -<span>94</span>: <span>die</span>(json_encode(<span>array</span>(<span>'status'</span>=><span>1</span>,<span>'errCode'</span>=><span>$match</span>[<span>1</span>],<span>'msg'</span>=><span>"请使用邮箱登陆"</span>))); <span>case</span><span>10</span>: <span>die</span>(json_encode(<span>array</span>(<span>'status'</span>=><span>1</span>,<span>'errCode'</span>=><span>$match</span>[<span>1</span>],<span>'msg'</span>=><span>"该公众会议号已经过期,无法再登录使用"</span>))); <span>case</span><span>0</span>: <span>$this</span>->userFakeid = <span>$this</span>->getUserFakeid(); <span>break</span>; } } <span>if</span>(preg_match(<span>'/^set-cookie:[\s]+([^=]+)=([^;]+)/i'</span>, <span>$value</span>,<span>$match</span>)){<span>//获取cookie</span><span>$this</span>->cookie .=<span>$match</span>[<span>1</span>].<span>'='</span>.<span>$match</span>[<span>2</span>].<span>'; '</span>; } } } <span>//单发消息</span><span>private</span><span><span>function</span><span>send</span><span>(<span>$fakeid</span>,<span>$content</span>)</span>{</span><span>$url</span> = <span>'https://mp.weixin.qq.com/cgi-bin/singlesend?t=ajax-response&lang=zh_CN'</span>; <span>$this</span>->send_data = <span>array</span>( <span>'type'</span> => <span>1</span>, <span>'f'</span> => <span>'json'</span>, <span>'action'</span> => <span>'sync'</span>, <span>'content'</span> => <span>$content</span>, <span>'tofakeid'</span> => <span>$fakeid</span>, <span>'token'</span> => <span>$this</span>->token, <span>'ajax'</span> => <span>1</span>, ); <span>$this</span>->referer = <span>'https://mp.weixin.qq.com/cgi-bin/singlemsgpage?token='</span>.<span>$this</span>->token.<span>'&fromfakeid='</span>.<span>$fakeid</span>.<span>'&msgid=&source=&count=20&t=wxm-singlechat&lang=zh_CN'</span>; <span>return</span><span>$this</span>->curlPost(<span>$url</span>); } <span>//群发消息</span><span>public</span><span><span>function</span><span>sendMessage</span><span>(<span>$content</span>=<span>''</span>,<span>$userId</span>=<span>''</span>)</span> {</span><span>if</span>(is_array(<span>$userId</span>) && !<span>empty</span>(<span>$userId</span>)){ <span>foreach</span>(<span>$userId</span><span>as</span><span>$v</span>){ <span>$json</span> = json_decode(<span>$this</span>->send(<span>$v</span>,<span>$content</span>)); <span>if</span>(<span>$json</span>->ret!=<span>0</span>){ <span>$errUser</span>[] = <span>$v</span>; } } }<span>else</span>{ <span>foreach</span>(<span>$this</span>->userFakeid <span>as</span><span>$v</span>){ <span>$json</span> = json_decode(<span>$this</span>->send(<span>$v</span>[<span>'fakeid'</span>],<span>$content</span>)); <span>if</span>(<span>$json</span>->ret!=<span>0</span>){ <span>$errUser</span>[] = <span>$v</span>[<span>'fakeid'</span>]; } } } <span>//共发送用户数</span><span>$count</span> = count(<span>$this</span>->userFakeid); <span>//发送失败用户数</span><span>$errCount</span> = count(<span>$errUser</span>); <span>//发送成功用户数</span><span>$succeCount</span> = <span>$count</span>-<span>$errCount</span>; <span>$data</span> = <span>array</span>( <span>'status'</span>=><span>0</span>, <span>'count'</span>=><span>$count</span>, <span>'succeCount'</span>=><span>$succeCount</span>, <span>'errCount'</span>=><span>$errCount</span>, <span>'errUser'</span>=><span>$errUser</span> ); <span>return</span> json_encode(<span>$data</span>); } <span>//获取所有用户信息</span><span>public</span><span><span>function</span><span>getAllUserInfo</span><span>()</span>{</span><span>foreach</span>(<span>$this</span>->userFakeid <span>as</span><span>$v</span>){ <span>$info</span>[] = <span>$this</span>->getUserInfo(<span>$v</span>[<span>'groupid'</span>],<span>$v</span>[<span>'fakeid'</span>]); } <span>return</span><span>$info</span>; } <span>//获取用户信息</span><span>public</span><span><span>function</span><span>getUserInfo</span><span>(<span>$groupId</span>,<span>$fakeId</span>)</span>{</span><span>$url</span> = <span>"https://mp.weixin.qq.com/cgi-bin/getcontactinfo?t=ajax-getcontactinfo&lang=zh_CN&fakeid={$fakeId}"</span>; <span>$this</span>->getHeader = <span>0</span>; <span>$this</span>->referer = <span>'https://mp.weixin.qq.com/cgi-bin/contactmanagepage?token='</span>.<span>$this</span>->token.<span>'&t=wxm-friend&lang=zh_CN&pagesize='</span>.<span>$this</span>->pageSize.<span>'&pageidx=0&type=0&groupid='</span>.<span>$groupId</span>; <span>$this</span>->send_data = <span>array</span>( <span>'token'</span>=><span>$this</span>->token, <span>'ajax'</span>=><span>1</span> ); <span>$message_opt</span> = <span>$this</span>->curlPost(<span>$url</span>); <span>return</span><span>$message_opt</span>; } <span>//获取所有用户fakeid</span><span>private</span><span><span>function</span><span>getUserFakeid</span><span>()</span>{</span> ini_set(<span>'max_execution_time'</span>,<span>600</span>); <span>$pageSize</span> = <span>1000000</span>; <span>$this</span>->referer = <span>"https://mp.weixin.qq.com/cgi-bin/home?t=home/index&lang=zh_CN&token={$this->token}"</span>; <span>$url</span> = <span>"https://mp.weixin.qq.com/cgi-bin/contactmanage?t=user/index&pagesize={$pageSize}&pageidx=0&type=0&groupid=0&token={$this->token}&lang=zh_CN"</span>; <span>$user</span> = <span>$this</span>->vget(<span>$url</span>); var_dump(<span>$user</span>); <span>$preg</span> = <span>"/\"id\":(\d+),\"nick_name\"/"</span>; preg_match_all(<span>$preg</span>,<span>$user</span>,<span>$b</span>); <span>$i</span> = <span>0</span>; <span>foreach</span>(<span>$b</span>[<span>1</span>] <span>as</span><span>$v</span>) { <span>$arr</span>[<span>$i</span>][<span>'fakeid'</span>] = <span>$v</span>; <span>$arr</span>[<span>$i</span>][<span>'groupid'</span>] = <span>0</span>; <span>$i</span>++; } <span>return</span><span>$arr</span>; } <span>/** * curl模拟登录的post方法 *<span> @param</span> $url request地址 *<span> @param</span> $header 模拟headre头信息 *<span> @return</span> json */</span><span>private</span><span><span>function</span><span>curlPost</span><span>(<span>$url</span>)</span> {</span><span>$header</span> = <span>array</span>( <span>'Accept:*/*'</span>, <span>'Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3'</span>, <span>'Accept-Encoding:gzip,deflate,sdch'</span>, <span>'Accept-Language:zh-CN,zh;q=0.8'</span>, <span>'Connection:keep-alive'</span>, <span>'Host:'</span>.<span>$this</span>->host, <span>'Origin:'</span>.<span>$this</span>->origin, <span>'Referer:'</span>.<span>$this</span>->referer, <span>'X-Requested-With:XMLHttpRequest'</span> ); <span>$curl</span> = curl_init(); <span>//启动一个curl会话</span> curl_setopt(<span>$curl</span>, CURLOPT_URL, <span>$url</span>); <span>//要访问的地址</span> curl_setopt(<span>$curl</span>, CURLOPT_HTTPHEADER, <span>$header</span>); <span>//设置HTTP头字段的数组</span> curl_setopt(<span>$curl</span>, CURLOPT_SSL_VERIFYPEER, <span>0</span>); <span>//对认证证书来源的检查</span> curl_setopt(<span>$curl</span>, CURLOPT_SSL_VERIFYHOST, <span>1</span>); <span>//从证书中检查SSL加密算法是否存在</span> curl_setopt(<span>$curl</span>, CURLOPT_USERAGENT, <span>$this</span>->useragent); <span>//模拟用户使用的浏览器</span> curl_setopt(<span>$curl</span>, CURLOPT_FOLLOWLOCATION, <span>1</span>); <span>//使用自动跳转</span> curl_setopt(<span>$curl</span>, CURLOPT_AUTOREFERER, <span>1</span>); <span>//自动设置Referer</span> curl_setopt(<span>$curl</span>, CURLOPT_POST, <span>1</span>); <span>//发送一个常规的Post请求</span> curl_setopt(<span>$curl</span>, CURLOPT_POSTFIELDS, <span>$this</span>->send_data); <span>//Post提交的数据包</span> curl_setopt(<span>$curl</span>, CURLOPT_COOKIE, <span>$this</span>->cookie); <span>//读取储存的Cookie信息</span> curl_setopt(<span>$curl</span>, CURLOPT_TIMEOUT, <span>30</span>); <span>//设置超时限制防止死循环</span> curl_setopt(<span>$curl</span>, CURLOPT_HEADER, <span>$this</span>->getHeader); <span>//显示返回的Header区域内容</span> curl_setopt(<span>$curl</span>, CURLOPT_RETURNTRANSFER, <span>1</span>); <span>//获取的信息以文件流的形式返回</span><span>$result</span> = curl_exec(<span>$curl</span>); <span>//执行一个curl会话</span> curl_close(<span>$curl</span>); <span>//关闭curl</span><span>return</span><span>$result</span>; } <span>private</span><span><span>function</span><span>vget</span><span>(<span>$url</span>)</span>{</span><span>// 模拟获取内容函数</span><span>$header</span> = <span>array</span>( <span>'Accept: */*'</span>, <span>'Connection: keep-alive'</span>, <span>'Host: mp.weixin.qq.com'</span>, <span>'Referer: '</span>.<span>$this</span>->referer, <span>'X-Requested-With: XMLHttpRequest'</span> ); <span>$useragent</span> = <span>'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'</span>; <span>$curl</span> = curl_init(); <span>// 启动一个CURL会话</span> curl_setopt(<span>$curl</span>, CURLOPT_URL, <span>$url</span>); <span>// 要访问的地址</span> curl_setopt(<span>$curl</span>, CURLOPT_HTTPHEADER, <span>$header</span>); <span>//设置HTTP头字段的数组</span> curl_setopt(<span>$curl</span>, CURLOPT_SSL_VERIFYPEER, <span>0</span>); <span>// 对认证证书来源的检查</span> curl_setopt(<span>$curl</span>, CURLOPT_SSL_VERIFYHOST, <span>1</span>); <span>// 从证书中检查SSL加密算法是否存在</span> curl_setopt(<span>$curl</span>, CURLOPT_USERAGENT, <span>$useragent</span>); <span>// 模拟用户使用的浏览器</span> curl_setopt(<span>$curl</span>, CURLOPT_FOLLOWLOCATION, <span>1</span>); <span>// 使用自动跳转</span> curl_setopt(<span>$curl</span>, CURLOPT_AUTOREFERER, <span>1</span>); <span>// 自动设置Referer</span> curl_setopt(<span>$curl</span>, CURLOPT_HTTPGET, <span>1</span>); <span>// 发送一个常规的GET请求</span> curl_setopt(<span>$curl</span>, CURLOPT_COOKIE, <span>$this</span>->cookie); <span>// 读取上面所储存的Cookie信息</span> curl_setopt(<span>$curl</span>, CURLOPT_TIMEOUT, <span>30</span>); <span>// 设置超时限制防止死循环</span> curl_setopt(<span>$curl</span>, CURLOPT_HEADER, <span>$this</span>->getHeader); <span>// 显示返回的Header区域内容</span> curl_setopt(<span>$curl</span>, CURLOPT_RETURNTRANSFER, <span>1</span>); <span>// 获取的信息以文件流的形式返回</span><span>$tmpInfo</span> = curl_exec(<span>$curl</span>); <span>// 执行操作</span><span>if</span> (curl_errno(<span>$curl</span>)) { <span>// echo 'Errno'.curl_error($curl);</span> } curl_close(<span>$curl</span>); <span>// 关闭CURL会话</span><span>return</span><span>$tmpInfo</span>; <span>// 返回数据</span> } } </span></span></code>
以上就介绍了[微信公众号]php版模拟登录,向指定用户推送消息目前,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题











许多用户在选择智能手表的时候都会选择的华为的品牌,其中华为GT3pro和GT4都是非常热门的选择,不少用户都很好奇华为GT3pro和GT4有什么区别,下面就就给大家介绍一下二者。华为GT3pro和GT4有什么区别一、外观GT4:46mm和41mm,材质是玻璃表镜+不锈钢机身+高分纤维后壳。GT3pro:46.6mm和42.9mm,材质是蓝宝石玻璃表镜+钛金属机身/陶瓷机身+陶瓷后壳二、健康GT4:采用最新的华为Truseen5.5+算法,结果会更加的精准。GT3pro:多了ECG心电图和血管及安

curl和Pythonrequests都是发送HTTP请求的强大工具。虽然curl是一种命令行工具,可让您直接从终端发送请求,但Python的请求库提供了一种更具编程性的方式来从Python代码中发送请求。将curl转换为Pythonrequestscurl命令的基本语法如下所示:curl[OPTIONS]URL将curl命令转换为Python请求时,我们需要将选项和URL转换为Python代码。这是一个示例curlPOST命令:curl-XPOSThttps://example.com/api

在Linux下更新curl版本,您可以按照以下步骤进行操作:检查当前curl版本:首先,您需要确定当前系统中安装的curl版本。打开终端,并执行以下命令:curl--version该命令将显示当前curl的版本信息。确认可用的curl版本:在更新curl之前,您需要确定可用的最新版本。您可以访问curl的官方网站(curl.haxx.se)或相关的软件源,查找最新版本的curl。下载curl源代码:使用curl或浏览器,下载您选择的curl版本的源代码文件(通常为.tar.gz或.tar.bz2

从头到尾:如何使用php扩展cURL进行HTTP请求引言:在Web开发中,经常需要与第三方API或其他远程服务器进行通信。而使用cURL进行HTTP请求是一种常见而强大的方式。本文将介绍如何使用php扩展cURL来执行HTTP请求,并提供一些实用的代码示例。一、准备工作首先,确保php已安装cURL扩展。可以在命令行执行php-m|grepcurl查

PHP8.1发布:引入curl多个请求并发处理近日,PHP官方发布了最新版本的PHP8.1,其中引入了一个重要的特性:curl多个请求并发处理。这个新特性为开发者提供了一个更加高效和灵活的方式来处理多个HTTP请求,极大地提升了性能和用户体验。在以往的版本中,处理多个请求往往需要通过创建多个curl资源,并使用循环来分别发送和接收数据。这种方式虽然能够实现目

PHPCurl中如何处理网页的301重定向?在使用PHPCurl发送网络请求时,时常会遇到网页返回的301状态码,表示页面被永久重定向。为了正确处理这种情况,我们需要在Curl请求中添加一些特定的选项和处理逻辑。下面将详细介绍在PHPCurl中如何处理网页的301重定向,并提供具体的代码示例。301重定向处理原理301重定向是指服务器返回了一个30

在linux中,curl是一个非常实用的、用来与服务器之间传输数据的工具,是一个利用URL规则在命令行下工作的文件传输工具;它支持文件的上传和下载,是综合传输工具。curl提供了一大堆非常有用的功能,包括代理访问、用户认证、ftp上传下载、HTTP POST、SSL连接、cookie支持、断点续传等等。

为什么截图工具在Windows11上不起作用了解问题的根本原因有助于找到正确的解决方案。以下是截图工具可能无法正常工作的主要原因:对焦助手已打开:这可以防止截图工具打开。应用程序损坏:如果截图工具在启动时崩溃,则可能已损坏。过时的图形驱动程序:不兼容的驱动程序可能会干扰截图工具。来自其他应用程序的干扰:其他正在运行的应用程序可能与截图工具冲突。证书已过期:升级过程中的错误可能会导致此issu简单的解决方案这些适合大多数用户,不需要任何特殊的技术知识。1.更新窗口和Microsoft应用商店应用程
