#!/usr/bin/python # -*- coding: utf-8 -*- # ##@package # # @todo: 受理HTTP请求 # # @author: Alee # @date 2018-5-4 22:10:51 # @version 1.0 # # @note: 中文必须传utf8,收到的为urlencode内容 .decode('gbk').encode('utf8') # #--------------------------------------------------------------------- from bottle import Bottle, request import logging import jpush import requests import urllib app_key = u'22186239fee975f883198cf4' master_secret = u'cb2b72ba143a3f3fb13a6f45' _jpush = jpush.JPush(app_key, master_secret) #_jpush.set_logging("DEBUG") requests.packages.urllib3.disable_warnings() # get: request.query.username request.GET.get('username','') # post: request.forms.get('username') request.POST.get('username') #=============================================================================== # @myapp.route('/cool/kk/:name3/:count#\\d+#') # def maybe(name3, count): #=============================================================================== myapp = Bottle() Def_Split_Mark = "|" Def_NoName = "亲" NotifyFormat = "【%s】%s" # 通知格式 【玩家名】信息 # 推送消息 # ?RegID=111141|1414|2141&PlayerName=熟练度空间|圣诞快乐|sjlkd&OSName=ios&NotifyMsg=BOSS复活 @myapp.route('/getui/index.php', method='POST') def JGGeTui(): getDict = request.POST notifyMsg = urllib.unquote(getDict.get("NotifyMsg","")) logging.info("%s-%s-%s"%(getDict.get("RegID",""), getDict.get("PlayerName",""), notifyMsg)) if not getDict.get("RegID",""): # 只能单\多推,不能全部推 return regIDs = getDict.get("RegID","").split(Def_Split_Mark) playrNames = getDict.get("PlayerName","") osName = getDict.get("OSName","") if not osName or osName == jpush.all_: osName = jpush.all_ else: osName = getDict.get("OSName","").split(Def_Split_Mark) #logging.info("%s-%s-%s"%(getDict.get("RegID",""), playrNames, notifyMsg)) #return "账号:" + getDict.get("AccountID",""), "充值", getDict.get("money","") if not playrNames: PushOne(regIDs, notifyMsg, osName) else: # 不支持notifymsg内容不一样的多推,只能一一对应推送 playrNames = playrNames.split(Def_Split_Mark) index = 0 for regID in regIDs: playerName = playrNames[index] if index < len(playrNames) else Def_NoName playerName = urllib.unquote(playerName) geTuiMsg = NotifyFormat%(playerName, notifyMsg) #logging.info("PushOne%s-%s-%s"%([regID], geTuiMsg, osName)) PushOne([regID], geTuiMsg, osName) index += 1 def PushOne(regIDList, notifyMsg, osName=jpush.all_): # 1.推送对象 单推(多推); 群推只能提交中心推 # 2.平台 ios 安卓 默认全平台 # 3.通知消息 push = _jpush.create_push() push.audience = {"registration_id" : regIDList} push.notification = jpush.notification(alert=notifyMsg) push.platform = osName push.options = {"time_to_live":300} #push.options = {"apns_production": False,} try: response=push.send() except: pass