


[WeChat public account] PHP version simulates login and pushes messages to designated users. Currently
[WeChat public account] PHP version simulates login and pushes messages to designated users
Currently, the WeChat public account does not have an open push interface. Simulated login means simulating user login. You can view user messages, reply to messages, etc. WeChat has not officially stated whether it is prohibited. Extensive use may result in account bans, etc. Use with caution!
The following code was collected from the Internet. The original text cannot be found, so the source will not be posted for the time being.
Simulated login code:
<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>'</br>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></code>
The above has introduced [WeChat public account] PHP version simulated login and push messages to designated users. Currently, it includes the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Both curl and Pythonrequests are powerful tools for sending HTTP requests. While curl is a command-line tool that allows you to send requests directly from the terminal, Python's requests library provides a more programmatic way to send requests from Python code. The basic syntax for converting curl to Pythonrequestscurl command is as follows: curl[OPTIONS]URL When converting curl command to Python request, we need to convert the options and URL into Python code. Here is an example curlPOST command: curl-XPOST https://example.com/api

To update the curl version under Linux, you can follow the steps below: Check the current curl version: First, you need to determine the curl version installed in the current system. Open a terminal and execute the following command: curl --version This command will display the current curl version information. Confirm available curl version: Before updating curl, you need to confirm the latest version available. You can visit curl's official website (curl.haxx.se) or related software sources to find the latest version of curl. Download the curl source code: Using curl or a browser, download the source code file for the curl version of your choice (usually .tar.gz or .tar.bz2

From start to finish: How to use php extension cURL for HTTP requests Introduction: In web development, it is often necessary to communicate with third-party APIs or other remote servers. Using cURL to make HTTP requests is a common and powerful way. This article will introduce how to use PHP to extend cURL to perform HTTP requests, and provide some practical code examples. 1. Preparation First, make sure that php has the cURL extension installed. You can execute php-m|grepcurl on the command line to check

PHP8.1 released: Introducing curl for concurrent processing of multiple requests. Recently, PHP officially released the latest version of PHP8.1, which introduced an important feature: curl for concurrent processing of multiple requests. This new feature provides developers with a more efficient and flexible way to handle multiple HTTP requests, greatly improving performance and user experience. In previous versions, handling multiple requests often required creating multiple curl resources and using loops to send and receive data respectively. Although this method can achieve the purpose

How to handle 301 redirection of web pages in PHPCurl? When using PHPCurl to send network requests, you will often encounter a 301 status code returned by the web page, indicating that the page has been permanently redirected. In order to handle this situation correctly, we need to add some specific options and processing logic to the Curl request. The following will introduce in detail how to handle 301 redirection of web pages in PHPCurl, and provide specific code examples. 301 redirect processing principle 301 redirect means that the server returns a 30

In Linux, curl is a very practical tool for transferring data to and from the server. It is a file transfer tool that uses URL rules to work under the command line; it supports file upload and download, and is a comprehensive transfer tool. . Curl provides a lot of very useful functions, including proxy access, user authentication, ftp upload and download, HTTP POST, SSL connection, cookie support, breakpoint resume and so on.

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps
