def buildMessage(type=2, title='', content='', style=None, action=None, custom=None): mess = xinge.Message() mess.type = type mess.title = title mess.content = content mess.expireTime = 86400 '''含义:样式编号0 ,响铃,震动,不可从通知栏清除''' mess.style = style '''we use the default action, that's to open the app''' if action is not None: action = xinge.ClickAction(activity=action) mess.action = action mess.custom = custom t1 = xinge.TimeInterval(0, 0, 13, 59) t2 = xinge.TimeInterval(14, 0, 23, 59) mess.acceptTime = (t1, t2) return mess
def BuildNotification(): msg = xinge.Message() msg.type = xinge.Message.TYPE_NOTIFICATION msg.title = 'some title' msg.content = 'some content' # 消息为离线设备保存的时间,单位为秒。默认为0,表示只推在线设备 msg.expireTime = 86400 # 定时推送,非必须 #msg.sendTime = '2012-12-12 18:48:00' # 自定义键值对,key和value都必须是字符串,非必须 msg.custom = {'aaa': '111', 'bbb': '222'} # 使用多包名推送模式,详细说明参见文档和wiki,如果您不清楚该字段含义,则无需设置 #msg.multiPkg = 1 # 允许推送时段设置,非必须 #ti1 = xinge.TimeInterval(9, 30, 11, 30) #ti2 = xinge.TimeInterval(14, 0, 17, 0) #msg.acceptTime = (ti1, ti2) # 通知展示样式,仅对通知有效 # 样式编号为2,响铃,震动,不可从通知栏清除,不影响先前通知 style = xinge.Style(2, 1, 1, 0, 0) msg.style = style # 点击动作设置,仅对通知有效 # 以下例子为点击打开url action = xinge.ClickAction() action.actionType = xinge.ClickAction.TYPE_URL action.url = 'http://xg.qq.com' # 打开url不需要用户确认 action.confirmOnUrl = 0 msg.action = action # 以下例子为点击打开intent。例子中的intent将打开拨号界面并键入10086 # 使用intent.toUri(Intent.URI_INTENT_SCHEME)方法来得到序列化后的intent字符串,自定义intent参数也包含在其中 #action = xinge.ClickAction() #action.actionType = xinge.ClickAction.TYPE_INTENT #action.intent = 'intent:10086#Intent;scheme=tel;action=android.intent.action.DIAL;S.key=value;end' #msg.action = action return msg
def run(self): while True: cursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor) cursor.execute( "SELECT * FROM tb_notice_push where state=0 or state=-100 order by pushtime limit 100" ) rows = cursor.fetchall() if len(rows) > 0: updatesql = '' for row in rows: try: userId = row['userid'] content = row['content'] noticetype = 1 if row['noticetype'] == 1 else 2 if row['clienttype'] == 1: xg = android_xg msg = xinge.Message() msg.type = xinge.Message.TYPE_NOTIFICATION msg.title = '家庭作业' if noticetype == 1 else '学校通知' msg.content = content msg.expireTime = 3600 msg.custom = { 'noticeid': row['noticeid'], 'noticetype': 0 } msg.type = xinge.Message.TYPE_NOTIFICATION style = xinge.Style(1, 1, 1, 1, 5) msg.action = xinge.ClickAction( 1, '', 0, 'cn.youteach.xxt2.activity.notify.NoticeInfoActivity', '') msg.style = style ret = xg.PushSingleAccount(0, userId, msg, row['clienttype'] - 1) else: xg = ios_xg noticeId = row['noticeid'] msg = xinge.MessageIOS() msg.badge = 1 msg.sound = 'default' msg.alert = content msg.expireTime = 3600 msg.custom = {'messageid': noticeId} ret = xg.PushSingleAccount(2, userId, msg, row['clienttype'] - 1) #xg = xinge.XingeApp(2200062766, 'c9206fa64a4cb03ed712c1ea4f23ffb1') #msg = xinge.MessageIOS() #msg.alert = content #msg.expireTime = 3600 # 自定义键值对,value可以是json允许的类型 #msg.custom = {'noticeid':row['noticeid'],'noticetype':noticetype} print ret state, m = ret state = 1 if state == 0 else state sql = "update tb_notice_push set state=" + str( state) + " where pushid=" + str( row['pushid']) + ";" updatesql = updatesql + sql except Exception as e: logger(e, 'push') if updatesql: try: cursor = conn.cursor() cursor.execute(updatesql) except Exception as e: logger(e, 'push') time.sleep(1)