#!/usr/bin/env python
# -*- coding: utf-8 -*-
import jpush as jpush
from api.utils import utils_url
from common import web_helper
@utils_url.route('/xxx', methods=['post'])
def tuisong_message():
content_ = web_helper.get_request_param('content_') # 推送内容
if not content_:
return web_helper.return_msg(0, '推送内容不能为空')
# app_key和master_secret
app_key = 'xxx'
master_secret = 'xxx'
_jpush = jpush.JPush(app_key, master_secret)
push = _jpush.create_push()
push.audience = jpush.all_
push.notification = jpush.notification(alert=content_)
push.platform = jpush.all_
try:
res = push.send()
except Exception:
return web_helper.return_msg(0, '推送失败')
return web_helper.return_msg(1, '推送成功')
需要安装jpush模块:sudo pip install jpush