DetectController.py 24 KB

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