This article mainly introduces the mass development information of the public platform. detailed information is provided here to describe the mass development process of the public platform. if you have any need, refer to this article to introduce the mass development information of the public platform, detailed information is provided here to illustrate the process of sending mass information to the public platform. For more information, see
1. purpose
Send messages to the public account. Here is just to complete simple text sending. You can also send voice images, but the data sending format is different. there is a link below to query the data sending format.
2. process of sending mass messages
-
Obtain the public account for testing (if you have an account, you do not need to test the account, but there are many formal account restrictions)
-
The user follows the above public account
-
Obtain our access_token through appid and appsecret
-
Send SMS messages by using access_token
3. obtain the test public account + follow public account
1) obtain the public test account
Access the connection above, select "interface test number application" to get to open the http://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo directly? Action = showinfo & t = sandbox/index: scan the client to log on.
After logon, you can obtain information about a public account. There are two parameters: appId and appsecret, which uniquely identify a public number and use them as parameters to obtain user information. ,
2) configure the interface information
For this step, you can refer to the Access Instructions. This page provides a php instance for downloading. it is easy to modify the custom TOKEN and then place the verification page on your server.
Here I provide an example:
Prepare resources:
Domain name + space (my sae space + HiChina domain name), PHP file for verification only
I created a wx_sample.php
Wx_sample.php
valid();class wechatCallbackapiTest{ public function valid() { $echoStr = $_GET["echostr"]; //valid signature , option if($this->checkSignature()){ echo $echoStr; exit; } } public function responseMsg() { //get post data, May be due to the different environments $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //extract post data if (!empty($postStr)){ /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection, the best way is to check the validity of xml by yourself */ libxml_disable_entity_loader(true); $postObj = simplexml_load_string($postStr, ‘SimpleXMLElement‘, LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $keyword = trim($postObj->Content); $time = time(); $textTpl = "
%s
%s
%s
%s
%s
0
"; if(!empty( $keyword )) { $msgType = "text"; $contentStr = "Welcome to wechat world!"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else{ echo "Input something..."; } }else { echo ""; exit; } } private function checkSignature() { // you must define TOKEN by yourself if (!defined("TOKEN")) { throw new Exception(‘TOKEN is not defined!‘); } $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = TOKEN; $tmpArr = array($token, $timestamp, $nonce); // use SORT_STRING rule sort($tmpArr, SORT_STRING); $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); if( $tmpStr == $signature ){ return true; }else{ return false; } }}?>
Then fill in the configuration information Token (must be consistent with the token in wx_sample.php above), URL (wx_sample.php address)
| Parameters |
Description |
| Access_token |
Obtained credential |
| Expires_in |
Valid credential time, in seconds |
When an error occurs, an error code or other information is returned. An example of a JSON data packet is as follows (this example is an invalid AppID error ):
{& Quot; errcode & quot;: 40013, & quot; errmsg & quot;: & quot; invalid appid & quot "}
Example:
Get access_token:
Https://api.weixin.qq.com/cgi-bin/token? Grant_type = client_credential & appid = wx41cb8dbd827a16e9 & secret = d4624c36b6795d1d99dcf0547af5443d
Returned data:
{ "access_token": "qR5UK2vMf5aTHV8e-uB10FZW0caTZm_1kbkUe4OPK2ILVvNaoa7pLzYWqLUAmx6Sjq1E7pKHrVAtuG0_1MPkqmDfOkm2750kaLWNk59DS-iDOpjjxompJtXa3WhbN5FKRWNhADAVAR", "expires_in": 7200}
5. send SMS messages through access_token
On the website of the public platform, the group sending permission is provided for the subscription number one per day, and the group sending permission is provided for the service number four per month (calendar month. For some public account operators with development capabilities, they can use the advanced group sending interface to achieve more flexible group sending capabilities.
Note:
1. for authentication subscription numbers, the group sending interface can be successfully called once a day. this group can be sent to all users or a group;
2. for the certification service number, although developers can use the advanced group-sending interface for up to 100 calls per day, users can only receive four messages per month, whether on the public platform website or using the interface Group, A user can receive only four group messages each month, and more than four group messages will fail to be sent to the user;
3. if you have a public account with the payment permission, you can use tags to join external links when using the group-sending interface to upload or send group text messages;
4. developers can use the preview interface to verify the message style and layout. the preview interface can send edited messages to the specified user for verification.
1) group by group. [both the subscription number and service number can be used after authentication]
Call Interface:
Http request method: POST
Https://api.weixin.qq.com/cgi-bin/message/mass/sendall? Access_token = ACCESS_TOKEN add the following data to the body (send data in JSON format) -- send data in other formats, you only need to modify the parameter information. for details, see the official documentation:
{ "filter":{ "is_to_all":false, "group_id":2 }, "text":{ "content":"CONTENT" }, "msgtype":"text"}
Parameter description:
| Parameters |
Required? |
Description |
| Filter |
Yes |
Used to set the receiver of a text message |
| Is_to_all |
No |
This parameter is used to set whether to send messages to all users. The value is true or false. if it is set to true, the messages are sent to all users. if it is set to false, messages can be sent to users in the specified group based on group_id. |
| Group_id |
No |
Group_id of the group to which a group is sent. this parameter is used for the user group interface in user management. if the value of is_to_all is true, group_id is not required. |
| Mpnews |
Yes |
Used to set the text message to be sent |
| Media_id |
Yes |
Media_id used for group messages |
| Msgtype |
Yes |
Group message type. The text message is mpnews, the text message is text, the voice is voice, the music is music, the image is image, the video is video, and the card coupon is wxcard. |
| Title |
No |
Message title |
| Description |
No |
Message description |
| Thumb_media_id |
Yes |
Media ID of the video thumbnail |
Example: send to everyone
Url:
Https://api.weixin.qq.com/cgi-bin/message/mass/sendall? Access_token = KBoNONaJZ4-KhafQVJoQ6VBX0F-bls7nAsJBn8Fy7GLwav4Be1lRJcob1RHH6wW35IxxFwkJnZfnc-On9EQITg3oxEWUw7O2YyVW9naDknu6PQX9fnSmQcr8ojTK8Ug-HDTcAAABXN
Json data sent: send to all users
{ "filter":{ "is_to_all":true }, "text":{ "content":"CONTENT" }, "msgtype":"text"}
Returned data:
{ "errcode": 0, "errmsg": "send job submission success", "msg_id": 1000000003}
Parameter meaning:
| Parameters |
Description |
| Type |
Media file types, including image, voice, video, and thumb. |
| Errcode |
Error code |
| Errmsg |
Error message |
| Msg_id |
ID of the message sending task |
| Msg_data_id |
The data ID of the message. This field appears only when a group of text messages is sent. It can be used to obtain the corresponding text message data in the graphic analysis data interface, which is the first half of the msgid field in the graphic analysis data interface, for details, see the description of the msgid field in the graphic analysis data interface.
|
Error codes and query:
Use postman to simulate https request sending, as shown in:
Https://api.weixin.qq.com/cgi-bin/message/mass/send? Access_token = ACCESS_TOKEN
Data format:
{ "touser":[ "OPENID1", "OPENID2" ], "msgtype": "text", "text": { "content": "hello from boxer."}}
OPENID1 and OPENID2 are the user openId (unique user ID) to be sent ).
Example:
Send "oF3PcsnsrMiJzEwalZZbAfWQpxCI" and "oF3PcshH1CUIhR_WYau6swUiPzlw" users.
Content: hello from boxer. welcome to Baidu
Url:
Https://api.weixin.qq.com/cgi-bin/message/mass/send? Access_token = wRyTbnsiu18ssEhMPLf4bDfeT-Bt6e6tgR4CQGVLBipRcyJPkdAKPYfM6-qkKuHUN8uRKJh6Xvm0OuAdFgqOo8Ru8hoDxl-cGc9bh-ezJb2ZUcJSnQk2s416zI8kbEOfOGYdAFARJB
Json data:
{"Touser": ["oF3PcsnsrMiJzEwalZZbAfWQpxCI", "audio"], "msgtype": "text", "text": {"content": "hello from boxer. welcome to xivo College "}}
Returned data:
{ "errcode": 0, "errmsg": "send job submission success", "msg_id": 3147483654}
Use postman to send the following requests:
For more public platform development, refer to the PHP Chinese website for sending mass information articles!