예제 #1
0
    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
예제 #2
0
def pushAllIos(request):
    if request.method == 'POST':
        title = request.POST.get('title')
        content = request.POST.get('content')
        print(title, content)
        print(type(title), type(content))
        ios_jpush = jpush.JPush(ios_app_key, ios_master_secret)
        push = ios_jpush.create_push()
        ios_jpush.set_logging("DEBUG")
        push.audience = jpush.all_
        raw = {"body": content, "title": title}
        ios_msg = jpush.ios(alert=raw, badge="+1", sound="beep.wav")
        push.notification = jpush.notification(alert=content, ios=ios_msg)
        push.platform = jpush.all_
        push.options = {"apns_production": False}
        try:
            response = push.send()
            print(response, type(response))
            return render(request, 'success.html')
        except common.Unauthorized:
            return render(request, 'failed.html', {"err_msg": "验证失败!"})
            # raise common.Unauthorized("Unauthorized")  # AppKey,Master Secret 错误,验证失败必须改正。
        except common.APIConnectionException:
            return render(request, 'failed.html', {"err_msg": "请求超时!"})
            # raise common.APIConnectionException("conn error")  # 包含错误的信息:比如超时,无网络等情况。
        except common.JPushFailure:
            return render(request, 'failed.html', {"err_msg": "请求出错!"})
            # print("JPushFailure")  # 请求出错,参考业务返回码。
        except:
            return render(request, 'failed.html', {"err_msg": "其他异常!"})
            # print("Exception")
    return render(request, 'iospush.html')
예제 #3
0
def pushAllAndroid(request):
    if request.method == 'POST':
        title = request.POST.get('title')
        content = request.POST.get('content')
        print(title, content)
        print(type(title), type(content))
        and_jpush = jpush.JPush(and_app_key, and_master_secret)
        push = and_jpush.create_push()
        and_jpush.set_logging("DEBUG")
        push.audience = jpush.all_
        android_msg = jpush.android(alert=content, title=title)
        push.notification = jpush.notification(alert=content,
                                               android=android_msg)
        push.platform = jpush.all_
        try:
            response = push.send()
            print(response, type(response))
            return render(request, 'success.html')
        except common.Unauthorized:
            return render(request, 'failed.html', {"err_msg": "验证失败!"})
            # raise common.Unauthorized("Unauthorized")  # AppKey,Master Secret 错误,验证失败必须改正。
        except common.APIConnectionException:
            return render(request, 'failed.html', {"err_msg": "请求超时!"})
            # raise common.APIConnectionException("conn error")  # 包含错误的信息:比如超时,无网络等情况。
        except common.JPushFailure:
            return render(request, 'failed.html', {"err_msg": "请求出错!"})
            # print("JPushFailure")  # 请求出错,参考业务返回码。
        except:
            return render(request, 'failed.html', {"err_msg": "其他异常!"})
            # print("Exception")
    return render(request, 'androidpush.html')
예제 #4
0
 def alias(self, msg, alias):
     push = self._jpush.create_push()
     push.audience = jpush.audience({'alias': alias})
     push.platform = jpush.all_
     push.notification = jpush.notification(alert=msg)
     print(push.payload)
     push.send()
예제 #5
0
def options():
    push = _jpush.create_push()
    push.audience = jpush.all_
    push.notification = jpush.notification(alert="Hello, world!")
    push.platform = jpush.all_
    push.options = {"time_to_live":86400, "sendno":12345,"apns_production":True}
    push.send()
예제 #6
0
 def push_with_alias(self, msg, alias=None, extra=None):
     if self.call_remote:
         self.call_in_remote_server('push_with_alias',
                                    msg=msg,
                                    alias=alias,
                                    extra=extra)
         return
     push = self._jpush.create_push()
     push.platform = jpush.all_
     if alias:
         push.audience = jpush.audience({'alias': alias})
     else:
         push.audience = jpush.all_
     android = jpush.android(alert=msg, extras=extra)
     ios = jpush.ios(alert="%s\n%s: %s" %
                     (extra['title'], extra['sender'], extra['content']))
     push.notification = jpush.notification(alert=msg,
                                            android=android,
                                            ios=ios)
     print(push.payload)
     retry_time = 3
     while retry_time:
         try:
             push.send()
             return
         except:
             retry_time -= 1
예제 #7
0
 def post(self, request):
     alert = self.request.data.get('alert', None)
     extras_data = self.request.data.get('extras', None)
     production = self.request.data.get('production', True)
     push = self.my_push
     push.audience = jpush.all_
     ios = jpush.ios(alert=alert, extras=extras_data, badge="+1")
     android = jpush.android(alert=alert, extras=extras_data)
     push.notification = jpush.notification(ios=ios, android=android)
     push.message = jpush.message("hi", extras=extras_data)
     push.platform = jpush.all_
     push.options = {
         "time_to_live": 86400,
         "sendno": 12345,
         "apns_production": production
     }
     try:
         response = push.send()
     except jpush.common.Unauthorized:
         raise jpush.common.Unauthorized("Unauthorized")
     except jpush.common.APIConnectionException:
         raise jpush.common.APIConnectionException("conn")
     except jpush.common.JPushFailure:
         raise ("JPushFailure", )
     except:
         raise ("Exception", )
     return Response(response.payload)
예제 #8
0
def jpushMessageWithAlias(alias, msg, action):
    push = jpushCreateClient()
    push.audience = jpush.audience(jpush.alias(alias))
    push.notification = jpush.notification(
        android=jpush.android(alert=action, extras=msg))
    resp = jushPushMessageToJiGuang(push)
    return resp
예제 #9
0
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
예제 #10
0
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")
예제 #11
0
파일: test_audience.py 프로젝트: zjn0224/mo
    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")
예제 #12
0
 def test_basic_push(self):
     self.push.platform = platform("ios", "android")
     self.push.audience = audience()
     with self.assertRaises(ValidateError):
         self.push.send_validate()
     self.push.notification = notification(alert="alert")
     self.push.send_validate()
예제 #13
0
def loginhtml(request):

    _jpush = jpush.JPush(u'47cd8c54b7d852e01ffb82ac', u'5838452a357f53a742fb509d')
    _jpush.set_logging("DEBUG")

    push = _jpush.create_push()
    push.audience = jpush.all_
    push.notification = jpush.notification(alert="!hello python jpush api")
    push.platform = jpush.all_
    push.options = {
        "apns_production": "false"
    }
    try:
        response = push.send()
        print("send")
    except common.Unauthorized:
        print("Unauthorized")
        raise common.Unauthorized("Unauthorized")
    except common.APIConnectionException:
        raise common.APIConnectionException("conn")
    except common.JPushFailure:
        print("JPushFailure")
    except:
        print("Exception")

    return render(request, 'account/login.html')
예제 #14
0
def AsyncSetProprtyRepair(apiKey, secretKey, currentCommunityId,
                          custom_content, message, customTitle, tagSuffix):
    #     import sys
    #     default_encoding = 'utf-8'
    #     if sys.getdefaultencoding() != default_encoding:
    #         reload(sys)
    #         sys.setdefaultencoding(default_encoding)
    tagName = tagSuffix + str(currentCommunityId)
    _jpush = jpush.JPush(apiKey, secretKey)
    pushExtra = {'pTitle': customTitle}
    pushExtra.update(custom_content)
    #    pushExtra = custom_content
    push = _jpush.create_push()
    push.audience = jpush.all_
    push.audience = jpush.audience(jpush.tag(tagName), )
    push.notification = jpush.notification(
        ios=jpush.ios(alert=message.encode('utf-8'),
                      badge="+1",
                      extras=pushExtra),
        android=jpush.android(message, customTitle, None, pushExtra))
    push.options = {
        "time_to_live": 86400,
        "sendno": 9527,
        "apns_production": PUSH_STATUS
    }
    push.platform = jpush.all_
    push.send()
예제 #15
0
def test_pushMessage_to_all(message="123"):
    _jpush = jpush.JPush(app_key, master_secret)
    push = _jpush.create_push()
    push.audience = jpush.all_
    push.notification = jpush.notification(alert=message)
    push.platform = jpush.all_
    push.send()
예제 #16
0
def jpushios(obj):
    _jpush = jpush.JPush(app_key, master_secret)
    push = _jpush.create_push()
    push.audience = jpush.all_

    name = Name(obj)
    project = Project(obj)
    content = obj.content
    version = Version(obj)
    urgency = Urgency(obj)
    module = Module(obj)
    distribter = Distribter(obj)

    msgdict = [
        name, u'在', project, version, u'版本', module, u'中', u'发现一个', urgency,
        u'问题', u':', content
    ]
    msg = ''.join(msgdict)

    push.audience = jpush.audience(jpush.alias(distribter))
    ios_msg = jpush.ios(alert=msg,
                        badge="+1",
                        sound="a.caf",
                        extras={'k': 'v'})
    push.options = {
        "time_to_live": 86400,
        "sendno": 12345,
        "apns_production": False
    }
    push.notification = jpush.notification(alert="", ios=ios_msg)
    push.platform = jpush.platform("ios")
    push.send()
예제 #17
0
    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()
예제 #18
0
파일: push.py 프로젝트: marscj/flight
def send_message(title, **kwargs):
    push = _jpush.create_push()
    push.audience = jpush.audience(kwargs)
    push.options = {"apns_production": False}
    push.notification = jpush.notification(
        alert={"title": title},
        android={"extras": {
            "android-key1": "android-value1"
        }},
        ios={
            "sound": "sound.caf",
            "badge": "+1",
            "extras": {
                "ios-key1": "ios-value1"
            }
        })
    push.platform = jpush.all_
    try:
        response = push.send()
    except jpush.common.Unauthorized:
        raise jpush.common.Unauthorized("Unauthorized")
    except jpush.common.APIConnectionException:
        raise jpush.common.APIConnectionException("conn")
    except jpush.common.JPushFailure:
        print("JPushFailure")
    except:
        print("Exception")
예제 #19
0
def jp_notification(alert, big_text, k1, v1, type_num=0, jg_ids=[]):
    push = _jpush.create_push()
    if jg_ids:
        push.audience = {'registration_id': jg_ids}
    else:
        push.audience = jpush.all_
    push.platform = jpush.all_
    ios = jpush.ios(alert=alert,
                    sound="a.caf",
                    extras={
                        k1: v1,
                        'type': type_num
                    })
    android = jpush.android(alert=alert.get('body'),
                            title=alert.get('title'),
                            priority=1,
                            style=1,
                            alert_type=1,
                            big_text=big_text,
                            extras={
                                k1: v1,
                                'type': type_num
                            })
    push.notification = jpush.notification(alert=alert,
                                           android=android,
                                           ios=ios)
    result = push.send()
    return result
예제 #20
0
 def push_extra(self,
                extra,
                msg='test',
                platform='all',
                audience=jpush.all_):
     p = {
         'all': jpush.all_,
         'android': jpush.platform('android'),
         'ios': jpush.platform('ios')
     }
     if audience != jpush.all_:
         audience = jpush.audience(jpush.alias(str(audience)))
     try:
         msg = msg.encode('utf-8')
     except:
         pass
     a_msg = jpush.android(alert=msg, extras=extra)
     i_msg = jpush.ios(alert=msg, extras=extra)
     self.push = self._jpush.create_push()
     self.push.audience = audience
     self.push.platform = p.get(platform)
     self.push.notification = jpush.notification(alert=msg,
                                                 android=a_msg,
                                                 ios=i_msg)
     return self.push.send()
예제 #21
0
def pushsinglemsg(apptype, body, receiver):
    key = 'bb9fc37f914d94589c6d7c4d'
    secret = '0b058bd331eae435fa38f20e'
    if apptype == 2:
        key = '382c5d880cae31ec81df46ff'
        secret = 'ac37c4c44a0b83539d469464'
    elif apptype == 3:
        key = '28e20ce5dcfd49511309806a'
        secret = 'b05bdc47c2cb686850a6c766'
    elif apptype == 4:
        key = '3c7971b2e03ef0f0df5c70b2'
        secret = 'ff57774954b9ed1f0771cef4'
    _jpush = jpush.JPush(key, secret)
    push = _jpush.create_push()
    push.audience = jpush.audience(jpush.alias(receiver))

    ios_msg = jpush.ios(alert=body,
                        badge="+1",
                        sound="a.caf",
                        extras={'k1': 'v1'})
    android_msg = jpush.android(alert=body)
    push.notification = jpush.notification(alert=body,
                                           android=android_msg,
                                           ios=ios_msg)

    push.platform = jpush.all_
    push.options = {"apns_production": False}
    re = push.send()
    print re
예제 #22
0
    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")
예제 #23
0
파일: Push.py 프로젝트: HannahCC/QianXun
 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)
예제 #24
0
    def save_model(self, request, obj, form, change):
        obj.save()
        '''x = xinge.XingeApp(2100130704, '82bbeb41db7f303a0f0f6521ddf23558')
        iosx=xinge.XingeApp(2200130705, 'd3156bf69ce4357382bfc8a93920582f')
        msg=xinge.Message()
        msg.type = xinge.Message.TYPE_NOTIFICATION
        msg.title = obj.title.encode('utf-8')
        msg.content = obj.content.encode('utf-8')
        msg.expireTime = 86400
        #msg.sendTime = '2012-12-12 18:48:00'
        # 自定义键值对,key和value都必须是字符串,非必须
        msg.custom = {'type':'2', 'id':str(obj.id)}
        style = xinge.Style(2, 1, 1, 1, 0)
        msg.style = style
        iosmsg=xinge.MessageIOS()
        iosmsg.alert = obj.title.encode('utf-8')
        iosmsg.custom = {'type':'2', 'id':str(obj.id)}
        iosmsg.sound='default'
        x.PushAllDevices(0, msg)
        iosx.PushAllDevices(0, iosmsg, 1)'''
        _jpush = jpush.JPush('65461ea95bac07cb5349907a', '5238c85d2eacd9cc6b80a225')
        push = _jpush.create_push()
        push.audience=jpush.all_
        ios_msg = jpush.ios(alert=obj.title.encode('utf-8'), badge="+1", sound="a.caf",extras={'type':'2', 'id':str(obj.id)})
        android_msg = jpush.android(alert=obj.title,extras={'type':'2', 'id':str(obj.id)})

        push.notification = jpush.notification(android=android_msg, ios=ios_msg)
        push.platform = jpush.all_
        push.options = {"time_to_live":86400, "sendno":12345,"apns_production":True}
        push.send()
예제 #25
0
    def send_push(cls,
                  platform=jpush.all_,
                  audience=None,
                  notification=None,
                  message=None,
                  apns_production=False):
        push.audience = audience
        ios = jpush.ios(alert=notification, sound=need_sound)
        android = jpush.android(alert=notification, priority=1, style=1)
        push.notification = jpush.notification(ios=ios, android=android)
        push.options = {
            "apns_production": apns_production,
        }
        push.platform = platform
        # push.message = message
        try:
            response = push.send()
        except jpush.common.Unauthorized:
            raise jpush.common.Unauthorized("Unauthorized")
        except jpush.common.APIConnectionException:
            raise jpush.common.APIConnectionException("conn")
        except jpush.common.JPushFailure:
            print("JPushFailure")
        except:
            print("Exception")


# JPushExtend.send_push(platform=jpush.all_, audience= "all", notification="My First Push")
 def push_by_reg_id(self, msg, reg_id):
     push = self._jpush.create_push()
     push.audience = {'registration_id': [reg_id]}
     push.notification = jpush.notification(alert=msg)
     push.platform = jpush.all_
     response = push.send()
     return response
예제 #27
0
def jpushMessageAllUser(action, msg):
    push = jpushCreateClient()
    push.audience = jpush.all_
    push.notification = jpush.notification(
        android=jpush.android(alert=action, extras=msg))
    resp = jushPushMessageToJiGuang(push)
    return resp
예제 #28
0
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')
예제 #29
0
def push_message(tags, message, platform=jpush.all_, extras=None):
    push.audience = jpush.all_ if tags == jpush.all_ else jpush.audience(
        {"tag": tags})
    push.notification = jpush.notification(
        alert=message,
        ios=jpush.ios(message, extras=extras),
        android=jpush.android(message, extras=extras),
        winphone=jpush.winphone(message, extras=extras))
    push.message = jpush.message(message, extras=extras)
    push.platform = platform
    try:
        response = push.send()
    except jpush.common.Unauthorized as e:
        logging.error("JPush Unauthorized: %s" % str(e))
    except jpush.common.APIConnectionException as e:
        logging.error("JPushconn error: %s" % str(e))
    except jpush.common.JPushFailure as e:
        logging.error("JPush Failure: %s" % str(e))
    except Exception as e:
        raise e
    else:
        logging.info(response.payload)
        if response.status_code == 200 and response.payload['sendno'] == '0':
            return True
    return False
예제 #30
0
        def _push_msg(message, device_id):
            app_key = 'app_key'
            master_secret = 'master_key'

            _jpush = jpush.JPush(app_key, master_secret)
            push = _jpush.create_push()
            # push.audience = jpush.audience([{"registration_id":device_id}])
            push.audience = {'registration_id': [device_id]}
            # push.audience = device_id
            android_msg = jpush.android(
                message,
                None,
                None,
                {
                    "msg": message,  # 强行套用app中notification的相关格式
                    "status": 0
                }
            )
            ios_msg = jpush.ios(
                message,
                None,
                None,
                {
                    "msg": message,  # 强行套用app中notification的相关格式
                    "status": 0
                }
            )
            push.notification = jpush.notification("hello jpush", ios_msg, android_msg, None)
            # push.options = {"time_to_live": 86400, "sendno": 12345, "apns_production":True}
            push.options = {"time_to_live": 86400, "apns_production": True}
            push.platform = jpush.platform("all")

            push.send()
예제 #31
0
def AsyncAddressAuditSubmit(apiKey, secretKey, alias, user_id, customContent,
                            pushContent, pushTitle):
    from users.models import User
    uObectj = User.objects.get(user_id=long(user_id))
    userCache = uObectj.user_handle_cache
    addrCache = uObectj.addr_handle_cache
    uObectj.addr_handle_cache = (int(addrCache) + 1) % 1000
    uObectj.save()
    _jpush = jpush.JPush(apiKey, secretKey)
    pushExtra = {'pTitle': pushTitle}
    pushExtra.update(customContent)
    #    pushExtra = customContent
    currentAlias = alias + str(user_id)
    push = _jpush.create_push()
    push.audience = jpush.all_
    push.audience = jpush.audience(jpush.alias(currentAlias), )
    push.notification = jpush.notification(
        ios=jpush.ios(alert=pushContent.encode('utf-8'),
                      badge="+1",
                      extras=pushExtra),
        android=jpush.android(pushContent, pushTitle, None, pushExtra))
    push.options = {
        "time_to_live": 86400,
        "sendno": 9527,
        "apns_production": PUSH_STATUS
    }
    push.platform = jpush.all_
    push.send()
예제 #32
0
def send_users_base_regid(reg_id, body, images='', extras=None):
    _jpush = jpush.JPush(setting.jpush_key, setting.jpush_secret)
    push = _jpush.create_push()
    alias1 = {"registration_id": [reg_id]}
    push.audience = jpush.audience(alias1)
    if extras:
        extras['images'] = images
        ios_msg = jpush.ios(alert=body,
                            badge="+1",
                            sound="a.caf",
                            content_available=True,
                            mutable_content=True,
                            extras=extras)
        android_msg = jpush.android(alert=body,
                                    style=3,
                                    big_pic_path=images,
                                    extras=extras)
    else:
        ios_msg = jpush.ios(alert=body,
                            badge="+1",
                            sound="a.caf",
                            content_available=True,
                            mutable_content=True)
        android_msg = jpush.android(alert=body)
    push.notification = jpush.notification(alert=body,
                                           android=android_msg,
                                           ios=ios_msg)

    push.platform = jpush.all_
    push.options = {"apns_production": True}

    result = push.send()
    # result = push.send_validate()
    print result.payload
예제 #33
0
def send_users_base_tags(tags, body, images='', extras={'link': ''}):
    _jpush = jpush.JPush(setting.jpush_key, setting.jpush_secret)
    push = _jpush.create_push()
    push.audience = jpush.audience()
    push.audience['tag'] = tags
    push.platform = jpush.all_

    if extras:
        extras['images'] = images
        ios_msg = jpush.ios(alert=body,
                            badge="+1",
                            sound="a.caf",
                            content_available=True,
                            mutable_content=True,
                            extras=extras)
        android_msg = jpush.android(alert=body,
                                    style=3,
                                    big_pic_path=images,
                                    extras=extras)
    else:
        ios_msg = jpush.ios(alert=body,
                            badge="+1",
                            sound="a.caf",
                            content_available=True,
                            mutable_content=True)
        android_msg = jpush.android(alert=body)
    push.notification = jpush.notification(alert=body,
                                           android=android_msg,
                                           ios=ios_msg)
    push.options = {"apns_production": True}

    result = push.send()
    print result.payload
예제 #34
0
 def send(self, msg_content, title, content_type, extras, tag=None):
     # self.push_android = _jpush.create_push()
     # self.push_ios = _jpush.create_push()
     # self.push.platform = jpush.all_
     self.push_android.platform = "android"
     self.push_ios.platform = "ios"
     if tag:
         self.push_android.audience = jpush.audience(
             # jpush.tag("p_44","p_45")
             jpush.tag(tag)
         )
         self.push_ios.audience = jpush.audience(
             jpush.tag(tag)
         )
     else:
         self.push_android.audience = jpush.all_
         self.push_ios.audience = jpush.all_
     self.push_android.message = jpush.message(msg_content=msg_content, title=title, content_type=content_type, extras=json.dumps(extras))
     self.push_ios.notification = jpush.notification(alert=msg_content)
     try:
         if PUSH_ON:
             self.push_android.send()
             self.push_ios.send()
     except Exception as e:
         print e
예제 #35
0
    def iso_android(self, tagname, msg):
        """
        just send message to iso and android
        :param tagname:
        :param msg:
        :return:
        """
        try:
            ios = jpush.ios(alert=str(msg), sound='default')
            android = jpush.android(alert=str(msg))

            self.push.audience = jpush.audience(jpush.tag(tagname))
            self.push.notification = jpush.notification(alert=str(msg),
                                                        android=android,
                                                        ios=ios)
            self.push.options = {
                "time_to_live": 86400,
                "apns_production": IS_IOS_DEV
            }
            self.push.platform = jpush.all_
            try:
                response = self.push.send()
                print 'IOS_ANDROID RESPONSE>>>', response
            except Exception, e:
                print 'IOS_ANDROID ERROR>>>', e
        except:
            pass
예제 #36
0
파일: Push.py 프로젝트: NobodyWHU/QianXun-1
 def broadcast_by_tags(self, notification, *tag_list):
     self.push.platform = jpush.all_
     if len(tag_list) > 0:
         self.push.audience = jpush.audience(jpush.tag(tag_list),)
     else:
         self.push.audience = jpush.all_
     self.push.notification = jpush.notification(alert=notification)
     self.__push()
예제 #37
0
파일: views.py 프로젝트: lyzpokemon/Biu
def send_msg(username, target, title, msg):
	_jpush = jpush.JPush(app_key, master_secret)
	push = _jpush.create_push()
	push.audience = jpush.audience(jpush.alias(target))
	android_msg = jpush.android(alert=msg, title=title, extras={'username': username})
	push.notification = jpush.notification(alert=msg, android=android_msg)
	push.platform = jpush.all_
	push.send()
예제 #38
0
def push_broadcast(_jpush, title, content):
	push = _jpush.create_push()
	push.audience = jpush.all_
	push.notification = jpush.notification(alert=content)
	push.notification['android'] = {'title':title}
	push.platform = jpush.all_
	push.options = {'time_to_live':3600}
	push.send()
예제 #39
0
파일: views.py 프로젝트: stanremix/sx2
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()
예제 #40
0
def sent_msg_to_people(alias,alert):
    _jpush = jpush.JPush(app_key, master_secret)    
    push = _jpush.create_push()
    push.audience = jpush.audience(
                jpush.alias(alias)
            )
    push.notification = jpush.notification(alert=alert)
    push.platform = jpush.all_
    srecv = push.send()
    return srecv
예제 #41
0
파일: push.py 프로젝트: jarrahwu/TAPI
    def send_notification(self, title, alert, alias=None, **kwargs):
        android = jpush.android(alert=alert, title=title, extras=kwargs)

        if alias is not None:
            self.push.audience = jpush.audience(jpush.alias(*alias))

        # ios = None
        self.push.notification = jpush.notification(alert=alert, android=android)
        self.push.platform = jpush.platform('android', 'ios')
        self.push.send()
예제 #42
0
파일: views.py 프로젝트: stanremix/sx2
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()
예제 #43
0
파일: views.py 프로젝트: whataa/NoticeWeb
def push(num):
    import jpush as jpush
    app_key = u'd6bdfb193bf44f78d78300ee'
    master_secret = u'1ec81f183f8fcf37fec1ca90'
    _jpush = jpush.JPush(app_key, master_secret)

    push = _jpush.create_push()
    push.audience = jpush.all_
    push.notification = jpush.notification(alert="update: " + str(num))
    push.platform = jpush.all_
    push.send()
예제 #44
0
 def send2(self, msg_content, title, content_type, extras, tag=None, alias=None):
     """
     增加alias发送方法
     by: 尚宗凯 at:2015-04-09
     修改alias用法
     by: 尚宗凯 at:2015-04-09
     ios通知无声
     by:尚宗凯 at:2015-04-10
     解决ios无法收到推送的问题
     by:尚宗凯 at:2015-04-15
     修改ios alert内容
     by:尚宗凯 at:2015-04-16
     修改ios 推送增加字段
     by:尚宗凯 at:2015-04-22
     修改ios 推送alias
     by:尚宗凯 at:2015-04-23
     增加badge+1
     by:尚宗凯 at:2015-04-29
     如果alias为空则不发送
     by:尚宗凯 at:2015-04-04
     极光推送改为+1
     by:尚宗凯 at:2015-05-18
     """
     if not alias:
         return False
     self.push_android.platform = "android"
     self.push_ios.platform = "ios"
     if ENVIRONMENT == 'aliyun':
         self.push_ios.options = {"apns_production":True}     #生产环境
     else:
         self.push_ios.options = {"apns_production":False}    #开发环境
     if tag:
         self.push_android.audience = jpush.audience(
             # jpush.tag("p_44","p_45")
             jpush.tag(tag)
         )
         self.push_ios.audience = jpush.audience(
             jpush.tag(tag)
         )
     elif alias:
         self.push_android.audience = jpush.alias(
             alias
         )
         self.push_ios.audience = jpush.alias(
             alias
         )
     # else:
     #     self.push_android.audience = jpush.all_
     #     self.push_ios.audience = jpush.all_
     self.push_android.message = jpush.message(msg_content=msg_content, title=title, content_type=content_type, extras=json.dumps(extras))
     self.push_ios.sound_disable=True
     ios_msg = jpush.ios(alert=u'%s,%s'%(title, msg_content), extras=extras, badge="+1")
     self.push_ios.notification = jpush.notification(alert=u'%s,%s'%(title, msg_content), ios=ios_msg)
     self.start()
예제 #45
0
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()
예제 #46
0
def push_news(artical_id, header):
    server = jpush.JPush(app_key, master_secret)
    push = server.create_push()
    push.audience = jpush.all_
    android_msg = jpush.android(alert=header,
                                title="ArsenalNews",
                                extras={"Header": header,
                                        "ArticalId": artical_id})
    push.notification = jpush.notification(alert="Hello, Arsenal",
                                           android=android_msg)
    push.platform = jpush.platform("android")
    push.send()
예제 #47
0
파일: utils.py 프로젝트: lisongjian/lo
def push(phone, msg):
    import jpush as jpush
    from conf import app_key, master_secret
    _jpush = jpush.JPush(app_key, master_secret)

    push = _jpush.create_push()
    push.audience = jpush.audience(
                jpush.alias(phone)
            )
    push.notification = jpush.notification(alert=msg)
    push.platform = jpush.all_
    push.message = {"msg_content":'test'}
    push.send()
예제 #48
0
파일: views.py 프로젝트: stanremix/sx2
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()
예제 #49
0
def pushToUser(userId,userName,trendId):
    userId_str = str(userId)
    _jpush = jpush.JPush(AK, SK)
    _jpush.set_logging("DEBUG")
    push = _jpush.create_push()
    push.audience = jpush.audience(
                jpush.alias(userId_str)
            )
    andriod_msg = jpush.android(alert=userName+"评论了你的动态",title = "新消息" , extras = {'trendId':str(trendId)})
    push.notification = jpush.notification(alert="新消息",android=andriod_msg)
    push.platform = jpush.all_
    print (push.payload)
    push.send()
예제 #50
0
파일: message.py 프로젝트: jpush/jbox
def send_direct_to_channel(channel):
    developer = get_developer()
    if developer is None:
        return jsonify({}), 404

    channel_to_post = Channel.query.filter_by(developer_id=developer.id,channel=channel).first()
    print(channel_to_post)
    if channel_to_post is None:
        return jsonify({}), 404
    message_url = ""
    if 'url' in request.json:
       message_url = request.json['url']
    _jpush = jpush.JPush(u'1c29cb5814072b5b1f8ef829', u'b46af6af73ee8f9480d4edad')
    push = _jpush.create_push()
    _jpush.set_logging("DEBUG")
    push.audience = jpush.audience(
        jpush.tag(developer.dev_key + '_' + channel)
    )
    android_msg = jpush.android(alert=request.json['title'], extras={'title': request.json['title'],
                                                                     'message': request.json['message']})
    ios_msg = jpush.ios(alert=request.json['title'], extras={'title': request.json['title'],
                                                             'message': request.json['message']})

    push.notification = jpush.notification(alert=request.json['title'], android=android_msg, ios=ios_msg)
    push.message = jpush.message(msg_content=request.json['message'], title=request.json['title'], content_type="tyope",
                                 extras={'dev_key': developer.dev_key, 'channel': channel,
                                         'datetime': int(time.time()),
                                         'icon': "",
                                         'url': message_url,
                                         'integration_name': ""})

    # push.options = {"time_to_live": 864000, "sendno": 12345, "apns_production": False}
    push.options = {"time_to_live": 864000, "sendno": 12345, "apns_production": True}
    push.platform = jpush.all_

    try:
        response = push.send()
        print(response)
    except common.Unauthorized:
        print("Unauthorized")
        return jsonify({'error': 'Unauthorized request'}), 401
    except common.APIConnectionException:
        print('connect error')
        return jsonify({'error': 'connect error, please try again later'}), 504
    except common.JPushFailure:
        print("JPushFailure")
        response = common.JPushFailure.response
        return jsonify({'error': 'JPush failed, please read the code and refer code document'}), 500
    except:
        print("Exception")
    return jsonify({}), 200
예제 #51
0
    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 test_winphone(self):
     self.assertEqual(
         jpush.notification(
             winphone=jpush.winphone(
                 alert="Hello",
                 extras={'k3': 'v3'}
             )
         ),
         {
             'winphone': {
                 'extras': {'k3': 'v3'},
                 'alert': 'Hello'
             }
         }
     )
 def test_android(self):
     self.assertEqual(
         jpush.notification(
             android=jpush.android(
                 alert="Hello",
                 extras={'k2': 'v2'}
             )
         ),
         {
             'android': {
                 'extras': {'k2': 'v2'},
                 'alert': 'Hello'
             }
         }
     )
예제 #54
0
 def all(self):
     self.push.audience = jpush.all_
     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(self, _jpush, targets, data):
        '''
        '''
        targets = [str(target) for target in targets]
        # TODO: 测试环境写成愿愿的id
#         targets = ["341255"]
        push = _jpush.create_push()
        push.audience = jpush.audience(
                            jpush.tag(*targets)
                        )
        push.notification = jpush.notification(alert=data['content'],
                                               ios=jpush.ios(alert=data['content'], badge=1, sound='default', extras=data['extras']),
                                               android=jpush.android(alert=data['content'], extras=data['extras'])
                                               )
        push.options = jpush.options({'sendno': 123456, 'apns_production': True, 'big_push_duration': 0})
        push.platform = jpush.all_
        push.send() 
 def test_iossilent(self):
     self.assertEqual(
         jpush.notification(
             ios=jpush.ios(
                 alert="Hello",
                 badge="+1",
                 extras={'k1': 'v1'},
                 sound_disable=True
             )
         ),
         {
             'ios': {
                 'extras': {'k1': 'v1'},
                 'badge': '+1',
                 'alert': 'Hello'
             }
         }
     )
 def test_ios(self):
     self.assertEqual(
         jpush.notification(
             ios=jpush.ios(
                 alert="Hello",
                 badge="+1",
                 sound="a.caf",
                 extras={'k1': 'v1'}
             )
         ),
         {
             'ios': {
                 'sound': 'a.caf',
                 'extras': {'k1': 'v1'},
                 'badge': '+1',
                 'alert': 'Hello'
             }
         }
     )
예제 #58
0
 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)
예제 #59
0
파일: utils.py 프로젝트: 384782946/MyBlog
def nofity():
    msg = request.args.get('msg')
    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=msg)
    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")
    return 'notify success'