Monitoring service calls to the micro-trust API how to send their own alarm information _ server Other

Source: Internet
Author: User
Tags openid

On a whim today, I want to try the micro-credit public number to send myself a message. The main is to how to monitor the operation of the equipment failure can be through micro-letter alarm.

Check the developer documentation, found that the common unsigned subscription number can not be mass through the API, the certification subscription number can only be a single signal per day, and the certification of the service number of each month to send a household only 4. Instantaneous heart cool half, so the net again search a bit, found that there is a "weixin-private-api-master" Dongdong said it can be individually to each of the users to send, so download a try, failure. Check the official document again, the single send interface is not found, and the official FAQ does not have the function.

Finally, the use of public platform test account, finally succeeded. The specific steps are as follows:

Note: The test account can send 100 groups of mass information and 100 OpenID list mass information per day.

1. Registered public Platform subscription number (individual's unsigned subscriber number)

2. Open the Developer Center function, register the public platform test account. Get to AppID and Appsecret

3. Obtain Access_token through AppID and Appsecret. (also is a temporary voucher, the effective time is two hours, need to update before expiration). Gets the URL that is
Https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
(Replace the AppID and Appsecret above with the ID and password obtained in step 2nd)

4. Use personal micro-signal to pay attention to this test account, attention to the right will appear after the encryption of the micro-signal (ie, OpenID)

5. Invoke the API through script, here with PHP, an OpenID list of mass as an example

<?php $post _data = Array ("Touser" =>array (' OpenID1 ', ' OpenID2 '),//To replace OpenID with the encrypted micro-signal obtained in step 4th note there are at least two OpenID, Otherwise, an error message is returned. If only one account attention, you can make a casual, or two OpenID written as "Msgtype" => "text", "text" => Array ("Content" => "I A 
M msg. "));
 
$post _data = Json_encode ($post _data); Because the API only accepts JSON-formatted data, the JSON encode, of course, can be written directly as follows://$postdata = ' {' Touser ': ["OpenID1 ', ' OpenID2 '], ' msgtype '
 
: "Text", "text": {"Content": "I am MSG."}} ';
$url = ' Https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=ACCESS_TOKEN '; 
Replace the Access_token with the token $ch = Curl_init () obtained by the 3rd step; 
curl_setopt ($ch, Curlopt_post, 1); 
curl_setopt ($ch, Curlopt_url, $url); 
curl_setopt ($ch, Curlopt_postfields, $p);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE);
curl_setopt ($ch, Curlopt_ssl_verifyhost, FALSE);
The above two lines is to solve the HTTPS certificate problem, no words will be an error, so direct Trust certificate. $result =curl_exec ($ch);
echo Curl_error ($ch); Curl_close ($ch); Print_r ($result);

6. Open this page in a browser to show success:

7. View the information sent from the subscription number on the mobile phone. (There are some delays, so it is not suitable to use the micro-credit subscription number for the monitoring of urgent processing)

Finally, in order to Tencent for security, the use of Access_token, two hours to time out, so in order to regain before the timeout, you can directly in the code to refresh the acquisition. The maximum number of test accounts can be obtained 2000 times per day.

The above content is the monitoring service calls the micro-trust API how to send alarm information to itself all the content, I hope you like.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.