DetectController.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
  5. @AUTHOR: ASJRD018
  6. @NAME: AnsjerFormal
  7. @software: PyCharm
  8. @DATE: 2019/1/14 15:57
  9. @Version: python3.6
  10. @MODIFY DECORD:ansjer dev
  11. @file: DetectController.py
  12. @Contact: chanjunkai@163.com
  13. """
  14. import os
  15. import time
  16. import apns2
  17. import jpush as jpush
  18. import oss2
  19. from django.http import JsonResponse
  20. from django.views.generic.base import View
  21. from pyfcm import FCMNotification
  22. from AnsjerPush.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, DETECT_PUSH_DOMAIN, JPUSH_CONFIG, \
  23. FCM_CONFIG, APNS_CONFIG, BASE_DIR, APNS_MODE
  24. from Model.models import Equipment_Info, UidPushModel, SysMsgModel
  25. from Object.ETkObject import ETkObject
  26. from Object.RedisObject import RedisObject
  27. from Object.UidTokenObject import UidTokenObject
  28. from Service.CommonService import CommonService
  29. '''
  30. http://push.dvema.com/notify/push?etk=Y2lTRXhMTjBWS01sWlpURTVJU0ZWTlJ6RXhNVUU9T3o=&n_time=1526845794&channel=1&event_type=704&is_st=0
  31. http://push.dvema.com/deviceShadow/generateUTK?username=debug_user&password=debug_password&uid=VVDHCVBYDKFMJRWA111A
  32. '''
  33. # 移动侦测接口
  34. class NotificationView(View):
  35. def get(self, request, *args, **kwargs):
  36. request.encoding = 'utf-8'
  37. return self.validation(request.GET)
  38. def post(self, request, *args, **kwargs):
  39. request.encoding = 'utf-8'
  40. return self.validation(request.POST)
  41. def validation(self, request_dict):
  42. uidToken = request_dict.get('uidToken', None)
  43. etk = request_dict.get('etk', None)
  44. channel = request_dict.get('channel', '1')
  45. n_time = request_dict.get('n_time', None)
  46. event_type = request_dict.get('event_type', None)
  47. is_st = request_dict.get('is_st', None)
  48. # print("aaa")
  49. # return JsonResponse(0,safe=False)
  50. if not all([channel, n_time]):
  51. return JsonResponse(status=200, data={
  52. 'code': 444,
  53. 'msg': 'param is wrong'})
  54. if etk:
  55. eto = ETkObject(etk)
  56. uid = eto.uid
  57. if len(uid) != 20:
  58. return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
  59. else:
  60. utko = UidTokenObject(uidToken)
  61. uid = utko.UID
  62. pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
  63. # ykey = 'MUJ887NLR8K8GBM9111A_redis_qs'.format(uid=uid)
  64. ykey = '{uid}_redis_qs'.format(uid=uid)
  65. dkey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=event_type, channel=channel)
  66. # 判断redisObj.get_data(key=pkey):不为空
  67. redisObj = RedisObject(db=6)
  68. have_ykey = redisObj.get_data(key=ykey) # uid_set 数据库缓存
  69. have_pkey = redisObj.get_data(key=pkey) # 一分钟限制key
  70. have_dkey = redisObj.get_data(key=dkey) # 推送类型限制
  71. # 一分钟外,推送开启状态
  72. detect_med_type = 0 # 0推送旧机制 1存库不推送,2推送存库
  73. if have_pkey:
  74. res_data = {'code': 0, 'msg': 'success!'}
  75. return JsonResponse(status=200, data=res_data)
  76. # 数据库读取数据
  77. if have_ykey:
  78. redis_list = eval(redisObj.get_data(key=ykey))
  79. else:
  80. # 从数据库查询出来
  81. uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid,uid_set__detect_status=1). \
  82. values('token_val', 'app_type', 'appBundleId',
  83. 'push_type', 'userID_id', 'userID__NickName',
  84. 'lang', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group')
  85. # 新建一个list接收数据
  86. redis_list = []
  87. # 把数据库数据追加进redis_list
  88. for qs in uid_push_qs:
  89. redis_list.append(qs)
  90. # 修改redis数据,并设置过期时间为10分钟
  91. redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
  92. if not redis_list:
  93. res_data = {'code': 404, 'msg': 'error !'}
  94. return JsonResponse(status=200, data=res_data)
  95. if not redis_list:
  96. print("没有redi_list")
  97. res_data = {'code': 0, 'msg': 'success!'}
  98. return JsonResponse(status=200, data=res_data)
  99. is_sys_msg = self.is_sys_msg(int(event_type))
  100. nickname = redis_list[0]['uid_set__nickname']
  101. detect_interval = redis_list[0]['uid_set__detect_interval']
  102. detect_group = redis_list[0]['uid_set__detect_group']
  103. now_time = int(time.time())
  104. if not nickname:
  105. nickname = uid
  106. if detect_group:
  107. if have_dkey:
  108. detect_med_type = 1
  109. else:
  110. detect_med_type = 2
  111. # detect_group=0允许全部推送的时候
  112. if detect_group == '0':
  113. redisObj.set_data(key=dkey, val=1, expire=detect_interval)
  114. else:
  115. detect_group_list = detect_group.split(',')
  116. if event_type in detect_group_list:
  117. if detect_interval < 60:
  118. detect_interval = 60
  119. redisObj.set_data(key=dkey, val=1, expire=detect_interval)
  120. redisObj.set_data(key=pkey, val=1, expire=60)
  121. # 旧模式并且没有pkey,重新创建一个
  122. if not detect_group and not have_pkey:
  123. # 设置推送时间为60秒一次
  124. redisObj.set_data(key=pkey, val=1, expire=60)
  125. auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
  126. bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
  127. kwag_args = {
  128. 'uid': uid,
  129. 'channel': channel,
  130. 'event_type': event_type,
  131. 'n_time': n_time,
  132. # 'appBundleId': appBundleId,
  133. # 'token_val': token_val,
  134. # 'msg_title': msg_title,
  135. # 'msg_text': msg_text
  136. }
  137. eq_list = []
  138. sys_msg_list = []
  139. userID_ids = []
  140. for up in redis_list:
  141. push_type = up['push_type']
  142. appBundleId = up['appBundleId']
  143. token_val = up['token_val']
  144. lang = up['lang']
  145. tz = up['tz']
  146. # 发送标题
  147. msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
  148. # 发送内容
  149. msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
  150. event_type=event_type)
  151. kwag_args['appBundleId'] = appBundleId
  152. kwag_args['token_val'] = token_val
  153. kwag_args['msg_title'] = msg_title
  154. kwag_args['msg_text'] = msg_text
  155. #推送
  156. if detect_med_type == 2 or detect_med_type == 0:
  157. if push_type == 0: # ios apns
  158. self.do_apns(**kwag_args)
  159. elif push_type == 1: # android gcm
  160. self.do_fcm(**kwag_args)
  161. elif push_type == 2: # android jpush
  162. self.do_jpush(**kwag_args)
  163. # 以下是存库
  164. userID_id = up["userID_id"]
  165. int_is_st = int(is_st)
  166. if userID_id not in userID_ids:
  167. eq_list.append(Equipment_Info(
  168. userID_id=userID_id,
  169. eventTime=n_time,
  170. eventType=event_type,
  171. devUid=uid,
  172. devNickName=nickname,
  173. Channel=channel,
  174. alarm='Motion \tChannel:{channel}'.format(channel=channel),
  175. is_st=int_is_st,
  176. receiveTime=n_time,
  177. addTime=now_time
  178. ))
  179. if is_sys_msg:
  180. sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
  181. event_type=event_type, is_sys=1)
  182. sys_msg_list.append(SysMsgModel(
  183. userID_id=userID_id,
  184. msg=sys_msg_text,
  185. addTime=now_time,
  186. updTime=now_time,
  187. uid=uid,
  188. eventType=event_type))
  189. userID_ids.append(userID_id)
  190. if is_sys_msg:
  191. SysMsgModel.objects.bulk_create(sys_msg_list)
  192. Equipment_Info.objects.bulk_create(eq_list)
  193. if is_st == '0' or is_st == '2':
  194. print("is_st=0or2")
  195. return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
  196. elif is_st == '1':
  197. print("is_st=1")
  198. # Endpoint以杭州为例,其它Region请按实际情况填写。
  199. obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
  200. # 设置此签名URL在60秒内有效。
  201. url = bucket.sign_url('PUT', obj, 7200)
  202. res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
  203. return JsonResponse(status=200, data=res_data)
  204. elif is_st == '3':
  205. print("is_st=3")
  206. # 人形检测带动图
  207. # Endpoint以杭州为例,其它Region请按实际情况填写。
  208. img_url_list = []
  209. for i in range(int(is_st)):
  210. obj = '{uid}/{channel}/{filename}_{st}.jpeg'. \
  211. format(uid=uid, channel=channel, filename=n_time, st=i)
  212. # 设置此签名URL在60秒内有效。
  213. url = bucket.sign_url('PUT', obj, 7200)
  214. img_url_list.append(url)
  215. res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success'}
  216. return JsonResponse(status=200, data=res_data)
  217. def get_msg_title(self, appBundleId, nickname):
  218. package_title_config = {
  219. 'com.ansjer.customizedd_a': 'DVS',
  220. 'com.ansjer.zccloud_a': 'ZosiSmart',
  221. 'com.ansjer.zccloud_ab': '周视',
  222. 'com.ansjer.adcloud_a': 'ADCloud',
  223. 'com.ansjer.adcloud_ab': 'ADCloud',
  224. 'com.ansjer.accloud_a': 'ACCloud',
  225. 'com.ansjer.loocamccloud_a': 'Loocam',
  226. 'com.ansjer.loocamdcloud_a': 'Anlapus',
  227. 'com.ansjer.customizedb_a': 'COCOONHD',
  228. 'com.ansjer.customizeda_a': 'Guardian365',
  229. 'com.ansjer.customizedc_a': 'PatrolSecure',
  230. }
  231. if appBundleId in package_title_config.keys():
  232. return package_title_config[appBundleId] + '(' + nickname + ')'
  233. else:
  234. return nickname
  235. def is_sys_msg(self, event_type):
  236. event_type_list = [702, 703, 704]
  237. if event_type in event_type_list:
  238. return True
  239. return False
  240. def get_msg_text(self, channel, n_time, lang, tz, event_type, is_sys=0):
  241. n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz,lang=lang)
  242. etype = int(event_type)
  243. if lang == 'cn':
  244. if etype == 704:
  245. msg_type = '电量过低'
  246. elif etype == 702:
  247. msg_type = '摄像头休眠'
  248. elif etype == 703:
  249. msg_type = '摄像头唤醒'
  250. else:
  251. msg_type = ''
  252. if is_sys:
  253. send_text = '{msg_type} 通道:{channel}'.format(msg_type=msg_type, channel=channel)
  254. else:
  255. send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
  256. # send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
  257. else:
  258. if etype == 704:
  259. msg_type = 'Low battery'
  260. elif etype == 702:
  261. msg_type = 'Camera sleep'
  262. elif etype == 703:
  263. msg_type = 'Camera wake'
  264. else:
  265. msg_type = ''
  266. if is_sys:
  267. send_text = '{msg_type} channel:{channel}'. \
  268. format(msg_type=msg_type, channel=channel)
  269. else:
  270. send_text = '{msg_type} channel:{channel} date:{date}'. \
  271. format(msg_type=msg_type, channel=channel, date=n_date)
  272. return send_text
  273. def do_jpush(self, uid, channel, appBundleId, token_val, event_type, n_time,
  274. msg_title, msg_text):
  275. app_key = JPUSH_CONFIG[appBundleId]['Key']
  276. master_secret = JPUSH_CONFIG[appBundleId]['Secret']
  277. # 此处换成各自的app_key和master_secre
  278. _jpush = jpush.JPush(app_key, master_secret)
  279. push = _jpush.create_push()
  280. # if you set the logging level to "DEBUG",it will show the debug logging.
  281. # _jpush.set_logging("DEBUG")
  282. # push.audience = jpush.all_
  283. push.audience = jpush.registration_id(token_val)
  284. push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  285. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
  286. android = jpush.android(alert=msg_text, priority=1, style=1, alert_type=7,
  287. big_text=msg_text, title=msg_title,
  288. extras=push_data)
  289. push.notification = jpush.notification(android=android)
  290. push.platform = jpush.all_
  291. try:
  292. res = push.send()
  293. print(res)
  294. except Exception as e:
  295. print("jpush fail")
  296. print("Exception")
  297. print(repr(e))
  298. return
  299. else:
  300. print("jpush success")
  301. return
  302. def do_fcm(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
  303. try:
  304. serverKey = FCM_CONFIG[appBundleId]
  305. except Exception as e:
  306. return
  307. push_service = FCMNotification(api_key=serverKey)
  308. data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  309. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
  310. result = push_service.notify_single_device(registration_id=token_val, message_title=msg_title,
  311. message_body=msg_text, data_message=data,
  312. extra_kwargs={
  313. 'default_vibrate_timings': True,
  314. 'default_sound': True,
  315. 'default_light_settings': True
  316. })
  317. print('fcm push ing')
  318. print(result)
  319. return
  320. def do_apns(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title,
  321. msg_text):
  322. try:
  323. cli = apns2.APNSClient(mode=APNS_MODE,
  324. client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
  325. push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  326. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
  327. alert = apns2.PayloadAlert(body=msg_text, title=msg_title)
  328. payload = apns2.Payload(alert=alert, custom=push_data)
  329. n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
  330. res = cli.push(n=n, device_token=token_val, topic=appBundleId)
  331. print(res.status_code)
  332. if res.status_code == 200:
  333. print('apns push success')
  334. return
  335. else:
  336. print('apns push fail')
  337. print(res.reason)
  338. return
  339. except Exception as e:
  340. print(repr(e))
  341. return
  342. # http://test.dvema.com/detect/add?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
  343. # 移动侦测接口
  344. class PushNotificationView(View):
  345. def get(self, request, *args, **kwargs):
  346. request.encoding = 'utf-8'
  347. # operation = kwargs.get('operation')
  348. return self.validation(request.GET)
  349. def post(self, request, *args, **kwargs):
  350. request.encoding = 'utf-8'
  351. # operation = kwargs.get('operation')
  352. return self.validation(request.POST)
  353. def validation(self, request_dict):
  354. etk = request_dict.get('etk', None)
  355. channel = request_dict.get('channel', '1')
  356. n_time = request_dict.get('n_time', None)
  357. event_type = request_dict.get('event_type', None)
  358. is_st = request_dict.get('is_st', None)
  359. eto = ETkObject(etk)
  360. uid = eto.uid
  361. if len(uid) == 20:
  362. redisObj = RedisObject(db=6)
  363. # pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
  364. pkey = '{uid}_ptl'.format(uid=uid)
  365. ykey = '{uid}_redis_qs'.format(uid=uid)
  366. if redisObj.get_data(key=pkey):
  367. res_data = {'code': 0, 'msg': 'success,!'}
  368. return JsonResponse(status=200, data=res_data)
  369. else:
  370. redisObj.set_data(key=pkey, val=1, expire=60)
  371. ##############
  372. redis_data = redisObj.get_data(key=ykey)
  373. if redis_data:
  374. redis_list = eval(redis_data)
  375. else:
  376. # 设置推送时间为60秒一次
  377. redisObj.set_data(key=pkey, val=1, expire=60)
  378. print("从数据库查到数据")
  379. # 从数据库查询出来
  380. uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
  381. values('token_val', 'app_type', 'appBundleId',
  382. 'push_type', 'userID_id', 'lang',
  383. 'tz', 'uid_set__nickname')
  384. # 新建一个list接收数据
  385. redis_list = []
  386. # 把数据库数据追加进redis_list
  387. for qs in uid_push_qs:
  388. redis_list.append(qs)
  389. # 修改redis数据,并设置过期时间为10分钟
  390. if redis_list:
  391. redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
  392. auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
  393. bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
  394. self.do_bulk_create_info(redis_list, n_time, channel, event_type, is_st, uid)
  395. if is_st == '0' or is_st == '2':
  396. return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
  397. elif is_st == '1':
  398. # Endpoint以杭州为例,其它Region请按实际情况填写。
  399. obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
  400. # 设置此签名URL在60秒内有效。
  401. url = bucket.sign_url('PUT', obj, 7200)
  402. res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
  403. return JsonResponse(status=200, data=res_data)
  404. elif is_st == '3':
  405. # 人形检测带动图
  406. img_url_list = []
  407. for i in range(int(is_st)):
  408. obj = '{uid}/{channel}/{filename}_{st}.jpeg'. \
  409. format(uid=uid, channel=channel, filename=n_time, st=i)
  410. # 设置此签名URL在60秒内有效。
  411. url = bucket.sign_url('PUT', obj, 7200)
  412. img_url_list.append(url)
  413. res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success'}
  414. return JsonResponse(status=200, data=res_data)
  415. else:
  416. return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
  417. else:
  418. return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong etk'})
  419. def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
  420. now_time = int(time.time())
  421. # 设备昵称
  422. userID_ids = []
  423. sys_msg_list = []
  424. is_sys_msg = self.is_sys_msg(int(event_type))
  425. is_st = int(is_st)
  426. eq_list = []
  427. nickname = uaqs[0]['uid_set__nickname']
  428. if not nickname:
  429. nickname = uid
  430. for ua in uaqs:
  431. lang = ua['lang']
  432. tz = ua['tz']
  433. userID_id = ua["userID_id"]
  434. if userID_id not in userID_ids:
  435. eq_list.append(Equipment_Info(
  436. userID_id=userID_id,
  437. eventTime=n_time,
  438. eventType=event_type,
  439. devUid=uid,
  440. devNickName=nickname,
  441. Channel=channel,
  442. alarm='Motion \tChannel:{channel}'.format(channel=channel),
  443. is_st=is_st,
  444. receiveTime=n_time,
  445. addTime=now_time
  446. ))
  447. if is_sys_msg:
  448. sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
  449. event_type=event_type, is_sys=1)
  450. sys_msg_list.append(SysMsgModel(
  451. userID_id=userID_id,
  452. msg=sys_msg_text,
  453. addTime=now_time,
  454. updTime=now_time,
  455. uid=uid,
  456. eventType=event_type))
  457. if eq_list:
  458. print('eq_list')
  459. Equipment_Info.objects.bulk_create(eq_list)
  460. if is_sys_msg:
  461. print('sys_msg')
  462. SysMsgModel.objects.bulk_create(sys_msg_list)
  463. return True
  464. def is_sys_msg(self, event_type):
  465. event_type_list = [702, 703, 704]
  466. if event_type in event_type_list:
  467. return True
  468. return False
  469. def get_msg_text(self, channel, n_time, lang, tz, event_type, is_sys=0):
  470. n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz)
  471. etype = int(event_type)
  472. if lang == 'cn':
  473. if etype == 704:
  474. msg_type = '电量过低'
  475. elif etype == 702:
  476. msg_type = '摄像头休眠'
  477. elif etype == 703:
  478. msg_type = '摄像头唤醒'
  479. else:
  480. msg_type = ''
  481. if is_sys:
  482. send_text = '{msg_type} 通道:{channel}'.format(msg_type=msg_type, channel=channel)
  483. else:
  484. send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
  485. else:
  486. if etype == 704:
  487. msg_type = 'Low battery'
  488. elif etype == 702:
  489. msg_type = 'Camera sleep'
  490. elif etype == 703:
  491. msg_type = 'Camera wake'
  492. else:
  493. msg_type = ''
  494. if is_sys:
  495. send_text = '{msg_type} channel:{channel}'. \
  496. format(msg_type=msg_type, channel=channel)
  497. else:
  498. send_text = '{msg_type} channel:{channel} date:{date}'. \
  499. format(msg_type=msg_type, channel=channel, date=n_date)
  500. return send_text