企业微信机器人定时提醒功能,企业微信机器人开发接口文档import requests
import json
import logging
from apscheduler.schedulers.blocking import BlockingScheduler
def do_something(content):
data = {
"msgtype": "text",
"text": {
"content": content,
}
}
url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=***********************"
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36"}
res = requests.post(url, data=json.dumps(data), headers=headers, timeout=10)
logging.info(f"{res.status_code}, {res.text}, 传送成功")
scheduler = BlockingScheduler(timezone='Asia/Shanghai')
scheduler.add_job(do_something, 'cron', day_of_week='0,1,2,3,4', hour=11, minute=5, args=("11点05啦,点外卖~点外卖~点外卖~", ), max_instances=100, misfire_grace_time=360)
scheduler.add_job(do_something, 'cron', day_of_week='0,1,2,3', hour=17, minute=5, args=("17:05啦,填写当日工时~填写当日工时~填写当日工时~",), max_instances=100, misfire_grace_time=360)
scheduler.add_job(do_something, 'cron', day_of_week='0,1,2,3', hour=17, minute=45, args=("17:45啦,再次提醒!填写当日工时~填写当日工时~填写当日工时~", ), max_instances=100, misfire_grace_time=360)
scheduler.add_job(do_something, 'cron', day_of_week='4', hour=17, minute=30, args=("17:30啦,发送每周周报邮件~发送每周周报邮件~发送每周周报邮件~", ), max_instances=100, misfire_grace_time=360)
scheduler.start()