Example #1
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
Example #2
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
Example #3
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()
Example #4
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
Example #5
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()
Example #6
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)
     self.push.options = {
         "time_to_live": 86400,
         "sendno": 12345,
         "apns_production": False
     }
     for i in range(5):
         try:
             self.push.send()
             return True
         except Exception, e:
             print e.__repr__()
Example #7
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")
Example #8
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
Example #9
0
def article_create_notification(title, article_id):
    '''
    文章发布notification
    :param title:
    :param article_id:
    :return:
    '''
    print("hello!")
    push = _jpush.create_push()

    push.audience = jpush.all_
    push.platform = jpush.all_

    ios = jpush.ios(alert="Hello, IOS JPush!",
                    sound="a.caf",
                    extras={'k1': 'v1'})
    android = jpush.android(
        alert="title:{},id:{}".format(title, article_id),
        priority=1,
        style=1,
        alert_type=1,
    )

    push.notification = jpush.notification(alert="Hello, JPush!",
                                           android=android,
                                           ios=ios)

    push.send()
Example #10
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()
Example #11
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
Example #12
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")
Example #13
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()
Example #14
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
Example #15
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)
Example #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()
Example #17
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()
Example #18
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()
Example #19
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')
Example #20
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
Example #21
0
def silent():
    push = _jpush.create_push()
    push.audience = jpush.all_
    ios_msg = jpush.ios(alert="Hello, IOS JPush!", badge="+1", extras={'k1':'v1'}, sound_disable=True)
    android_msg = jpush.android(alert="Hello, android msg")
    push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg)
    push.platform = jpush.all_
    push.send()
Example #22
0
    def __init__(self, msg='金指投', extras={}):

        self.msg = msg
        self.ios_msg = jpush.ios(alert=msg,
                                 badge="+1",
                                 sound="a.caf",
                                 extras=extras)
        self.android_msg = jpush.android(alert=msg, extras=extras)
        self.push = jpush.JPush(settings.JAK, settings.JMS).create_push()
Example #23
0
def platfrom_msg():
    push = _jpush.create_push()
    push.audience = jpush.all_
    ios_msg = jpush.ios(alert="Hello, IOS JPush!", badge="+1", sound="a.caf", extras={'k1':'v1'})
    android_msg = jpush.android(alert="Hello, android msg")
    push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg)
    push.message=jpush.message("content",extras={'k2':'v2','k3':'v3'})
    push.platform = jpush.all_
    push.send()
Example #24
0
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()
Example #25
0
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()
Example #26
0
    def __init__(self, msg='金指投', extras={}):

        self.msg = msg
        self.ios_msg = jpush.ios(
            alert=msg , 
            badge="+1", 
            sound="a.caf", 
            extras=extras
        )
        self.android_msg = jpush.android( alert=msg, extras=extras)
        self.push = jpush.JPush(settings.JAK, settings.JMS).create_push() 
Example #27
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()
 def notification_by_platform(self, android_msg, ios_msg, default_msg):
     """不同平台推送不同消息"""
     push = self._jpush.create_push()
     push.audience = jpush.all_
     ios_notification = jpush.ios(alert=ios_msg)
     android_notification = jpush.android(alert=android_msg)
     push.notification = jpush.notification(alert=default_msg,
                                            android=android_notification,
                                            ios=ios_notification)
     push.platform = jpush.all_
     response = push.send()
     return response
Example #29
0
 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'
         }})
Example #30
0
 def create_message(self):
     msg_dic = self.get_message_dic()
     ios_msg = jpush.ios(**msg_dic)
     msg_dic.pop('badge', None)
     android_msg = jpush.android(**msg_dic)
     push = self._push
     push.notification = jpush.notification(
                     alert=self._message.encode('utf-8'),
                     ios=ios_msg,
                     android=android_msg)
     push.platform = jpush.all_
     push.options =  {"time_to_live":86400,
                      "apns_production":True}
Example #31
0
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()
Example #32
0
def notification():
    push = _jpush.create_push()

    push.audience = jpush.all_
    push.platform = jpush.all_

    ios = jpush.ios(alert="Hello, IOS JPush!", sound="a.caf", extras={'k1':'v1'})
    android = jpush.android(alert="Hello, Android msg", priority=1, style=1, alert_type=1,big_text='jjjjjjjjjj', extras={'k1':'v1'})

    push.notification = jpush.notification(alert="Hello, JPush!", android=android, ios=ios)

    # pprint (push.payload)
    result = push.send()
Example #33
0
 def post(self):
     push = self.my_push
     push.audience = jpush.all_
     ios_msg = jpush.ios(alert="Hello, IOS JPush!",
                         badge="+1",
                         extras={'k1': 'v1'},
                         sound_disable=True)
     android_msg = jpush.android(alert="Hello, android msg")
     push.notification = jpush.notification(alert="Hello, JPush!",
                                            android=android_msg,
                                            ios=ios_msg)
     push.platform = jpush.all_
     return Response(push.send())
Example #34
0
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
    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'
             }
         }
     )
Example #38
0
def PushMessage(alert,title,n_type,n_id):
	push = _jpush.create_push()
	push.audience = jpush.all_
	push.notification = jpush.notification(
		ios=jpush.ios(
			alert=alert,
			badge="+1",
			extras={"n_type":n_type,"n_id":n_id}
			),
		android=jpush.android(
			alert=alert,
			title=title,
			extras={"n_type":n_type,"n_id":n_id}
			)
		)
	push.platform = jpush.platform('ios', 'android')
	push.options = {"apns_production":True,"time_to_live":7200}
	try:
		push.send()
	except:
		traceback.print_exc()
Example #39
0
def push(app, title, content, type):

    msg_content = {
        'title': title,
        'description': content,
        'type': type
    }

    jpush = JPush.JPush(app['app_key'], app['master_key'])

    push = jpush.create_push()
    # push.audience = JPush.alias("1547")
    push.audience = JPush.all_
    ios_msg = JPush.ios(alert=content, badge="+1",
                        sound="default", extras=msg_content)

    push.message = JPush.message(msg_content=msg_content)
    push.notification = JPush.notification(ios=ios_msg)
    push.platform = JPush.platform('android', 'ios')
    push.options = {"time_to_live":14400}
    push.send()
Example #40
0
    def save_model(self, request, obj, form, change):
        obj.save()
        year = obj.date.year
        month = obj.date.month
        day = obj.date.day
        title = "明日无推荐"
        content = "天天组合:%d年%d月%d日无推荐" % (year, month, day)
        zuhehelp = ZuheHelp.objects.create(style=3, title=title, content=content, date=obj.date)

        """x = xinge.XingeApp(2100130704, '57bd74b32b26adb3f48b0fd8fb34502d')
        iosx=xinge.XingeApp(2200130705, 'd3156bf69ce4357382bfc8a93920582f')
        msg=xinge.Message()
        msg.type = xinge.Message.TYPE_NOTIFICATION
        msg.title = title
        msg.content = content
        msg.expireTime = 86400
        #msg.sendTime = '2012-12-12 18:48:00'
        # 自定义键值对,key和value都必须是字符串,非必须
        msg.custom = {'type':'3', 'id':str(zuhehelp.id)}
        style = xinge.Style(2, 1, 1, 0, 0)
        msg.style = style
        iosmsg=xinge.MessageIOS()
        iosmsg.alert = content
        iosmsg.custom = {'type':'3', 'id':str(zuhehelp.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=content, badge="+1", sound="a.caf", extras={"type": "3", "id": str(zuhehelp.id)})
        android_msg = jpush.android(alert=content, extras={"type": "3", "id": str(zuhehelp.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()
Example #41
0
    def process_item(self, item, spider):
        for word in self.words_to_filter:
            #print unicode(item['name']).lower()
            if unicode(word) in unicode(item['name']).lower():
                if item['domain']:
                    item['url'][0] = item['domain'] +"/"+ item['url'][0]
                # line = json.dumps(OrderedDict(item), ensure_ascii=False, sort_keys=False) + "\n"
                # self.file.write(line)
                # insert = [null,item['name'][0],item['url'][0], time.time()];
                # self.cur.execute('insert into test values(%d,%s,%s,%d)',value)
                #pdb.set_trace()
                self.cu.execute("select * from fetch where  url=  '"+item['url'][0]+"'")
                #pdb.set_trace()
                r = self.cu.fetchone()

                if r == None:

                    #print  item['name'][0]
                    t = [item['name'][0],item['url'][0], int(time.time())];
                    self.cu.execute("insert into fetch (name,url,ctime) values (?,?,?)", t)
                    self.cx.commit()
                    _jpush = jpush.JPush('8a4d4ac5c14856cb59df9c84', '4be8bd02e575ee5d16d8b8cd')
                    push = _jpush.create_push()
                    push.audience = jpush.all_
                    # device = _jpush.create_device()
                    # device.get_aliasuser('30B414C0D1BE414C8DCEEDE3627B43A7','ios');

                    ios_msg = jpush.ios(alert="Fetch有新的数据!", badge="+1", sound="a.caf", extras={'k1':'v1'})
                    push.notification = jpush.notification(alert="fetch notify!", android= None, ios=ios_msg)
                    push.options = {"time_to_live":86400, "sendno":12345,"apns_production":False}
                    push.platform = jpush.platform("ios")
                    push.send()

                else :
                    print u'已存在';
                return item
            else:
                None
Example #42
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()
Example #43
0
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()

import jpush as jpush
from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret)
_jpush.set_logging("DEBUG")
push = _jpush.create_push()
push.audience = jpush.all_
ios_msg = jpush.ios(alert="Hello, IOS JPush!", badge="+1", extras={'k1':'v1'}, sound_disable=True)
android_msg = jpush.android(alert="Hello, android msg")
push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg)
push.platform = jpush.all_
push.send()
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.all_
ios_msg = jpush.ios(
    alert="Hello, IOS JPush!",
    badge="+1",
    sound="a.caf",
    extras={'k1': 'v1'}
)
android_msg = jpush.android(alert="Hello, android msg")
push.notification = jpush.notification(
    alert="Hello, JPush!",
    android=android_msg,
    ios=ios_msg
)
push.platform = jpush.all_
push.send()
Example #46
0
File: github.py Project: jpush/jbox
def send_github_msg(integration_id):
    print("print the request json")
    print(request.json)
    
    integration = Integration.query.filter_by(integration_id=integration_id).first()
    if integration is None:
        abort(404)
    developer = Developer.query.filter_by(id=integration.developer_id).first()
    if developer is None:
        abort(404)
    _jpush = jpush.JPush(u'1c29cb5814072b5b1f8ef829', u'b46af6af73ee8f9480d4edad')
    push = _jpush.create_push()
    _jpush.set_logging("DEBUG")
    push.audience = jpush.audience(
        jpush.tag(developer.dev_key + '_' + integration.channel.channel)
    )

    message = ''
    title = ''
    commits = ''
    comment = ''
    issue = ''
    pull_request = ''
    repository = request.json['repository']
    sender = request.json['sender']
    author = sender['login']
    url = ''
    if 'commits' in request.json:
        commits = request.json['commits']
    if 'comment' in request.json:
        comment = request.json['comment']
    if 'issue' in request.json:
        issue = request.json['issue']
    if 'pull_request' in request.json:
        pull_request = request.json['pull_request']
    if 'action' in request.json:
        action = request.json['action']
    else:
        action = ''

    target_repository = '[' + repository['name'] + ':' + repository['default_branch'] + ']'
    # push event
    if commits != '':
        print('push event')
        length = len(commits)
        if length > 1:
            title = target_repository + str(length) + 'new commits by ' + author + ':'
        else:
            title = target_repository + '1 new commit by ' + author + ':'
        print(commits)
        for i in range(len(commits)):
            commit_id = commits[i]['id'][:7]
            commit_comment = commits[i]['message']
            message = message + commit_id + ': ' + commit_comment + '-' + author + '\n'
        url = commits[0]['html_url']
        print(message)
    elif issue != '':
        url = issue['html_url']
        issue_title = issue['title']
        # issue comment event
        if comment != '':
            print('issue comment event')
            title = target_repository + 'New comment by ' + author + ' on issue ' + issue_title
            message = comment['body']
        # issue event(opened, closed)
        else:
            print('issue event')
            title = target_repository + 'Issue ' + action + ' by ' + author
            message = issue['body']
    # commit comment event
    elif comment != '':
        print('commit comment event')
        title = target_repository + 'New commit comment by ' + author
        message = comment['body']
        url = comment['html_url']
    # pull request event
    elif pull_request != '':
        print('pull request event')
        url = pull_request['html_url']
        if action == 'opened':
            title = target_repository + 'Pull request submitted by ' + author
            message = pull_request['body']
        elif action == 'closed':
            merged = pull_request['merged']
            if merged:
                title = target_repository + 'Pull request by ' + author + ' was merged'
            else:
                title = target_repository + 'Pull request by ' + author + ' was closed with unmerged commits'

    print("the title")
    print(title)
    print("the message")
    print(message)
    android_msg = jpush.android(alert=title, extras={'title': title, 'message': message})
    ios_msg = jpush.ios(alert=title, extras={'title': title, 'message': message})
    # ios_msg = jpush.ios(alert=request.json['title'], extras={'title': request.json['title']})
    print(integration.icon)
    if integration.icon is None or len(integration.icon) == 0:
        icon_url = ''
    else:
        icon_url = baseurl + '/static/images/' + integration.icon
    push.notification = jpush.notification(alert=title, android=android_msg, ios=ios_msg)
    push.message = jpush.message(msg_content=message, title=title, content_type="tyope",
                                 extras={'dev_key': developer.dev_key, 'channel': integration.channel.channel,
                                         'datetime': int(time.time()),
                                         'icon': icon_url,
                                         'integration_name': integration.name,
                                         'url': url})

    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
Example #47
0
def send_discourse_msg(integration_id, token):
    print("discourse")
    integration = Integration.query.filter_by(integration_id=integration_id, token=token).first()
    if integration is None:
        abort(400)

    # channel dev_ID
    developer = Developer.query.filter_by(id=integration.developer_id).first()
    if developer is None:
        abort(404)
    _jpush = jpush.JPush(u'1c29cb5814072b5b1f8ef829', u'b46af6af73ee8f9480d4edad')
    push = _jpush.create_push()
    _jpush.set_logging("DEBUG")
    push.audience = jpush.audience(
        jpush.tag(developer.dev_key + '_' + integration.channel.channel)
    )
    # push.audience = jpush.all_
    # push.notification = jpush.notification(alert=request.json['title'],extras={'title': request.json['title'],
    #

    message_url = ""
    if 'url' in request.json:
        message_url = request.json['url']
    print("the message url " + message_url)

    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']})
    # ios_msg = jpush.ios(alert=request.json['title'], extras={'title': request.json['title']})
    print(integration.icon)
    if integration.icon is None or len(integration.icon) == 0:
        url = ''
    else:
        url = baseurl + '/static/images/' + integration.icon
    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': integration.channel.channel,
                                         'datetime': int(time.time()),
                                         'icon': url,
                                         'url': message_url,
                                         'integration_name': integration.name})

    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
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.all_
ios_msg = jpush.ios(alert="Hello, IOS JPush!", badge="+1", extras={"k1": "v1"}, sound_disable=True)
android_msg = jpush.android(alert="Hello, android msg")
push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg)
push.platform = jpush.all_
push.send()
Example #49
0
import jpush as jpush
from conf import app_key, master_secret
# from pprint import pprint

_jpush = jpush.JPush(app_key, master_secret)
_jpush.set_logging("DEBUG")
push = _jpush.create_push()

push.audience = jpush.all_
push.platform = jpush.all_

ios = jpush.ios(alert="Hello, IOS JPush!", sound="a.caf", extras={'k1':'v1'})
android = jpush.android(alert="Hello, Android msg", priority=1, style=1, big_text='jjjjjjjjjj', extras={'k1':'v1'})

push.notification = jpush.notification(alert="Hello, JPush!", android=android, ios=ios)

# pprint (push.payload)
result = push.send()