def pushForAlias(self, id, title, subtitle, body, link): if len(title) == 0 and len(subtitle) == 0 and len(body) == 0: return push = self._jpush.create_push() alias = [id] alias1 = {"alias": alias} push.audience = jpush.audience(alias1) ios = jpush.ios(alert={ "title": title, "subtitle": subtitle, "body": body }, sound="default", extras={'link': link}) push.notification = jpush.notification(alert=subtitle, ios=ios) push.options = { "time_to_live": 86400, "sendno": 12345, "apns_production": config.is_release } push.platform = "ios" print(push.payload) # push.send() try: response = push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn") except common.JPushFailure: print("JPushFailure") except: print("Exception")
def jpush_all(message): ''' 全体推送 * @param 推送消息 ''' _jpush = JPush(settings.JPUSH_APPKEY, settings.JPUSH_SECRET) _jpush.set_logging("DEBUG") and settings.DEBUG push = _jpush.create_push() push.options = { "time_to_live": 86400, "sendno": 12345, "apns_production": not settings.DEBUG } push.audience = jpush.all_ push.notification = jpush.notification(alert=message) push.platform = jpush.all_ try: return push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn") except common.JPushFailure: print("JPushFailure") except: print("Exception")
def jpush_push(notify_info): # base on os to deal os_type = platform.system() if(os_type == "Windows"): pass elif(os_type == "Linux"): print "Start to deal jpush push API\n" _jpush = jpush.JPush(app_key, master_secret) _jpush.set_logging("DEBUG") push = _jpush.create_push() push.audience = jpush.all_ push.notification = jpush.notification(alert=notify_info) push.platform = jpush.all_ try: response = push.send() except common.Unauthorized as e: raise common.Unauthorized("Unauthorized") logging.error('Unauthorized exception received') except common.APIConnectionException as e: raise common.APIConnectionException("Connection") logging.error('Connection exception received') except common.JPushFailure as e: logging.error('JPush failure exception received') except: logging.error('Other unhandled exception received') return 0 # self test used #jpush_push(u'hello python jpush api')
def jpush_alias(message, *args, **kwargs): ''' 别名推送 * @param 推送消息 * @param 推送别名 ''' _jpush = JPush(settings.JPUSH_APPKEY, settings.JPUSH_SECRET) _jpush.set_logging("DEBUG") and settings.DEBUG push = _jpush.create_push() push.options = { "time_to_live": 86400, "sendno": 12345, "apns_production": not settings.DEBUG } push.audience = jpush.audience({"alias": args}) push.notification = jpush.notification(alert=message) push.platform = jpush.all_ try: return push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn") except common.JPushFailure as e: raise e except Exception as e: raise e
def test_audience(self): _jpush = jpush.JPush(app_key, master_secret) push = _jpush.create_push() push.audience = jpush.audience( jpush.tag("tag1", "tag2"), jpush.alias("alias1", "alias2") ) push.notification = jpush.notification(alert="Hello world with audience!") push.platform = jpush.all_ try: response = push.send() self.assertEqual(response.status_code, 200) except common.Unauthorized as e: self.assertFalse(isinstance(e, common.Unauthorized)) raise common.Unauthorized("Unauthorized") except common.APIConnectionException as e: self.assertFalse(isinstance(e, common.APIConnectionException)) raise common.APIConnectionException("conn") except common.JPushFailure as e: self.assertFalse(isinstance(e, common.JPushFailure)) print ("JPushFailure") except: self.assertFalse(1) print ("Exception")
def jushPushMessageToJiGuang(push): try: response=push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn") except common.JPushFailure: print ("JPushFailure") except: print ("Exception") return response
def send(message, alert): android_msg = jpush.android(alert=alert) push.notification = jpush.notification(alert=message, android=android_msg) try: response = push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn error") except common.JPushFailure: print("JPushFailure") except: print("Exception")
def all(self, msg): push = self._jpush.create_push() push.audience = jpush.all_ push.notification = jpush.notification(alert=msg) push.platform = jpush.all_ try: push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn") except common.JPushFailure: print("JPushFailure")
def send( self, alert, alias: [str] = None, registration_id: [str] = None, platform=None, ): push = self._jpush.create_push() # audience if alias: push.audience = {"alias": alias} elif registration_id: push.audience = { "registration_id": [ registration_id, ] } else: raise Exception("jpush audience not found!") # platform && notification if platform == 'android': android_msg = jpush.android(alert=alert, ) push.notification = jpush.notification(android=android_msg) push.platform = platform elif platform == 'ios': ios_msg = jpush.ios(alert=alert, badge="+1") push.notification = jpush.notification(ios=ios_msg) push.platform = platform else: push.notification = jpush.notification(alert=alert) push.platform = jpush.all_ # options push.options = self.options try: response = push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn error") except common.JPushFailure: print("JPushFailure") except: print("Exception") else: return response
def sendPush2all(text): push = _jpush.create_push() # if you set the logging level to "DEBUG",it will show the debug logging. push.audience = jpush.all_ push.notification = jpush.notification(alert=text) push.platform = jpush.all_ push.message = jpush.message("msg", extras={'img_url': 'img_url'}) try: response = push.send() g_stdlogging.info("[sendPush2all]%s %s" % (text, response)) except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn error")
def all(): push = group.create_push() push.audience = jpush.all_ push.notification = jpush.notification(alert="!hello python jpush api") push.platform = jpush.all_ try: response = push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn") except common.JPushFailure: print("JPushFailure") except: print("Exception")
def send_message_to_all(self): self._push.audience = jpush.all_ try: response=self._push.send() pass except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn") except common.JPushFailure: print ("JPushFailure") raise Exception('JPush Failure') except: print ("Exception") raise Exception('Exception when pushing message')
def get_device(self, registration_id): device = self._jpush.create_device() device.options = self.options try: response = device.get_deviceinfo(registration_id) except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn error") except common.JPushFailure: print("JPushFailure") except Exception: print("Exception") else: return response
def push_all(push_msg): push = _jpush.create_push() push.audience = jpush.all_ push.notification = jpush.notification(alert=push_msg) push.platform = jpush.all_ try: response = push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn") except common.JPushFailure: print("JPushFailure") except: print("Exception")
def all(alert): lock.acquire() push = _jpush.create_push() push.audience = jpush.all_ push.notification = jpush.notification(alert=alert) push.platform = jpush.all_ try: response = push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn") except common.JPushFailure: print("JPushFailure") except: print("Exception") finally: lock.release()
def all(self, tagname, msg): """ send message to all device """ self.push.audience = jpush.all_ self.push.notification = jpush.notification(alert=msg) self.push.platform = jpush.all_ try: response = self.push.send() print '==========', response except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn") except common.JPushFailure: print("JPushFailure") except: print("Exception")
def post(self): _data = self.request.DATA alert = _data.get('alert') push = self.my_push push.audience = jpush.all_ push.notification = jpush.notification(alert=alert) push.platform = jpush.all_ try: response = push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn") except common.JPushFailure: print("JPushFailure") except: print("Exception") return Response(response)
def jpush_extras(message, alias, extras, *args, **kwargs): ''' 别名推送(附加值) * @param 推送消息 * @param 推送别名 * @param 附加值 ''' _jpush = JPush(settings.JPUSH_APPKEY, settings.JPUSH_SECRET) _jpush.set_logging("DEBUG") and settings.DEBUG push = _jpush.create_push() push.options = { "time_to_live": 86400, "sendno": int(time.time()), "apns_production": False } settings.JPUSH_OPTIONS = { "time_to_live": 86400, "sendno": 12345, "apns_production": False } push.platform = jpush.all_ ios_msg = jpush.ios(alert=str(message), sound="default", extras=extras) android_msg = jpush.android(alert=str(message), extras=extras) push.audience = jpush.audience({"alias": alias}) push.notification = jpush.notification(alert="bankeys push", ios=ios_msg, android=android_msg) try: return push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn") except common.JPushFailure as e: raise e except Exception as e: raise e
def send_temple(reg_id=None, ): app_key = '59b2f897c0e8ce252bf2dbb7' master_secret = 'a073aa2872cc228553a78ee7' _jpush = jpush.JPush(app_key, 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.notification = jpush.notification(alert="hello python jpush api") push.platform = jpush.all_ try: response = push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn error") except common.JPushFailure: print("JPushFailure") except: print("Exception")
def set_device( self, registration_id, mobile, alias, tags_add: [str] = None, tags_remove: [str] = None, ): device = self._jpush.create_device() device.options = self.options tags = {} if tags_add: tags['add'] = tags_add if tags_remove: tags['remove'] = tags_remove payload = { "tags": tags, "alias": alias, "mobile": mobile, } try: response = device.set_deviceinfo(registration_id=registration_id, entity=payload) except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn error") except common.JPushFailure: print("JPushFailure") except Exception: print("Exception") else: return response
def send(self, message, *args, **kwargs): _jpush = JPush(settings.JPUSH_APPKEY, settings.JPUSH_SECRET) _jpush.set_logging("DEBUG") and settings.DEBUG alias = kwargs.get('alias') extra = kwargs.get('extra') push = _jpush.create_push() push.options = settings.JPUSH_OPTIONS push.options['sendno'] = self.sendno push.platform = jpush.all_ # if alias: # pass # # if extra: # pass ios_msg = jpush.ios(alert=str(message), sound="default", extras=extra) android_msg = jpush.android(alert=str(message), extras=extra) push.audience = jpush.audience({"alias": alias}) push.notification = jpush.notification(alert="bankeys push.", ios=ios_msg, android=android_msg) try: return push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn") except common.JPushFailure as e: raise e except Exception as e: raise e
def get_device_temple(alias=None, reg_id=None): app_key = '59b2f897c0e8ce252bf2dbb7' master_secret = 'a073aa2872cc228553a78ee7' _jpush = jpush.JPush(app_key, master_secret) device = _jpush.create_device() try: if alias: response = device.get_aliasuser(alias=alias, ) elif reg_id: response = device.get_deviceinfo(registration_id=reg_id) else: raise Exception("error alias or reg_id not found") print(response) except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn error") except common.JPushFailure: print("JPushFailure") except Exception: print("Exception") else: return response
def get_device_cuser(alias=None, reg_id=None): app_key = '568a31c38959e0741704d915' master_secret = '66f517e9008515dac6f4bfd5' _jpush = jpush.JPush(app_key, master_secret) device = _jpush.create_device() try: if alias: response = device.get_aliasuser(alias=alias, ) elif reg_id: response = device.get_deviceinfo(registration_id=reg_id) else: raise Exception("error alias or reg_id not found") print(response) except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn error") except common.JPushFailure: print("JPushFailure") except Exception: print("Exception") else: return response
import jpush from jpush import common _jpush = jpush.JPush('f7b11a3dbd7677d41cd77cdb', '739fd6536b1df8e6eb825934') 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.notification = jpush.notification(alert="hello python jpush api") push.platform = jpush.all_ try: response = push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn error") except common.JPushFailure: print("JPushFailure") except: print("Exception")