如何运用SAE+cron+微信开发定时通知提醒模块

首先你可以申请SAE开发者认证,然后就可以免费创建5个sae应用,无论你使用php,java或python语言。

我使用的是php.

然后你可以在微信企业号平台申请企业号(团队),然后在微信企业号中添加应用,新建管理组,记得将自己加入管理组,设置为管理员,然后你就能看到cropid和secret, 用来生成token。

下载你的sae项目到本地,我使用的是idea.

编辑config.yaml文件,添加定时任务

name: cronTaskversion: 1cron:- description: task to send weixin msg url: /task1.html schedule: “/1 “- description: task to refresh token url: /task2.html schedule: “ /2

task1用于发送微信消息。

https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=ACCESS_TOKEN

post如下数据:

{
“touser”: “UserID1|UserID2|UserID3”,
“toparty”: “ PartyID1 | PartyID2 “,
“totag”: “ TagID1 | TagID2 “,
“msgtype”: “text”,
“agentid”: “1”,
“text”: {
“content”: “Holiday Request For Pony(http://xxxxx)"
},
“safe”:”0”
}

task2用于刷新token,并存储。微信token有效期2小时,token是你发送消息必要参数。

https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=id&corpsecret=secrect

get方式获取token,然后json解析,存储access_token.

然后查看一下自己的userid,

替换task1的post数据,即可。

时2.JPG

效果如下:

s.png

0%