def post(self, request): print(request.data) request_data = request.data try: open_id = request_data['open_id'] title = request_data['title'] content = request_data['content'] custom = request_data['custom'] except Exception as e: print(e) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Parameter invalid') return Response(result.get_response(), result.get_code()) try: msg = build_ios_notification(title, content, custom) print(msg.GetMessageObject()) push_app = XingeApp(self.AccessId, self.SecretKey) ret = push_app.PushSingleAccount(0, open_id, msg, self.environment) # ret = push_app.PushSingleDevice(open_id, msg, 2) result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('ret', ret) return Response(result.get_response(), result.get_code()) except Exception as e: print(e) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Parameter invalid') return Response(result.get_response(), result.get_code())
def sendPushToAdmin(title, content, custom): msg = build_android_notification(title, content) msg.custom = custom push_app = XingeApp(AccessId, SecretKey) ret = push_app.PushAllDevices(0, msg) return ret
def send_push_notification(self): access_id = '2100257323' secret_key = 'e7c3215b9b837132ae73f5493b15ad3b' message = self.build_notification_msg() message.custom = self.custom push_app = XingeApp(access_id, secret_key) ret_code = push_app.PushSingleAccount(DEVICE_ANDROID, self.open_id, message) print('SEND PUSH NOTIFICATION : ', ret_code)
def _push_account_ios(account, content, custom_args): app = XingeApp(settings.XINGE_IOS_ACCESS_ID, settings.XINGE_IOS_SECRET_KEY) message = MessageIOS() message.expireTime = 86400 message.alert = content message.badge = 1 message.custom = custom_args return app.PushSingleAccount(0, account, message, 2)
def send_push_notification(self): if settings.DEBUG: server_env = 2 else: server_env = 1 access_id = '2200264357' secret_key = '28b4e56f299a5521a005d8d787d17cba' message = self.build_notification_msg() push_app = XingeApp(access_id, secret_key) ret_code = push_app.PushSingleAccount(DEVICE_IOS, self.open_id, message, server_env) print('SEND PUSH NOTIFICATION : ', ret_code)
def post(self, request): print(request.data) request_data = request.data try: open_id = request_data['open_id'] action_type = request_data['action_type'] action = ClickAction() if action_type == 0: action = None elif action_type == 1: action.actionType = 1 action.activity = request_data['activity'] action.intentFlag = request_data['if'] action.pendingFlag = request_data['pf'] elif action_type == 2: action.actionType = 2 action.url = request_data['browser'] else: action.actionType = 3 action.intent = request_data['intent'] except Exception as e: print(e) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Parameter invalid') return Response(result.get_response(), result.get_code()) try: msg = build_android_notification_api('Custom push test', 'Test content!') if action_type != 0: msg.action = action if 'custom' in request_data: msg.custom = request_data['custom'] push_app = XingeApp(self.AccessId, self.SecretKey) ret = push_app.PushSingleAccount(0, open_id, msg) result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('ret', ret) return Response(result.get_response(), result.get_code()) except Exception as e: print(e) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Parameter invalid') return Response(result.get_response(), result.get_code())
def _push_account_android(account, content, custom_args): app = XingeApp(settings.XINGE_ANDROID_ACCESS_ID, settings.XINGE_ANDROID_SECRET_KEY) message = Message() message.type = MESSAGE_TYPE_ANDROID_NOTIFICATION message.content = content message.expireTime = 86400 message.style = Style(0, 1, 1, 1) message.custom = custom_args action = ClickAction() action.actionType = ClickAction.TYPE_ACTIVITY action.activity = "" message.action = action return app.PushSingleAccount(0, account, message)
def post(self, request): request_data = request.data result = ResultResponse(code.ARIES_200_SUCCESS, 'success') open_id = request_data['open_id'] msg = build_ios_notification('Delivering complete.', 'Enjoy it!', request_data['custom']) print(msg.custom) print(len(msg.custom)) push_app = XingeApp(self.AccessId, self.SecretKey) ret = push_app.PushSingleAccount(0, open_id, msg) result.set('ret', ret) return Response(result.get_response(), result.get_code())
def post(self, request): request_data = request.data result = ResultResponse(code.ARIES_200_SUCCESS, 'success') open_id = request_data['open_id'] title = request_data['title'] content = request_data['content'] msg = build_android_notification(title, content) msg.custom = request_data['custom'] print(msg.custom) print(len(msg.custom)) push_app = XingeApp(self.AccessId, self.SecretKey) ret = push_app.PushSingleAccount(0, open_id, msg) result.set('ret', ret) return Response(result.get_response(), result.get_code())
def send_push_for_android(open_id_list, title, content, custom): access_id = '2100257323' secret_key = 'e7c3215b9b837132ae73f5493b15ad3b' message = build_android_notification(title, content) message.custom = custom push_app = XingeApp(access_id, secret_key) ret_code, error_msg, third = push_app.PushAccountList( DEVICE_ANDROID, open_id_list, message) print(ret_code, error_msg, third) if ret_code: result = False print('Push failed! retcode: {}, msg: {}'.format(ret_code, error_msg)) else: result = True print('Push successfully') return result
def send_push_for_ios(open_id_list, title, content, custom): if settings.DEBUG: server_environ = 2 else: server_environ = 1 access_id = '2200264357' secret_key = '28b4e56f299a5521a005d8d787d17cba' message = build_ios_notification(title, content, custom) push_app = XingeApp(access_id, secret_key) ret_code, error_msg, third = push_app.PushAccountList( DEVICE_IOS, open_id_list, message, server_environ) print(ret_code, error_msg, third) if ret_code: result = False print('Push failed! retcode: {}, msg: {}'.format(ret_code, error_msg)) else: result = True print('Push successfully') return result
mess.sound = "beep.wav" mess.custom = {'key1':'value1', 'key2':'value2'} t1 = TimeInterval(0, 0, 23, 59) mess.acceptTime = (t1,) raw = { "aps" : { "sound" : "beep.wav", "alert" : "ios test", "badge" : 1, "content-available" : 1 } } mess.raw = json.dumps(raw) # 注册app push = XingeApp('accessId', 'secretKey') mess = Message() # or mess = MessageIos() # 推送消息给单个设备 ret = push.PushSingleDevice('token', mess) # 推送给单个账户或别名 ret2 = push.PushSingleDevice('token', mess) # 推送给单个app的所有设备 ret3 = push.PushAllDevices(0, mess) # 推送给tags指定设备 ret4 = push.PushTags(0, ('1', '2'), 'AND', mess) # 推送大批量消息 ret5 = push.CreateMultipush(mess) # 推送消息给大批量账号 push_id = ret5[2] ret6 = push.PushAccountListMultiple(push_id, ('1', '2'))