Exemplo n.º 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()
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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()
Exemplo n.º 5
0
def jpush_foundpage(channel_no, version, id, title, city):
    if JPUSH.SWITCH and channel_no == JPUSH.DEFAULT_CHANNELNO and version >= JPUSH.DEFAULT_VERSION:
        import jpush
        oCmsChannelJpush = CmsChannelJpush.objects.get(channel_no=channel_no)
        cities = city.split(",")
        new_cities = []
        for city in cities:
            if len(city) > 2 and city[-1] in ["市", "县"]:
                city = city[:-1]
            new_cities.append(city)
        cities = new_cities
        version = "Putao_" + version.replace(".", "_")
        app_key = oCmsChannelJpush.app_key
        master_secret = oCmsChannelJpush.master_secret
        _jpush = jpush.JPush(app_key, master_secret)
        push = _jpush.create_push()
        push.platform = jpush.all_
        for i in range(0, len(cities), 20):
            city = cities[i:i + 20]
            msg_time = int(time.time())
            city_list = []
            # push.audience = jpush.all_
            if "*" in city:
                push.audience = jpush.audience(jpush.tag(channel_no, version))
            else:
                push.audience = jpush.audience(
                    jpush.tag(*city), jpush.tag_and(channel_no, version))
                city_list = city
            # push.notification = jpush.notification(alert="new found page")

            messages = {
                "version":
                1,
                "data": [{
                    "msg_digest": title,
                    "msg_type": 10,
                    "msg_subject": title,
                    "msg_id": id,
                    "is_notify": 0,
                    "msg_expand_param": {
                        "tab_index": 1,
                        "city_list": city_list
                    },
                    "msg_time": msg_time,
                    "msg_product_type": "0"
                }]
            }
            push.message = {"msg_content": json.dumps(messages)}
            push.send()
Exemplo n.º 6
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()
Exemplo n.º 7
0
def jpushMessageWithTags(tags, msg, action):
    push = jpushCreateClient()
    push.audience = jpush.audience(jpush.tag(tags))
    push.notification = jpush.notification(
        android=jpush.android(alert=action, extras=msg))
    resp = jushPushMessageToJiGuang(push)
    return resp
Exemplo n.º 8
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
    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
Exemplo n.º 10
0
def AsyncDelCommentPush(topicId, senderId, communityId, commentId,
                        commentCount):
    config = readIni()
    tagSuffix = config.get('topic', "tagSuffix")
    pushContent = str(topicId).encode('utf-8') + ":" \
                 +str(senderId).encode('utf-8') + ":" \
                 +str(communityId).encode('utf-8') + ":" \
                 +str(commentId).encode('utf-8') + ":" \
                 +str(commentCount).encode('utf-8')

    tagSuffix = config.get('topic', "tagSuffix")
    tagNormalName = tagSuffix + str(communityId)
    tagSuffix = config.get('report', "tagSuffix")
    tagAdminName = tagSuffix + str(communityId)
    tagSuffix = config.get('property', "tagSuffix")
    tagPropertyName = tagSuffix + str(communityId)

    apiKey = config.get("SDK", "apiKey")
    secretKey = config.get("SDK", "secretKey")
    _jpush = jpush.JPush(apiKey, secretKey)
    push = _jpush.create_push()
    push.audience = jpush.all_
    push.audience = jpush.audience(
        jpush.tag(tagNormalName, tagAdminName, tagPropertyName), )
    push.message = jpush.message(pushContent, u"push_del_comm", None, None)
    push.options = {
        "time_to_live": 0,
        "sendno": 9527,
        "apns_production": PUSH_STATUS
    }
    push.platform = jpush.all_
    push.send()
Exemplo n.º 11
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")
Exemplo n.º 12
0
 def alias(self, alias: list, tags: list):
     push = self.my_push
     data = {'alias': alias}
     push.audience = jpush.audience(jpush.tag(*tags), data)
     push.notification = jpush.notification(
         alert="Hello world with audience!")
     push.platform = jpush.all_
     push.send()
Exemplo n.º 13
0
 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()
Exemplo n.º 14
0
Arquivo: tests.py Projeto: cash2one/pt
def jpush_foundpage(channel_no, version, id, title, city):
    cities = city.split(",")
    new_cities = []
    for city in cities:
        if len(city) > 2 and city[-1] in ["市", "县"]:
            city = city[:-1]
        new_cities.append(city)
    cities = new_cities
    version = "Putao_" + version.replace(".", "_")
    app_key = "5e111aec05ad8a27b651624f"
    master_secret = "423462d8a3880ce786765d6b"
    _jpush = jpush.JPush(app_key, master_secret)
    push = _jpush.create_push()
    push.platform = jpush.all_
    for i in range(0, len(cities), 20):
        city = cities[i:i + 20]
        msg_time = int(time.time())
        city_list = []
        # push.audience = jpush.all_
        if "*" in city:
            push.audience = jpush.audience(jpush.tag(channel_no, version))
        else:
            push.audience = jpush.audience(jpush.tag(*city),
                                           jpush.tag_and(channel_no, version))
            city_list = city
        # push.notification = jpush.notification(alert="new found page")

        messages = {
            "version":
            1,
            "data": [{
                "msg_digest": title,
                "msg_type": 10,
                "msg_subject": title,
                "msg_id": id,
                "is_notify": 0,
                "msg_expand_param": {
                    "tab_index": 1,
                    "city_list": city_list
                },
                "msg_time": msg_time,
                "msg_product_type": "0"
            }]
        }
        push.message = {"msg_content": json.dumps(messages)}
        push.send()
Exemplo n.º 15
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()
Exemplo n.º 16
0
def send_tip(request):
	# save tip
	# notify receiver
	data = {}

	if request.method=='POST':		
		logger.debug(str(request.POST))

		mobile=request.POST.get('mobile')
		friend=request.POST.get('friend_mobile')
		try:
			client = User.objects.get(username=mobile)
			to_friend = User.objects.get(username=friend)
			to_friend_info = UserInfo.objects.get(user=to_friend)
		except ObjectDoesNotExist:
			logger.debug("user or friend do not exist!")
			data['status']=28
			data['error']='user have not register'
			return HttpResponse(json.dumps(data,ensure_ascii=False),content_type='application/json')

		
		content=request.POST.get('message')
		create_time=request.POST.get('create_time')
		audio_url=request.POST.get('audio_url')
		photo_url=request.POST.get('photo_url')

		tip = Tip(user=client)
		tip.receiver = friend
		tip.message = content
		tip.create_time = create_time
		if 'photo_file' in request.FILES:
			photo_name = request.FILES['photo_file']._get_name()
			tip.photo.save(photo_name, request.FILES['photo_file'])
		if 'audio_file' in request.FILES:
			audio_name = request.FILES['audio_file']._get_name()
			tip.audio.save(audio_name, request.FILES['audio_file'])
		tip.save()
		# retrieve tip id for next to get
		cacheID = tip.id
 	
		push_target = to_friend_info.imsi

		_jpush = jpush.JPush(app_key, master_secret)
		push = _jpush.create_push()
		push.audience = jpush.audience(
			jpush.tag(push_target)
		)
		push_data = {}
		push_data['from'] = mobile
		push_data['id'] = cacheID
		push.message = jpush.message(msg_content=302, extras=json.dumps(push_data,ensure_ascii=False))
		push.platform = jpush.all_
		push.send()

		data['status']=0
		return HttpResponse(json.dumps(data,ensure_ascii=False),content_type='application/json')
Exemplo n.º 17
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()
Exemplo n.º 18
0
def sent_msg_to_zone(alias,alert):
    _jpush = jpush.JPush(app_key, master_secret)    
    push = _jpush.create_push()
    push.audience = jpush.audience(
                jpush.tag(alias)
            )
    push.notification = jpush.notification(alert=alert)
    push.platform = jpush.all_
    srecv = push.send()
    return srecv
Exemplo n.º 19
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())
Exemplo n.º 20
0
 def test_message(self):
     msg = message("hello world")
     sms_msg = sms_message("content", 20)
     noti = notification(alert="hello,jpush")
     self.push.notification = noti
     self.push.platform = platform("all")
     self.push.audience = audience(**{"tag": tag("tcc", "all")})
     self.push.message = msg
     self.push.sms_message = sms_msg
     self.push.send_validate()
Exemplo n.º 21
0
def alias():
    push = _jpush.create_push()
    alias = ["alias1", "alias2"]
    alias1 = {"alias": alias}
    print(alias1)
    push.audience = jpush.audience(jpush.tag("tag1", "tag2"), alias1)

    push.notification = jpush.notification(alert="Hello world with audience!")
    push.platform = jpush.all_
    print(push.payload)
    push.send()
Exemplo n.º 22
0
def AsyncForcedReturn():
    config = readIni()
    ListApkInfo = []
    from core.settings import NEW_VERSION_URL
    from web.models import APK
    QuerySet = APK.objects.filter().order_by('-v_id')[:1]
    apkObj = QuerySet[0]
    valCode  = apkObj.v_name
    valSize  = str(apkObj.v_size) + 'MB'
    valURL   = NEW_VERSION_URL
    valForce = apkObj.v_force
    function = apkObj.v_function
    bug      = apkObj.v_bug
    dicts = {}
    dicts.setdefault('fun',function)
    dicts.setdefault('bug',bug)
    ListApkInfo.append(dicts)
    response_data = {}
    response_data['flag']    = 'ok'
    response_data['vcode']   = valCode
    response_data['size']    = valSize
    response_data['url']     = valURL
    response_data['srv_url'] = 'none'
    response_data['force']   = valForce
    response_data['detail']  = ListApkInfo
    pushContent = response_data
    apiKey = config.get("SDK", "apiKey")
    secretKey = config.get("SDK", "secretKey")
    tagSuffixWithTopic = config.get('topic', "tagSuffix")
    tagSuffixWithReport = config.get('report', "tagSuffix")
    tagSuffixWithProperty = config.get('property', "tagSuffix")
    _jpush = jpush.JPush(apiKey,secretKey)
    from addrinfo.models import Community
    commQuerySet = Community.objects.all()
    for i in range(0,commQuerySet.count(),1):
        commId = commQuerySet[i].getCommunityId()
        tagNormalName = tagSuffixWithTopic + str(commId)
        tagAdminName = tagSuffixWithReport+str(commId)
        tagPropertyName = tagSuffixWithProperty+str(commId)
        push = _jpush.create_push()
        push.audience = jpush.all_
        push.audience = jpush.audience(
                    jpush.tag(tagNormalName,tagAdminName,tagPropertyName),
                )
        push.message = jpush.message(
                    pushContent,
                    u"push_force_return",
                    None,
                    None
                )
        push.options = {"time_to_live":0, "sendno":9527, "apns_production":PUSH_STATUS}
        push.platform = jpush.all_
        push.send() 
Exemplo n.º 23
0
 def post(self, request):
     alias_list = self.request.data.get('alias_list', [])
     tags_list = self.request.data.get('tags_list', '')
     push = self.my_push
     push.audience = jpush.audience(
         jpush.tag(*tags_list),
         alias_list,
     )
     push.notification = jpush.notification(
         alert="Hello world with audience!")
     push.platform = jpush.all_
     res = push.send()
     return Response(res.payload)
Exemplo n.º 24
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
Exemplo n.º 25
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")})
Exemplo n.º 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()
Exemplo n.º 27
0
    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() 
Exemplo n.º 28
0
    def test_notification(self):
        noti = notification(alert="hello,jpush")
        self.assertIsInstance(noti, dict)
        self.assertEqual(noti['alert'], 'hello,jpush')

        noti = notification(alert="alert",
                            android=android("alert android!"),
                            ios=ios("alert ios!"),
                            winphone=winphone("alert winphone!"))
        self.assertEqual(noti['alert'], 'alert')
        self.assertEqual(noti['android']['alert'], 'alert android!')
        self.assertEqual(noti['ios']['alert'], 'alert ios!')
        self.assertEqual(noti['winphone']['alert'], 'alert winphone!')

        self.push.platform = platform("all")
        self.push.notification = noti
        self.push.audience = audience(**{"tag": tag("tcc", "all")})
        self.push.send_validate()
Exemplo n.º 29
0
def jpush_send_message(push_data, push_target, id):
	_jpush = jpush.JPush(app_key, master_secret)
	push = _jpush.create_push()
	push.audience = jpush.audience(
		# push_target may user account or phone number
		jpush.tag(push_target)
	)
	push.message = jpush.message(msg_content=id, extras=push_data)
	push.platform = jpush.all_
	push.options = {"time_to_live":86400}
	try:
		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")
Exemplo n.º 30
0
def AsyncPushNew(apiKey, secretKey, custom_content, tagName, 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.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": 3600,
        "sendno": 9527,
        "apns_production": PUSH_STATUS
    }
    push.platform = jpush.all_
    push.send()
Exemplo n.º 31
0
def pushRecords(msg, tag, to_alias):
    """
    :param msg: push msg
    :param tag: push tag
    :param to_alias: push to who
    :return: 
    """
    _jpush = jpush.JPush(settings.JPUSH_APP_KEY, settings.JPUSH_MASTER_SECRET)
    _jpush.set_logging("DEBUG")
    push = _jpush.create_push()
    alias = [
        to_alias,
    ]
    alias1 = {"alias": alias}
    print alias1
    push.audience = jpush.audience(jpush.tag(tag, ), alias1)

    push.notification = jpush.notification(alert=msg)
    push.platform = jpush.all_
    print(push.payload)
    push.send()
Exemplo n.º 32
0
def AsyncReportTopic(apiKey, secretKey, tagSuffix, communityId, custom_content,
                     message, pTitle):
    tagName = tagSuffix + str(communityId)
    _jpush = jpush.JPush(apiKey, secretKey)
    pushExtra = {'pTitle': pTitle}
    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, pTitle, None, pushExtra))
    push.options = {
        "time_to_live": 86400,
        "sendno": 9527,
        "apns_production": PUSH_STATUS
    }
    push.platform = jpush.all_
    push.send()
Exemplo n.º 33
0
def AsyncSetNotice(apiKey, secretKey, currentCommunityId, custom_content, tagSuffix,\
                   tagSuffix1, message, customTitle, topicId,user_id):
    #     import sys
    #     default_encoding = 'utf-8'
    #     if sys.getdefaultencoding() != default_encoding:
    #         reload(sys)
    #         sys.setdefaultencoding(default_encoding)
    try:
        config = readIni()
        apiKey = config.get("SDK", "apiKey")
        secretKey = config.get("SDK", "secretKey")
        tagSuffix = config.get('topic', "tagSuffix")
        tagNormalName = tagSuffix + str(currentCommunityId)
        tagSuffix = config.get('report', "tagSuffix")
        tagAdminName = 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(tagNormalName,
                                                 tagAdminName), )
        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()
    except Exception, e:
        return str(e)
Exemplo n.º 34
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.tag("tag1", "tag2"),
            jpush.alias("alias1", "alias2")
        )
push.notification = jpush.notification(alert="Hello, world with audience!")
push.platform = jpush.all_
push.send()
Exemplo n.º 35
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
Exemplo n.º 36
0
def send_message(integration_id, token):
    if not request.json or not 'message' in request.json or not 'title' in request.json:
        abort(400)
    integration = Integration.query.filter_by(integration_id=integration_id,
                                              token=token).first()
    if integration is None:
        abort(400)

    message_url = ""
    if 'url' in request.json:
        message_url = request.json['url']
    print("the message url " + message_url)
    # 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': request.json['message']})
    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
Exemplo n.º 37
0
Arquivo: github.py Projeto: 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
Exemplo n.º 38
0
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.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()
Exemplo n.º 39
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