# 定时推送消息
def schedule_push_msg(content_, strdate_):
pattern = "^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$"
result = re.match(pattern, strdate_, flags=0)
if not result:
return -1 #'发送时间格式为yyyy-MM-dd HH:mm:ss'
_jpush = jpush.JPush(app_key, master_secret)
schedule = _jpush.create_schedule()
push = _jpush.create_push()
push.audience = jpush.all_
push.notification = jpush.notification(alert=content_)
push.platform = jpush.all_
push = push.payload
trigger = jpush.schedulepayload.trigger(strdate_)
schedule_payload = jpush.schedulepayload.schedulepayload("name", True, trigger, push)
result = schedule.post_schedule(schedule_payload)
if result.status_code != 200:
return -1 # 失败
return # 成功
注意点:需要传入定时时间和通知内容,通知的内容为字符串格式,定时时间格式必须为“yyyy-MM-dd HH:mm:ss”
成功返回200状态码