WeChat development has been active for a long time. There is a magical interface called template message interface in WeChat development. It can push custom template messages from the server to the user according to the user’s openid. Because of this, we can use This feature pushes messages to the user at any time on the server side (provided that the user pays attention to the official account).
Summarize 3 points: 1. The format of the template message can be customized, 2. The content of the template message can be customized, 3. The time when the template message is sent can be customized. Then we can use these properties to make a good morning program for ourselves!
lab environment
Alibaba Cloud Linux server Python environment
ICIBA Daily Sentence API Introduction
Call address:
http://open.iciba.com/dsapi/ Request method: GET request parameters:
Return type: JSON
JSON field explanation:
Example of normal return:
Example request:
Python2 request example
Python3 request example
PHP request example
.
Official document of this interface (one sentence of the day):
http://open.iciba.com/?c=wiki
Reference materials: Kingsoft PowerWord · Development Platform
Log in to the WeChat public platform interface test account
Scan to log in to the public platform test account to apply for the test account address
https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login
Confirm login on phone
Find the new test template, add template message
Fill in the template title one sentence per day, and fill in the following template content
{ {content.DATA}} { {note.DATA}} { {translation.DATA}}
After submitting and saving, remember the template ID, you will use it later
Find the test number information, remember the appid and appsecret, you will need it later
Find the QR code of the test number. Scan this QR code with your mobile phone. After following, your nickname will appear in the list on the right. Remember the WeChat ID and you will use it later (Note: This WeChat ID is not your real WeChat ID)
Procedure for sending WeChat template messages
The GitHub address of this program:
https://github.com/varlemon/wechat-iciba-everyday
You only need to modify 4 places in this program, please see the note Python2 implementation
Python3 implementation
test program
Execute programs on Linux
Check on the phone, I have received a message of the day
The deployment program sets up timing tasks on Linux
crontab -e
Add the following content
0 6 * * * python /root/python/iciba/main-v1.0.py
Note: The meaning of the above content is that at 6:00 every day, execute this Python program to check whether the timing task is set successfully
crontab -l
At this point, the program deployment is completed, please check it tomorrow at 6:00! The effect diagram is as follows
Recently, many friends consulted about Python learning issues through private messages. To facilitate communication, click on the blue to join the discussion and answer resource base by yourself