Example #1
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 #2
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 #3
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 #4
0
    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")
Example #5
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
Example #6
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 #7
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 #8
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 #9
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 #10
0
    def pushMessage(self, audience, message_dict):
        try:
            push = self._jpush.create_push()
            if not audience:
                raise JpushException('audience is empty', self.JPUSH_AUDIENCE_EMPTY)
            if audience == 'all':
                push.audience = jpush.all_
            else:
                push.audience = jpush.audience(
                    jpush.alias(*audience)
                )
            #android_msg = jpush.android(alert="Hello, android msg")
            if not message_dict:
                raise JpushException('message_dict is empty', self.MESSAGE_DICT_EMPTY)

            alert_message = message_dict.get('content', '')
            if not alert_message:
                raise JpushException('message_content is empty', self.MESSAGE_CONTENT_EMPTY)
            msg_content = json.dumps(message_dict)

            push.message = jpush.message(msg_content=msg_content)
            push.platform = jpush.all_
            return push.send()
        except jpush.common.JPushFailure, e:
            print e
            return False
Example #11
0
    def send_message(self, message, alias=None, **kwargs):

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

        self.push.message = jpush.message(msg_content=message, extras=kwargs)
        self.push.platform = jpush.platform('android', 'ios')
        self.push.send()
Example #12
0
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()
Example #13
0
    def audience(self, alias: list, tags: list):
        push = self.my_push

        push.audience = jpush.audience(jpush.tag(tags), jpush.alias(alias))

        push.notification = jpush.notification(
            alert="Hello world with audience!")
        push.platform = jpush.all_
        push.send()
Example #14
0
def audience_for_alias(alias, msg):
    push = _jpush.create_push()

    push.audience = jpush.audience(jpush.alias(alias))

    push.notification = jpush.notification(alert=msg)
    push.platform = jpush.all_
    print(push.payload)
    push.send()
Example #15
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
Example #16
0
 def push_article(self,
                  t,
                  i,
                  msg='test',
                  platform='all',
                  audience=jpush.all_):
     if audience != jpush.all_:
         audience = jpush.audience(jpush.alias(str(audience)))
     extra = {'t': str(t), 'i': str(i)}
     return self.push_extra(extra, msg, platform, audience)
Example #17
0
    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()
Example #18
0
 def audience(self):
     _data = self.request.DATA
     alias = _data.get('alias')
     tags = _data.get('tags')
     push = self.my_push
     push.audience = jpush.audience(jpush.tag(tags), jpush.alias(alias))
     push.notification = jpush.notification(
         alert="Hello world with audience!")
     push.platform = jpush.all_
     return Response(push.send())
Example #19
0
def audience():
    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_
    print(push.payload)
    push.send()
Example #20
0
def sendinfo(username, parkingmame):
    _jpush = jpush.JPush(app_key, master_secret)
    _jpush.set_logging("DEBUG")
    push = _jpush.create_push()

    push.audience = jpush.audience(jpush.alias(str(username)))
    info = "Dear " + username + ",you car has parked at " + parkingmame + "!"
    push.notification = jpush.notification(alert=str(info))
    push.platform = jpush.all_
    print(push.payload)
    push.send()
Example #21
0
def push2user(user, type, data={}, alert=None, title=None, builder_id=1, badge="+1"):
    audience = jpush.audience(jpush.alias('u%s' % user.phone))
    extras = data

    code = push_helper(
        alert=alert, type=type, title=title, builder_id=builder_id, badge=badge,
        audience=audience, **extras)

    PushLog(user=user.id, type=type, data=json.dumps(data), alert=alert, title=title, code=code).save()

    return True if code == 0 else False
Example #22
0
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()
Example #23
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()
Example #24
0
def push_message_to_alias(content, msg_type, alias, platform='android'):
    msg = {
        'msg_type': msg_type,
        'content': content
    }

    _jpush = jpush.JPush(app.config['JPUSH_APP_KEY'], app.config['JPUSH_MASTER_SECRET'])
    push = _jpush.create_push()
    push.message = jpush.message(json.dumps(msg))
    push.audience = jpush.audience(jpush.alias(alias))
    push.platform = jpush.platform(platform)
    ret = push.send()
    return ret.payload['sendno'].encode('utf-8')
Example #25
0
def push_msg(*, alias: str, msg: dict):
    try:
        jpush_ = jpush.JPush(_app_key, _master_secret)
        push = jpush_.create_push()
        push.audience = jpush.audience(jpush.alias(alias))
        msg = json.dumps(msg)
        push.message = jpush.message(msg_content=msg)
        push.platform = jpush.all_
        push.send()
    #terrible
    except JPushFailure:
        raise PushError
    except Unauthorized:
        raise PushError
Example #26
0
def audience(alert, tags, alias):
    lock.acquire()
    try:
        push = _jpush.create_push()

        push.audience = jpush.audience(jpush.tag(tuple(tags)),
                                       jpush.alias(tuple(alias)))

        push.notification = jpush.notification(alert=alert)
        push.platform = jpush.all_
        print(push.payload)
        push.send()
    finally:
        lock.release()
Example #27
0
def AsyncDelBlackList(user_id,black_user_id):
    from users.models import User
    userObj = User.objects.get(user_id = long(user_id))
    try:
        from users.models import Remarks
        remObj = Remarks.objects.get(target_id=long(black_user_id),remuser_id=long(user_id))
        user_name = remObj.user_remarks
    except:
        user_name = userObj.user_nick
    user_type = userObj.user_type
    user_portrait = userObj.user_portrait
    user_public_status = userObj.user_public_status
    user_profession = userObj.user_profession
    user_signature = userObj.user_signature
    user_level = userObj.user_level
    user_phone_number = userObj.user_phone_number
    familyId = userObj.user_family_id
    try:
        from users.models import FamilyRecord
        frObj = FamilyRecord.objects.get(family_id=familyId)
        building_num = frObj.family_building_num
        aptnum = frObj.family_apt_num
    except:
        building_num = None
        aptnum = None
    from users.views import genNeighborDict
    userInfo = genNeighborDict(user_id,user_name,user_portrait,building_num,aptnum,familyId,user_type,\
                               user_phone_number,user_profession,user_signature,user_level,user_public_status)
    config = readIni()
    pushContent = userInfo
    alias = config.get("SDK", "youlin")
    apiKey = config.get("SDK", "apiKey")
    secretKey = config.get("SDK", "secretKey")
    currentAlias = alias + str(black_user_id)
    _jpush = jpush.JPush(apiKey,secretKey) 
    push = _jpush.create_push()
    push.audience = jpush.all_
    push.audience = jpush.audience(
        jpush.alias(currentAlias),
    )
    push.message = jpush.message(
                pushContent,
                u"push_del_black",
                None,
                None
            )
    push.options = {"time_to_live":3600, "sendno":9527, "apns_production":PUSH_STATUS}
    push.platform = jpush.all_
    push.send()
Example #28
0
def audience(alias, title, msg_content, extras=None):
    push = _jpush.create_push()
    push.audience = jpush.audience(jpush.alias(alias), )
    push.message = jpush.message(msg_content, title=title, extras=extras)
    push.platform = jpush.all_
    try:
        response = push.send()
    except Unauthorized:
        raise PushError("Unauthorized", 1)
    except APIConnectionException:
        raise PushError("API Connection Error", 2)
    except JPushFailure as e:
        raise PushError('Push Error:{}'.format(e.details), e.error_code)
    except Exception as e:
        raise PushError("Exception:{}".format(str(e)), 3)
    def notification_by_tag_or_alias(self, msg, tags, alias=None):
        """根据别名或tag推送消息"""
        push = self._jpush.create_push()

        if alias:
            push.audience = jpush.audience(
                jpush.tag(*tags),
                jpush.alias(*alias),
            )
        else:
            push.audience = jpush.audience(jpush.tag(*tags))

        push.notification = jpush.notification(alert=msg)
        push.platform = jpush.all_
        response = push.send()
        return response
Example #30
0
def run_detection(iou_threshold, confidence_threshold, source_address,
                  source_file_name, username, app_request):
    basePath = os.path.split(os.path.dirname(source_address))[0]

    outputDirPath = os.path.join(basePath, 'output')
    if not os.path.exists(outputDirPath):
        os.makedirs(outputDirPath)
        os.chmod(outputDirPath, mode=0o777)
    # run yolo3 detection
    outputFilePath, people_number = yolo_detection(iou_threshold,
                                                   confidence_threshold,
                                                   source_address,
                                                   outputDirPath)
    # add IP server location
    outputFilePath = 'http://45.113.234.163:8009' + outputFilePath[5:]
    newVideo = Video(location=outputFilePath, name=source_file_name)
    db.session.add(newVideo)
    db.session.flush()
    # get video id
    video_id = newVideo.id
    # get current user id
    user = User.query.filter_by(name=username).first()
    # add history
    newHistory = History(user_id=user.id,
                         count=people_number,
                         video_id=video_id,
                         submit_time=datetime.now(),
                         status=1)
    db.session.add(newHistory)
    # send notification to user
    msg_content = os.path.basename(outputFilePath) + " completed."
    msg = Message(recipient=user,
                  content=msg_content,
                  time_stamp=datetime.now())
    db.session.add(msg)
    db.session.commit()
    if app_request == 'true':
        # send notification to APP
        push = _jpush.create_push()
        push.audience = jpush.audience(jpush.alias(username))
        push.notification = jpush.notification(alert="Video Completed!")
        push.platform = jpush.all_
        push.send()
    else:
        # send email to user
        send_notification_email(user)
    sys.exit()
Example #31
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':'1', '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':'1', 'id':str(obj.id)}
        iosmsg.sound='default'
        if obj.style==1:
            x.PushAllDevices(0, msg)
            iosx.PushAllDevices(0, iosmsg, 1)
        else:
            idlist=obj.members.values_list('id',flat=True)
            idlist=[str(i) for i in idlist]
            if len(idlist)>1:
                ret=x.PushTags(0, idlist, 'AND', msg)
                ret=iosx.PushTags(0, idlist, 'AND', iosmsg, 1)
            if len(idlist)==1:
                ret=x.PushTags(0, idlist, 'OR', msg)
                ret=iosx.PushTags(0, idlist, 'OR', iosmsg, 1)'''
        _jpush = jpush.JPush('65461ea95bac07cb5349907a', '5238c85d2eacd9cc6b80a225')
        push = _jpush.create_push()
        if obj.style==1:
            push.audience=jpush.all_
        else:
            idlist=request.POST.getlist('members','')
            idlistt=[str(i) for i in idlist]
            
            push.audience = jpush.audience(jpush.alias(*idlistt),)
        ios_msg = jpush.ios(alert=obj.title.encode('utf-8'), badge="+1", sound="a.caf",extras={'type':'1', 'id':str(obj.id)})
        android_msg = jpush.android(alert=obj.title,extras={'type':'1', '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 #32
0
 def push_notification(self, msg, 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
     #print audience
     self.push = self._jpush.create_push()
     self.push.audience = audience
     self.push.platform = p.get(platform)
     self.push.notification = jpush.notification(alert=msg)
     return self.push.send()
Example #33
0
def push(phone, msg, jpid, jpkey):
    import jpush as jpush
    if jpid and jpkey:
        app_key = jpid
        master_secret = jpkey
    else:
        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))
    ios_msg = jpush.ios(alert=msg, sound="default")
    push.notification = jpush.notification(alert=msg, ios=ios_msg)
    push.platform = jpush.all_
    #push.message = {"msg_content":'test'}
    # push.options = {"time_to_live":86400, "sendno":12345,"apns_production":False}
    push.send()
Example #34
0
def AsyncSayHelloPush(apiKey, secretKey, custom_content, currentAlias, message,
                      customTitle):
    _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.alias(currentAlias), )
    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 #35
0
def AsyncShareCommunityNews(apiKey, secretKey, alias, recipyId, customContent,
                            pushContent, pushTitle):
    _jpush = jpush.JPush(apiKey, secretKey)
    currentAlias = alias + str(recipyId)
    pushExtra = {'pTitle': pushTitle}
    pushExtra.update(customContent)
    #    pushExtra = customContent
    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 #36
0
def push_alias(uid, message, **kargs):
    _jpush = jpush.JPush(config.JPUSH_APPKEY, config.JPUSH_SECRET)
    push = _jpush.create_push()
    push.audience = jpush.audience(jpush.alias(uid))
    #push.options
    android = jpush.android(alert=message, extras=kargs)
    push.notification = jpush.notification(android=android)
    push.platform = jpush.all_
    try:
        resp = push.send()
        success = True
    except jpush.JPushFailure:
        resp = 'JPushFailure %s %s' % (uid, message)
        success = False
    try:
        fp = open(config.BASE_DIR + 'log/push.log', 'a')
    except:
        fp = open(config.BASE_DIR + 'log/push.log', 'w')

    fp.write("%s\n" % resp)
    fp.close()
    return success
Example #37
0
def AsyncSetProcessStatus(apiKey, secretKey, aliasSuffix, senderUserId,
                          custom_content, pushContent, pushTitle):
    tagAlias = aliasSuffix + str(senderUserId)
    _jpush = jpush.JPush(apiKey, secretKey)
    pushExtra = {'pTitle': pushTitle}
    pushExtra.update(custom_content)
    #    pushExtra = custom_content
    push = _jpush.create_push()
    push.audience = jpush.all_
    push.audience = jpush.audience(jpush.alias(tagAlias), )
    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 #38
0
def AsyncAddBlackList(user_id,black_user_id):
    config = readIni()
    pushContent = str(user_id).encode('utf-8') + ":" \
                 +str(black_user_id).encode('utf-8')
    alias = config.get("SDK", "youlin")
    apiKey = config.get("SDK", "apiKey")
    secretKey = config.get("SDK", "secretKey")
    currentAlias = alias + str(black_user_id)
    _jpush = jpush.JPush(apiKey,secretKey) 
    push = _jpush.create_push()
    push.audience = jpush.all_
    push.audience = jpush.audience(
        jpush.alias(currentAlias),
    )
    push.message = jpush.message(
                pushContent,
                u"push_add_black",
                None,
                None
            )
    push.options = {"time_to_live":3600, "sendno":9527, "apns_production":PUSH_STATUS}
    push.platform = jpush.all_
    push.send()
Example #39
0
    def test_audience(self):
        self.push.platform = platform("all")
        self.push.audience = audience(**{"tag": tag("tcc", "test", "深圳")})
        self.assertTupleEqual(self.push.payload['audience']["tag"],
                              ("tcc", "test", "深圳"))

        audiences = audience(
            **{
                "tag": tag("tcc", "test", "深圳"),
                "alias": alias(*["alias{}".format(i) for i in range(5)])
            })
        self.assertIsInstance(audiences, dict)
        self.assertDictEqual(
            audiences, {
                "tag": ("tcc", "test", "深圳"),
                "alias": tuple(["alias{}".format(i) for i in range(5)])
            })

        self.push.notification = notification(alert="alert")
        self.push.send_validate()

        with self.assertRaises(ValueError):
            audience(**{"tags": tag("tcc", "all")})
Example #40
0
def PushMessageUser(alert, title, n_type, n_id, user):
    push = _jpush.create_push()
    push.audience = jpush.audience(jpush.alias(user))
    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 #41
0
def PushMessageUser(alert,title,n_type,n_id,user):
	push = _jpush.create_push()
	push.audience = jpush.audience(
		jpush.alias(user)
		)
	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 #42
0
def send_push(msg, user_ids=None, extras=None, title=None):
    '''
    user_ids is a list of user_id [1, 2, ...]
    if user_ids is None then send to all
    '''
    app_key = settings.JPUSH_APP_KEY
    master_secret = settings.JPUSH_MASTER_SECRET
    _jpush = jpush.JPush(app_key, master_secret)

    push = _jpush.create_push()

    ios_msg = jpush.ios(alert=msg, extras=extras)
    android_msg = jpush.android(alert=msg, extras=extras, title=title)
    push.notification = jpush.notification(alert=msg,
                                           android=android_msg,
                                           ios=ios_msg)
    push.platform = jpush.all_

    # for ios dev or prd env
    options = dict()
    options['apns_production'] = settings.APNS_PRODUCTION
    jpush.options(options)

    if user_ids is None:
        push.audience = jpush.all_
        return str(push.send())
    elif len(user_ids) > 1000:
        ans = []
        for i in range(len(user_ids) // 1000 + 1):
            ret = send_push(msg, user_ids[i * 1000:(i + 1) * 1000])
            ans.append(ret)
        return ans
    elif len(user_ids) == 0:
        return ''
    else:
        push.audience = jpush.audience(jpush.alias(*user_ids))
        return str(push.send())
Example #43
0
def AsyncUpdatePasswd(userId,imei):
    config = readIni()
    pushContent = imei
    alias = config.get("SDK", "youlin")
    apiKey = config.get("SDK", "apiKey")
    secretKey = config.get("SDK", "secretKey")
    currentAlias = alias + str(userId)
    _jpush = jpush.JPush(apiKey,secretKey) 

    
    push = _jpush.create_push()
    push.audience = jpush.all_
    push.audience = jpush.audience(
        jpush.alias(currentAlias),
    )
    push.message = jpush.message(
                pushContent,
                u"push_new_passwd",
                None,
                None
            )
    push.options = {"time_to_live":86400, "sendno":9527, "apns_production":PUSH_STATUS}
    push.platform = jpush.all_
    push.send()
Example #44
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 #45
0
def push_test():
    _jpush = jpush.JPush(app_key, master_secret)
    push = _jpush.create_push()
    _jpush.set_logging("DEBUG")

    user_account = "18500000000"
    push.audience = jpush.audience(jpush.alias(user_account))

    msg = "AlphalionGroup JPush Test"
    meeting_ids = "extras information"

    android_msg = jpush.android(alert=msg, extras={'m': meeting_ids})
    ios_msg = jpush.ios(alert=msg, extras={'m': meeting_ids}, badge=1)

    push.notification = jpush.notification(alert=msg,
                                           ios=ios_msg,
                                           android=android_msg)
    push.platform = jpush.all_

    try:
        push.send()
        print('jpush test ok')
    except common.Unauthorized:
        print('jpush unauthorized')
        #raise common.Unauthorized("Unauthorized")
    except common.APIConnectionException:
        print('jpush conn error')
        #raise common.APIConnectionException("conn error")
    except common.JPushFailure:
        print('jpush failure')
        #print ("JPushFailure")
    except:
        print('jpush others exception')
        #print ("Exception")

    pass
Example #46
0
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("13507462179")
        )
push.notification = jpush.notification(alert="Hello, world with audience!")
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.audience(
            jpush.tag("tag1", "tag2"),
            jpush.alias("alias1", "alias2")
        )
push.notification = jpush.notification(alert="Hello, world with audience!")
push.platform = jpush.all_
push.send()
Example #48
0
# -*- coding: utf-8 -*-

"""
    alter by: Daemon
    alter on 2016-08-02
"""
import jpush as jpush
from jpush import common

_jpush = jpush.JPush("5d4173b694e8efa78d84fb41", "32801a523b363dae0ad2e378")

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.audience(
            jpush.alias("test")
)
push.notification = jpush.notification(alert="TEST ALERT !!!!!")
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")