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
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
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
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()
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()
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()
def send_push(cls, platform=jpush.all_, audience=None, notification=None, message=None, apns_production=False): push.audience = audience ios = jpush.ios(alert=notification, sound=need_sound) android = jpush.android(alert=notification, priority=1, style=1) push.notification = jpush.notification(ios=ios, android=android) push.options = { "apns_production": apns_production, } push.platform = platform # push.message = message try: response = push.send() except jpush.common.Unauthorized: raise jpush.common.Unauthorized("Unauthorized") except jpush.common.APIConnectionException: raise jpush.common.APIConnectionException("conn") except jpush.common.JPushFailure: print("JPushFailure") except: print("Exception") # JPushExtend.send_push(platform=jpush.all_, audience= "all", notification="My First Push")
def 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
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)
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
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()
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()
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__()
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()
def pushAllAndroid(request): if request.method == 'POST': title = request.POST.get('title') content = request.POST.get('content') print(title, content) print(type(title), type(content)) and_jpush = jpush.JPush(and_app_key, and_master_secret) push = and_jpush.create_push() and_jpush.set_logging("DEBUG") push.audience = jpush.all_ android_msg = jpush.android(alert=content, title=title) push.notification = jpush.notification(alert=content, android=android_msg) push.platform = jpush.all_ try: response = push.send() print(response, type(response)) return render(request, 'success.html') except common.Unauthorized: return render(request, 'failed.html', {"err_msg": "验证失败!"}) # raise common.Unauthorized("Unauthorized") # AppKey,Master Secret 错误,验证失败必须改正。 except common.APIConnectionException: return render(request, 'failed.html', {"err_msg": "请求超时!"}) # raise common.APIConnectionException("conn error") # 包含错误的信息:比如超时,无网络等情况。 except common.JPushFailure: return render(request, 'failed.html', {"err_msg": "请求出错!"}) # print("JPushFailure") # 请求出错,参考业务返回码。 except: return render(request, 'failed.html', {"err_msg": "其他异常!"}) # print("Exception") return render(request, 'androidpush.html')
def jpushMessageAllUser(action, msg): push = jpushCreateClient() push.audience = jpush.all_ push.notification = jpush.notification( android=jpush.android(alert=action, extras=msg)) resp = jushPushMessageToJiGuang(push) return resp
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
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 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
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()
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()
def jpushMessageWithRegId(regid, msg, action): push = jpushCreateClient() push.audience = jpush.audience(jpush.registration_id(regid)) push.notification = jpush.notification( android=jpush.android(alert=action, extras=msg)) print msg, push.notification resp = jushPushMessageToJiGuang(push) return resp
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()
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()
def test_android(self): self.assertEqual( jpush.notification( android=jpush.android(alert="Hello", extras={'k2': 'v2'})), {'android': { 'extras': { 'k2': 'v2' }, 'alert': 'Hello' }})
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()
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()
def push_news(artical_id, header): server = jpush.JPush(app_key, master_secret) push = server.create_push() push.audience = jpush.all_ android_msg = jpush.android(alert=header, title="ArsenalNews", extras={"Header": header, "ArticalId": artical_id}) push.notification = jpush.notification(alert="Hello, Arsenal", android=android_msg) push.platform = jpush.platform("android") push.send()
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
def send(message, alert): android_msg = jpush.android(alert=alert) push.notification = jpush.notification(alert=message, android=android_msg) try: response = push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn error") except common.JPushFailure: print("JPushFailure") except: print("Exception")
def 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())
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()
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}
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()
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 send_notification(self, _id, title, actors): for actor in actors: client_ids = self.get_actor_subscribers(actor) if client_ids: push = self._jpush.create_push() push.audience = jpush.audience( jpush.registration_id(*client_ids) ) log.msg("client ids = " + json.dumps(client_ids)) message = jpush.android(alert=u'新片通知 : 您关注的艺人 ' + actor.encode('utf-8') + u' 有新片 %s ,点击查看详情。' %(title.encode('utf-8')), extras={'VideoID':str(_id)}) push.notification = jpush.notification(alert=u'新片通知 : 您关注的艺人发布了新片,点击查看详情。', android=message) log.msg("Sending push notification for %s and %s" %(title, actor)) push.platform = jpush.all_ push.send()
def send( self, alert, alias: [str] = None, registration_id: [str] = None, platform=None, ): push = self._jpush.create_push() # audience if alias: push.audience = {"alias": alias} elif registration_id: push.audience = { "registration_id": [ registration_id, ] } else: raise Exception("jpush audience not found!") # platform && notification if platform == 'android': android_msg = jpush.android(alert=alert, ) push.notification = jpush.notification(android=android_msg) push.platform = platform elif platform == 'ios': ios_msg = jpush.ios(alert=alert, badge="+1") push.notification = jpush.notification(ios=ios_msg) push.platform = platform else: push.notification = jpush.notification(alert=alert) push.platform = jpush.all_ # options push.options = self.options try: response = push.send() except common.Unauthorized: raise common.Unauthorized("Unauthorized") except common.APIConnectionException: raise common.APIConnectionException("conn error") except common.JPushFailure: print("JPushFailure") except: print("Exception") else: return response
def test_android(self): self.assertEqual( jpush.notification( android=jpush.android( alert="Hello", extras={'k2': 'v2'} ) ), { 'android': { 'extras': {'k2': 'v2'}, 'alert': 'Hello' } } )
def push_extra(self,extra,msg='test',platform='all',audience = 'all'): p = { 'all':jpush.all_ , 'android':jpush.platform('android'), 'ios':jpush.platform('ios') } a = { 'all':jpush.all_ , } 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 = a.get(audience) self.push.platform = p.get(platform) self.push.notification = jpush.notification(alert =msg,android=a_msg,ios=i_msg) return self.push.send()
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 pushProduct(id, operId): try: db.execute("SELECT * FROM " + getTableName('push', operId)+ " WHERE id=%s LIMIT 1", (id,)) msg = db.get_rows(size=1, is_dict=True) db.execute("SELECT * FROM %s WHERE `status`=1" %getTableName('pusher', operId)) pusher = db.get_rows(is_dict=True) _jpush = jpush.JPush(app_key, master_secret) push = _jpush.create_push() total = 0 for vo in pusher: if vo['categories'] and msg['category'] not in vo['categories']: continue if vo['keyword'] and msg['keyword'] not in vo['keyword']: continue push.audience = jpush.audience( jpush.registration_id(vo['registration']) ) push.notification = jpush.notification( android=jpush.android( alert=msg['title'], builder_id=getBuidlerId(vo['sound'], vo['vibrate']), extras={"id": msg['product'], 'target': 'product'} ) ) push.platform = jpush.platform('android') push.send() total = total + 1 db.update(getTableName('pusher', operId), {'date': time2stamp(datetime.date.today().strftime('%Y-%m-%d'))}, {'id': vo['id']}) except Exception: db.update(getTableName('push', operId), {'status': 2}, {'id': id}) return False else: db.update(getTableName('push', operId), {'status': 1, 'total': total}, {'id': id}) return True
def pushMessage(registration, operId): db.execute("SELECT * FROM " + getTableName('pusher', operId)+ " WHERE registration=%s AND `status`=1 LIMIT 1", (registration,)) if db.get_rows_num() == 0: return pusher = db.get_rows(size=1, is_dict=True) _jpush = jpush.JPush(app_key, master_secret) push = _jpush.create_push() push.audience = jpush.audience( jpush.registration_id(registration) ) push.notification = jpush.notification( android=jpush.android( alert=u'你的吐槽信息有了新的回复~', builder_id=getBuidlerId(pusher['sound'], pusher['vibrate']), extras={'target': 'tucao'} ) ) push.platform = jpush.platform('android') push.send()
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()
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
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()
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
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()
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()