A few days ago, I saw an article on the Internet "Teaching you to use WeChat to say good night to your girlfriend every day". I thought it was very magical. Then I studied it and found that the idea is indeed clever. Okay, let’s start construction! The server is there, the Python environment is there, and the IDE is opened... However... However... I realized a very serious problem... I don’t have a girlfriend (T_T)...
WeChat development has been active for a long time. There is a magical interface in WeChat development called the template message interface . It can push customized template messages to users from the server based on 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 follows the official account).
Three points are summarized: 1. The format of the template message can be customized, 2. The content of the template message can be customized, and 3. The time for sending the template message can be customized. Then we can use these properties to make a good morning program for ourselves!
Calling address: http://open.iciba.com/dsapi/
Request method: GET
Request parameters:
parameter | Required | type | illustrate |
---|---|---|---|
date | no | string | The format is: 2013-05-06 ; if date is empty, the current day will be taken by default. |
type | no | string | Optional values are last and next ; based on date , last returns the previous day, next returns the next day |
Return type: JSON
JSON field explanation:
attribute name | attribute value type | illustrate |
---|---|---|
sid | string | Daily ID sentence |
tts | string | audio address |
content | string | English content |
note | string | Chinese content |
love | string | Number of likes per sentence per day |
translation | string | PowerWord editor |
picture | string | Image address |
picture2 | string | Large picture address |
caption | string | title |
dateline | string | time |
s_pv | string | Number of views |
sp_pv | string | Voice review views |
tags | array | Related tags |
fenxiang_img | string | Composite pictures, recommended for sharing on Weibo |
Normal return example:
{
"sid" : " 3080 " ,
"tts" : " http://news.iciba.com/admin/tts/2018-08-01-day.mp3 " ,
"content" : " No matter how hard we try to be mature, we will always be a kid when we all get hurt and cry. " ,
"note" : "不管多努力蜕变成熟,一旦受伤哭泣时,我们还是像个孩子。 " ,
"love" : " 1966 " ,
"translation" : "小编的话:这句话出自小说《彼得·潘》。岁月永远年轻,我们慢慢老去。不管你如何蜕变,最后你会发现:童心未泯,是一件值得骄傲的事情。长大有时很简单,但凡事都能抱着一颗童心去快乐享受却未必容易。 " ,
"picture" : " http://cdn.iciba.com/news/word/20180801.jpg " ,
"picture2" : " http://cdn.iciba.com/news/word/big_20180801b.jpg " ,
"caption" : "词霸每日一句" ,
"dateline" : " 2018-08-01 " ,
"s_pv" : " 0 " ,
"sp_pv" : " 0 " ,
"tags" : [
{
"id" : null ,
"name" : null
}
],
"fenxiang_img" : " http://cdn.iciba.com/web/news/longweibo/imag/2018-08-01.jpg "
}
Request example:
Python2 request example
#!/usr/bin/python2
#coding=utf-8
import json
import urllib2
def get_iciba_everyday ():
url = 'http://open.iciba.com/dsapi/'
request = urllib2 . Request ( url )
response = urllib2 . urlopen ( request )
json_data = response . read ()
data = json . loads ( json_data )
return data
print get_iciba_everybody ()
Python3 request example
#!/usr/bin/python3
#coding=utf-8
import json
import requests
def get_iciba_everyday ():
url = 'http://open.iciba.com/dsapi/'
r = requests . get ( url )
return json . loads ( r . text )
print ( get_iciba_everyday ())
PHP request example
<?php
function https_request ( $ url , $ data = null ){
$ curl = curl_init ();
curl_setopt ( $ curl , CURLOPT_URL , $ url );
curl_setopt ( $ curl , CURLOPT_HEADER , 0 );
curl_setopt ( $ curl , CURLOPT_SSL_VERIFYPEER , 0 );
curl_setopt ( $ curl , CURLOPT_SSL_VERIFYHOST , 0 );
if (! empty ( $ data )) {
curl_setopt ( $ curl , CURLOPT_POST , 1 );
curl_setopt ( $ curl , CURLOPT_POSTFIELDS , $ data );
}
curl_setopt ( $ curl , CURLOPT_RETURNTRANSFER , 1 );
$ output = curl_exec ( $ curl );
curl_close ( $ curl );
return $ output ;
}
function get_iciba_everyday (){
$ url = ' http://open.iciba.com/dsapi/ '
$ result = https_request ( $ url );
$ data = json_decode ( $ result );
return $ data ;
}
echo get_iciba_everyday ();
Official document of this interface (one sentence per day): http://open.iciba.com/?c=wiki
Reference: Kingsoft PowerWord · Development Platform
Scan and 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 mobile phone
Find新增测试模板
and add the template message
Fill in the template title每日一句
, and fill in the following template content
{{content.DATA}}
{{note.DATA}}
{{translation.DATA}}
After submitting and saving, remember the模板ID
, which will be used later.
Find测试号信息
and remember appid
and appsecret
, which will be used later.
Find测试号二维码
. Scan this QR code with your mobile phone. After following it, your nickname will appear in the list on the right. Remember this WeChat ID, you will need it later (Note: This WeChat ID is not your real WeChat ID)
You only need to modify 4 places in this program, please see the comments
This project provides implementation of Python2.x
, Python3.x
, PHP
, Linux shell
and other languages. You can choose the appropriate program by yourself.
In the project directory, crontab.txt
is the writing format of Linux scheduled tasks; main.*
file is the execution entry file of the program.
Execute programs on Linux
Check it on your mobile phone and you have received the daily message
Set up scheduled 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 is to execute this Python program at 6:00
every day Check whether the scheduled task is set successfully
crontab -l
At this point, the program deployment is completed, please check it at 6:00
tomorrow! The renderings are as follows
This project address: https://github.com/varlemon/wechat-iciba-everyday
Back to top