def send_message(self,message): for rid in self.get_receivers(): message.audience = jpush.registration_id(rid) try: message.send() except jpush.JPushFailure as e : raise PushException()
def send(self, *args, **kwargs): try: content = NoticeTemplate.objects.get(category=self.category) except NoticeTemplate.DoesNotExist: print u"没有发现模板" return False print content.content template = Template(content.content) messages = template.render(dict(*args, **kwargs)) registration_id = kwargs.get('registration_id') opts = jpush.JPush(settings.JPUSH_APPKEY, settings.JPUSH_SECRET) push = opts.create_push() push.notification = jpush.notification(alert=messages) push.options = { "time_to_live": 86400, "apns_production": True, 'extras': kwargs.get('extras') } push.audience = jpush.audience(jpush.registration_id( registration_id)) if registration_id else jpush.all_ push.platform = jpush.all_ push.send()
def push_by_id(self, notification, registration_id): self.push.platform = jpush.all_ self.push.audience = jpush.audience(jpush.registration_id(registration_id)) self.push.notification = jpush.notification(alert=notification) self.__push() tip_message = 'JPush SUCCESS.To: %s'% (registration_id) _LOGGER.info(tip_message)
def jpushMessageWithRegId(regid, msg, action): push = jpushCreateClient() push.audience = jpush.audience(jpush.registration_id(regid)) push.notification = jpush.notification( android=jpush.android(alert=action, extras=msg)) print msg, push.notification resp = jushPushMessageToJiGuang(push) return resp
def send_new_photo_notification(regids, data): _jpush = jpush.JPush(settings.JPUSH_APP_KEY, settings.JPUSH_APP_MASTER) push = _jpush.create_push() push.audience = jpush.registration_id(*regids) push.notification = jpush.notification(ios=jpush.ios(alert='', content_available=True, extras={"d": data, "action": "photo"})) push.options = dict(apns_production=False) push.platform = jpush.platform('ios') return push.send()
def send_friend_notification(regid, data): _jpush = jpush.JPush(settings.JPUSH_APP_KEY, settings.JPUSH_APP_MASTER) push = _jpush.create_push() push.audience = jpush.registration_id(regid) push.notification = jpush.notification(ios=jpush.ios(alert='sb has make friend with you!', extras={"d": data, "action": "friend"})) push.options = dict(apns_production=False) push.platform = jpush.platform('ios') return push.send()
def push_news(push_id, news): _jpush = jpush.JPush(app_key, master_secret) push = _jpush.create_push() push.audience = jpush.audience( jpush.registration_id(push_id) ) push.notification = jpush.notification(alert=news) push.platform = jpush.all_ push.send()
def send_like_notification(regid, like_num): if not regid or len(regid) <> 11: return 'invalid reg_id' _jpush = jpush.JPush(settings.JPUSH_APP_KEY, settings.JPUSH_APP_MASTER) push = _jpush.create_push() push.audience = jpush.registration_id(regid) push.notification = jpush.notification(ios=jpush.ios(alert='', content_available=True, extras={"like_num": like_num, "action": "like"})) push.options = dict(apns_production=False) push.platform = jpush.platform('ios') return push.send()
def send_notification(self, _id, title, actors): for actor in actors: client_ids = self.get_actor_subscribers(actor) if client_ids: push = self._jpush.create_push() push.audience = jpush.audience( jpush.registration_id(*client_ids) ) log.msg("client ids = " + json.dumps(client_ids)) message = jpush.android(alert=u'新片通知 : 您关注的艺人 ' + actor.encode('utf-8') + u' 有新片 %s ,点击查看详情。' %(title.encode('utf-8')), extras={'VideoID':str(_id)}) push.notification = jpush.notification(alert=u'新片通知 : 您关注的艺人发布了新片,点击查看详情。', android=message) log.msg("Sending push notification for %s and %s" %(title, actor)) push.platform = jpush.all_ push.send()
def single(self, reg_id): self.push.audience = jpush.audience( jpush.registration_id('id1', reg_id)) self.push.notification = jpush.notification(alert=self.msg, android=self.android_msg, ios=self.ios_msg) self.push.options = { "time_to_live": 86400, "sendno": 12345, "apns_production": False } self.push.platform = jpush.all_ try: self.push.send() except Exception as e: print(e)
def push_Msg(): _jpush = jpush.JPush( app_key, master_secret) ##1、初始化JPush,获取AppKey,Master Secret;实例化JPush, push = _jpush.create_push() print("jpush:" + app_key + "/n" + master_secret) # --------------------------------推送设备对象--------------------------- # 一个推送对象,以 JSON 格式表达,表示一条推送相关的所有信息。 # push.audience=jpush.all_ ;#audience 必填 推送设备指定;确认推送设备对象,JPush 提供了多种方式,比如:别名、标签、注册ID、分群、广播等。 push.audience = jpush.audience( jpush.registration_id("1a0018970af48adfcbf", )) # ----------------------------自定义消息 发给android的实现--------------- push.message = jpush.message( "{'salists': [{'payType': 1, 'proid': 3, 'name': '燕麦谷粒多', 'count': 1, 'sinPrice': 2, 'toPrice': 2, 'chid': 162}], 'nums': 1}" ) # message 可选 消息内容体。是被推送到客户端的内容。与 notification 一起二者必须有其一,可以二者并存 # --------------------------- 发送通知 给android的实现-------------------- push.platform = jpush.all_ # platform 必填 推送平台设置 push.send()
def send_notification(self, _id, title, actors): for actor in actors: client_ids = self.get_actor_subscribers(actor) if client_ids: push = self._jpush.create_push() push.audience = jpush.audience( jpush.registration_id(*client_ids)) log.msg("client ids = " + json.dumps(client_ids)) message = jpush.android( alert=u'新片通知 : 您关注的艺人 ' + actor.encode('utf-8') + u' 有新片 %s ,点击查看详情。' % (title.encode('utf-8')), extras={'VideoID': str(_id)}) push.notification = jpush.notification( alert=u'新片通知 : 您关注的艺人发布了新片,点击查看详情。', android=message) log.msg("Sending push notification for %s and %s" % (title, actor)) push.platform = jpush.all_ push.send()
def handle(self, *args, **options): user = GKUser.objects.get(pk=2067879) rids = list(user.jpush_token.all().values_list('rid', flat=True)) _jpush = jpush.JPush(app_key, app_secret) push = _jpush.create_push() extras = {'url': 'http://www.guoku.com/detail/03071d5f/'} push.notification = jpush.notification(alert='推送测试', ios=jpush.ios('iOS推送测试', extras=extras), android=jpush.android( 'Android推送测试', extras=extras)) push.platform = jpush.all_ push.audience = jpush.registration_id(*rids) push.options = {'apns_production': False} print(push.payload) push.send()
def single(self, reg_id): self.push.audience = jpush.audience( jpush.registration_id('id1', reg_id) ) self.push.notification = jpush.notification( alert=self.msg, android=self.android_msg, ios=self.ios_msg ) self.push.options = { "time_to_live":86400, "sendno":12345, "apns_production":False } self.push.platform = jpush.all_ try: self.push.send() except Exception as e: print(e)
def pushProduct(id, operId): try: db.execute("SELECT * FROM " + getTableName('push', operId)+ " WHERE id=%s LIMIT 1", (id,)) msg = db.get_rows(size=1, is_dict=True) db.execute("SELECT * FROM %s WHERE `status`=1" %getTableName('pusher', operId)) pusher = db.get_rows(is_dict=True) _jpush = jpush.JPush(app_key, master_secret) push = _jpush.create_push() total = 0 for vo in pusher: if vo['categories'] and msg['category'] not in vo['categories']: continue if vo['keyword'] and msg['keyword'] not in vo['keyword']: continue push.audience = jpush.audience( jpush.registration_id(vo['registration']) ) push.notification = jpush.notification( android=jpush.android( alert=msg['title'], builder_id=getBuidlerId(vo['sound'], vo['vibrate']), extras={"id": msg['product'], 'target': 'product'} ) ) push.platform = jpush.platform('android') push.send() total = total + 1 db.update(getTableName('pusher', operId), {'date': time2stamp(datetime.date.today().strftime('%Y-%m-%d'))}, {'id': vo['id']}) except Exception: db.update(getTableName('push', operId), {'status': 2}, {'id': id}) return False else: db.update(getTableName('push', operId), {'status': 1, 'total': total}, {'id': id}) return True
def pushMessage(registration, operId): db.execute("SELECT * FROM " + getTableName('pusher', operId)+ " WHERE registration=%s AND `status`=1 LIMIT 1", (registration,)) if db.get_rows_num() == 0: return pusher = db.get_rows(size=1, is_dict=True) _jpush = jpush.JPush(app_key, master_secret) push = _jpush.create_push() push.audience = jpush.audience( jpush.registration_id(registration) ) push.notification = jpush.notification( android=jpush.android( alert=u'你的吐槽信息有了新的回复~', builder_id=getBuidlerId(pusher['sound'], pusher['vibrate']), extras={'target': 'tucao'} ) ) push.platform = jpush.platform('android') push.send()
def do_push_msgs(msgs=None, mobile=None, registration_id=None, *args, **kwargs): opts = jpush.JPush(settings.JPUSH_APPKEY, settings.JPUSH_SECRET) push = opts.create_push() extras = {'mobile': mobile} push.notification = jpush.notification(alert=msgs) push.options = { "time_to_live": 86400, "apns_production": True, 'extras': extras } push.audience = jpush.audience(jpush.registration_id( registration_id)) if registration_id else jpush.all_ push.platform = jpush.all_ push.send() return True
def push_by_id(self, notification, registration_id): self.push.platform = jpush.all_ self.push.audience = jpush.audience(jpush.registration_id(registration_id)) self.push.notification = jpush.notification(alert=notification) self.__push()
import jpush as jpush _jpush = jpush.JPush('9370f4f126efb68cb51448d9', '5aa29e3617a58eca440a01a9') push = _jpush.create_push() aa = [] aa.append('0013e79cbfc') aa.append('0416fadd27b') taa = tuple(aa) #push.audience = jpush.registration_id('0013e79cbfc', '0416fadd27b') push.audience = jpush.registration_id(*taa) push.notification = jpush.notification(ios=jpush.ios( alert='#####JPush power cnvnwnovs', badge=1, sound='default')) push.message = jpush.message('abcdefg') push.options = dict(apns_production=False) push.platform = jpush.platform('ios') push.send()
# -*- coding:utf-8 -*- import jpush as jpush # from tests.conf import app_key,master_secret app_key = u'0854f04c0ed3c2d211a06b1c' master_secret = u'543b4c4eea6dce3c5adc973e' _jpush_1 = jpush.JPush( app_key, master_secret) ##1、初始化JPush,获取AppKey,Master Secret;实例化JPush, push = _jpush_1.create_push() # --------------------------------推送设备对象--------------------------- # 一个推送对象,以 JSON 格式表达,表示一条推送相关的所有信息。 # push.audience=jpush.all_ ;#audience 必填 推送设备指定;确认推送设备对象,JPush 提供了多种方式,比如:别名、标签、注册ID、分群、广播等。 push.audience = jpush.audience(jpush.registration_id( "18071adc0308b6e0dc2", ), ) # ----------------------------------------------------------------------- # ----------------------------自定义消息 发给android的实现--------------- push.message = jpush.message( "{'salists': [{'payType': 1, 'proid': 3, 'name': '燕麦谷粒多', 'count': 1, 'sinPrice': 2, 'toPrice': 2, 'chid': 162}], 'nums': 1}" ) # message 可选 消息内容体。是被推送到客户端的内容。与 notification 一起二者必须有其一,可以二者并存 # ------------------------------------------------------------------------ # --------------------------- 发送通知 给android的实现-------------------- # android = jpush.android(alert={ # "salists": [ # { # "payType": 1, # "proid": 3, # "name": "燕麦谷粒多", # "count": 1 # } # ],
import string import jpush import traceback jpush_app_key = "8c5e6ca676b8c1a9910615b5" jpush_master_secret = "c1464c6ac4502530f722c541" _jpush = jpush.JPush(jpush_app_key, jpush_master_secret) push = _jpush.create_push() # if you set the logging level to "DEBUG",it will show the debug logging. _jpush.set_logging("DEBUG") #push.audience = jpush.all_ #push.platform = jpush.all_ push.audience = jpush.audience(jpush.registration_id('191e35f7e01344072f8')) push.platform = jpush.platform('ios') ios = jpush.ios(alert="Hello, 专辑推送测试", extras={"type":"3","id":"16302530","ios":{"sound":"default","badge":1}}) android = jpush.android(alert="Hello, 专辑推送测试", priority=1, style=1, alert_type=1, extras={"type":"3","id":"16302530","ios":{"sound":"default","badge":1}}) #push.notification = jpush.notification(alert="Hello, JPush!", android=android, ios=ios) push.notification = jpush.notification(alert="Hello, JPush!", ios=ios) # pprint (push.payload) result = push.send()
import jpush as jpush _jpush = jpush.JPush('9370f4f126efb68cb51448d9', '5aa29e3617a58eca440a01a9') push = _jpush.create_push() aa = [] aa.append('0013e79cbfc') aa.append('0416fadd27b') taa = tuple(aa) #push.audience = jpush.registration_id('0013e79cbfc', '0416fadd27b') push.audience = jpush.registration_id(*taa) push.notification = jpush.notification(ios=jpush.ios(alert='#####JPush power cnvnwnovs', badge=1, sound='default')) push.message = jpush.message('abcdefg') push.options = dict(apns_production=False) push.platform = jpush.platform('ios') push.send()
def send_message(self): self._push.audience = jpush.registration_id(self._rid) self._push.send()