Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
In the home page to see a love nuggets Girl big guy shared a [one hundred lines of code implementation! Cloud function version of the Denver nuggets automatic sign-in & draw & E-mail reminder ~], think about if you can send reminder to WeChat will be more convenient, but WeChat public individual cannot send a message, and find a small program found that can send, then make a wave, because most of the articles and code were written love nuggets hey girl bosses dalai, in this thank you.
Wechat applets
We use wechat mini program to realize the function of pushing messages to wechat. First, we apply for an account (wechat public platform – Immediate registration – mini program), and choose Education > Education Information Service as the service category, because it is found that only the first category of education can choose the template of long-term subscription.
Subscribe message template
After successful registration, scan code to enter wechat applet background => Function – Subscribe message – Public Template library (long-term subscription)
Choose the first assignment reminder
Submit and then go back to my template => Template details and record the template ID and details
Developer ID (applets ID, applets key)
Development – Development Management – Development Settings – Copy AppID and AppSecret for later use
To obtain the openId
Open wechat developer tools, create small programs, back-end services select wechat cloud development – OK
Enter the small program interface – Cloud function – obtain OpenId
Obtain the delivery permission.
See the small program end news subscription interface wx. RequestSubscribeMessage
I here are added to miniprogram – 2 / miniprogram/pages/index/index, js jumpPage method below, then click a secondary menu can call this function
wx.requestSubscribeMessage({
tmplIds: ['template ID'].// Fill in the ID of the template copied above
success (res) {
if (res.errMsg === 'requestSubscribeMessage:ok') {
// The subscription succeeded
console.log(res)
}
},
fail (res) {
console.log(res)
}
})
Copy the code
Wechat developer Tools – Preview – wechat scan the QR code and then turn up the client mini program subscription message interface check box
Tencent Cloud Function
No server here with the help of Tencent cloud cloud function (white whao), enter Tencent cloud Serverless – function service – new function
Basic configuration
Wait for the deployment to complete.
Function code
- On the Function Management page, choose Function Code > Code Edit to view and edit functions.
- willjj-signInIn the directory
package.json
,index.js
Copy all tosrc
Directory, and configureindex.js
中config
Related parameters.
- Select a new terminal from the menu bar terminal at the top of the IDE to open the terminal window.
- Run the following command on the terminal to install the dependency library:
cd src The dependency library needs to be installed in the same level as the function entry file, i.e. go to the 'SRC' directory before performing the dependency installation operation.
npm install
Copy the code
- Once installed, look in the file tree on the left side of the IDE
package.json
和node_modules
. - Click the deployed dependency library to package it with the function code and upload it to the cloud. As shown below:
- Click Test to see how the code works
Trigger configuration
Function services – Function details – Trigger Management – Create triggers
0 0 1 * * * * stands for one o ‘clock every day. For details, see Timing trigger description – Cloud Function
Wechat service notice
Every day after successful check-in, the wechat service notice will receive an assignment reminder
Zizi, over ~
reference
- One hundred lines of code! Cloud function edition gold nuggets automatic check-in & raffle & email alerts ~
- Cloud function – development guide – Tencent Cloud