EquipmentManagerV3.py 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. import re
  2. import threading
  3. import time
  4. import traceback
  5. import requests
  6. from Controller.CheckUserData import RandomStr
  7. import oss2, base64
  8. from django.db.models import Q
  9. from django.views.generic.base import View
  10. from Controller.DeviceConfirmRegion import Device_Region
  11. from Object.RedisObject import RedisObject
  12. from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY, BASE_DIR
  13. from Model.models import Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidPushModel, UidChannelSetModel, \
  14. Device_User, iotdeviceInfoModel, UIDCompanySerialModel, UIDMainUser, UIDModel
  15. from Object.ResponseObject import ResponseObject
  16. from Object.TokenObject import TokenObject
  17. from Service.CommonService import CommonService
  18. from Service.ModelService import ModelService
  19. import time, json
  20. class EquipmentManagerV3(View):
  21. def get(self, request, *args, **kwargs):
  22. request.encoding = 'utf-8'
  23. operation = kwargs.get('operation')
  24. return self.validation(request.GET, request, operation)
  25. def post(self, request, *args, **kwargs):
  26. request.encoding = 'utf-8'
  27. operation = kwargs.get('operation')
  28. return self.validation(request.POST, request, operation)
  29. def validation(self, request_dict, request, operation):
  30. response = ResponseObject()
  31. token = request_dict.get('token', None)
  32. # 设备主键uid
  33. if operation == 'notLoginMainUserDevice':
  34. return self.not_login_do_mainUserDevice(request_dict, response)
  35. tko = TokenObject(token)
  36. if tko.code != 0:
  37. return response.json(tko.code)
  38. response.lang = tko.lang
  39. userID = tko.userID
  40. # 手机端添加设备,查询,修改
  41. if operation == 'add':
  42. return self.do_add(userID, request_dict, response, request)
  43. if operation == 'batchAdd':
  44. return self.do_batch_add(userID, request_dict, response, request)
  45. elif operation == 'query':
  46. return self.do_query(userID, request_dict, response)
  47. elif operation == 'modify':
  48. return self.do_modify(userID, request_dict, response, request)
  49. elif operation == 'modifyChannelName':
  50. return self.do_modify_channel_name(userID, request_dict, response, request)
  51. elif operation == 'fuzzyQuery':
  52. return self.do_fuzzy_query(userID, request_dict, response)
  53. elif operation == 'mainUserDevice':
  54. return self.do_mainUserDevice( request_dict, response)
  55. elif operation == 'getDeviceFeatures':
  56. return self.do_get_device_features(request_dict, response)
  57. else:
  58. return response.json(414)
  59. def do_add(self, userID, request_dict, response, request):
  60. UID = request_dict.get('UID', None)
  61. NickName = request_dict.get('NickName', None)
  62. View_Account = request_dict.get('View_Account', None)
  63. View_Password = request_dict.get('View_Password', '')
  64. encrypt_pass = View_Password
  65. print("准备解密")
  66. View_Password = self.decode_pwd(View_Password)
  67. Type = request_dict.get('Type', None)
  68. ChannelIndex = request_dict.get('ChannelIndex', None)
  69. version = request_dict.get('version', '')
  70. isCheckMainUser = request_dict.get('isCheckMainUser', None)
  71. if not all([UID, NickName, View_Account, Type, ChannelIndex]): # Type和ChannelIndex可能为0
  72. return response.json(444, {'param': 'UID, NickName, View_Account, Type, ChannelIndex'})
  73. Type = int(Type)
  74. ChannelIndex = int(ChannelIndex)
  75. re_uid = re.compile(r'^[A-Za-z0-9]{14,20}$')
  76. if not re_uid.match(UID):
  77. return response.json(444, {'param': 'UID'})
  78. device_info_qs = Device_Info.objects.filter(UID=UID, userID_id=userID)
  79. if device_info_qs:
  80. # 判断设备是否已存在
  81. if device_info_qs[0].isExist == 1:
  82. return response.json(174)
  83. else:
  84. device_info_qs.delete()
  85. id = CommonService.getUserID(getUser=False)
  86. userName = Device_User.objects.get(userID=userID).username
  87. main_exist = Device_Info.objects.filter(UID=UID)
  88. main_exist = main_exist.filter(~Q(vodPrimaryUserID='')).values('vodPrimaryUserID', 'vodPrimaryMaster')
  89. vodPrimaryUserID = userID
  90. vodPrimaryMaster = userName
  91. primaryUserID = ''
  92. primaryMaster = ''
  93. isShare = False
  94. is_bind = Device_Info.objects.filter(UID=UID, isShare=False).values('userID__userID', 'primaryUserID', 'primaryMaster')
  95. if main_exist.exists():
  96. vodPrimaryUserID = main_exist[0]['vodPrimaryUserID']
  97. vodPrimaryMaster = main_exist[0]['vodPrimaryMaster']
  98. if is_bind.exists():
  99. primaryUserID = is_bind[0]['primaryUserID']
  100. primaryMaster = is_bind[0]['primaryMaster']
  101. isShare = True
  102. isusermain = False
  103. if (vodPrimaryUserID != userID and vodPrimaryUserID != '') or (primaryUserID != userID and primaryUserID != ''):
  104. isusermain = True
  105. # 判断是否有已绑定用户
  106. if isCheckMainUser == '1' and isusermain:
  107. res = {
  108. 'id': id,
  109. 'userID': userID,
  110. 'NickName': NickName,
  111. 'UID': UID,
  112. 'View_Account': View_Account,
  113. 'View_Password': View_Password,
  114. 'ChannelIndex': ChannelIndex,
  115. 'Type': Type,
  116. 'isShare': isShare,
  117. 'primaryUserID': primaryUserID,
  118. 'primaryMaster': primaryMaster,
  119. 'vodPrimaryUserID': vodPrimaryUserID,
  120. 'vodPrimaryMaster': vodPrimaryMaster,
  121. 'data_joined': '',
  122. 'version': version,
  123. 'isVod': 0,
  124. 'isExist': 1,
  125. 'userID__userEmail': ''
  126. }
  127. res['vod'] = [
  128. {
  129. "status": 1,
  130. "channel": ChannelIndex,
  131. "endTime": '',
  132. "bucket__content": '',
  133. "uid": UID
  134. }
  135. ]
  136. res['isMainUserExists'] = 1
  137. return response.json(0, res)
  138. try:
  139. # 判断是否有用户绑定
  140. nowTime = int(time.time())
  141. us_qs = UidSetModel.objects.filter(uid=UID)
  142. if us_qs.exists():
  143. us_qs.update(nickname=NickName)
  144. UidSet_id = us_qs.first().id
  145. else:
  146. ip = CommonService.get_ip_address(request)
  147. region_id = Device_Region().get_device_region(ip)
  148. region_alexa = 'CN' if region_id == 1 else 'ALL'
  149. uid_set_create_dict = {
  150. 'uid': UID,
  151. 'addTime': nowTime,
  152. 'updTime': nowTime,
  153. 'ip': CommonService.get_ip_address(request_dict),
  154. 'channel': ChannelIndex,
  155. 'nickname': NickName,
  156. 'version': version,
  157. 'region_alexa': region_alexa,
  158. }
  159. UidSet = UidSetModel.objects.create(**uid_set_create_dict)
  160. UidSet_id = UidSet.id
  161. # 查询uid_channel表有无该uid的数据
  162. uid_channel_set = UidChannelSetModel.objects.filter(uid_id=UidSet_id)
  163. if not uid_channel_set.exists():
  164. # 多通道设备设置通道名
  165. multi_channel_list = [1, 2, 3, 4, 10001]
  166. if Type in multi_channel_list:
  167. UidChannelSet_bulk = []
  168. for i in range(1, ChannelIndex+1):
  169. channel_name = 'channel'+str(i) # channel1,channel2...
  170. UidChannelSet = UidChannelSetModel(uid_id=UidSet_id, channel=i, channel_name=channel_name)
  171. UidChannelSet_bulk.append(UidChannelSet)
  172. UidChannelSetModel.objects.bulk_create(UidChannelSet_bulk)
  173. userDevice = Device_Info(id=id, userID_id=userID, UID=UID, NickName=NickName, View_Account=View_Account,
  174. View_Password=View_Password, Type=Type, ChannelIndex=ChannelIndex, version=version,
  175. vodPrimaryUserID=vodPrimaryUserID, vodPrimaryMaster=vodPrimaryMaster)
  176. userDevice.save()
  177. uid_serial_qs = UIDCompanySerialModel.objects.filter(uid__uid=UID)
  178. if uid_serial_qs.exists():
  179. uid_serial = uid_serial_qs[0]
  180. Device_Info.objects.filter(UID=UID).update(vodPrimaryUserID=vodPrimaryUserID,
  181. vodPrimaryMaster=vodPrimaryMaster,
  182. serial_number=uid_serial.company_serial.serial_number + uid_serial.company_serial.company.mark)
  183. else:
  184. Device_Info.objects.filter(UID=UID).update(vodPrimaryUserID=vodPrimaryUserID,
  185. vodPrimaryMaster=vodPrimaryMaster)
  186. if not us_qs.exists():
  187. us_qs = UidSetModel.objects.filter(uid=UID)
  188. if us_qs.exists() and us_qs[0].is_alexa == 1:
  189. if us_qs[0].channel > 1:
  190. data_list = []
  191. uid_channel_set_qs = UidChannelSetModel.objects.filter(uid_id=us_qs[0].id).\
  192. values('channel', 'channel_name')
  193. if uid_channel_set_qs.exists():
  194. # 多通道设备名为 UidChannelSetModel 的 channel_name
  195. for uid_channel_set in uid_channel_set_qs:
  196. data_list.append({'userID': userID, 'UID': UID, 'uid_nick': uid_channel_set['channel_name'],
  197. 'channel': uid_channel_set['channel'], 'password': encrypt_pass})
  198. else:
  199. data_list = [{'userID': userID, 'UID': UID, 'uid_nick': NickName, 'password': encrypt_pass}]
  200. # 请求Alexa服务器更新事件网关
  201. data_list = json.dumps(data_list)
  202. data = {'data_list': data_list}
  203. url = 'https://www.zositech.xyz/deviceStatus/addOrUpdateV2'
  204. requests.post(url, data=data, timeout=2)
  205. except Exception as e:
  206. return response.json(10, repr(e))
  207. else:
  208. dvqs = Device_Info.objects.filter(id=id).values('id', 'userID', 'NickName', 'UID',
  209. 'View_Account',
  210. 'View_Password', 'ChannelIndex', 'Type',
  211. 'isShare',
  212. 'primaryUserID', 'primaryMaster',
  213. 'vodPrimaryUserID', 'vodPrimaryMaster',
  214. 'userID__userEmail',
  215. 'data_joined', 'version',
  216. 'isVod', 'isExist', 'isCameraOpenCloud', 'serial_number')
  217. dvql = CommonService.qs_to_list(dvqs)
  218. ubqs = UID_Bucket.objects.filter(uid=UID). \
  219. values('bucket__content', 'status', 'channel', 'endTime', 'uid')
  220. res = dvql[0]
  221. res['vod'] = list(ubqs)
  222. iotqs = iotdeviceInfoModel.objects.filter(serial_number=dvql[0]['serial_number'])
  223. if iotqs.exists():
  224. res['iot'] = {
  225. 'endpoint': iotqs[0].endpoint,
  226. 'token_iot_number': iotqs[0].endpoint
  227. }
  228. return response.json(0, res)
  229. def do_batch_add(self, userID, request_dict, response, request):
  230. # 批量添加设备
  231. uidContent = request_dict.get('uidContent', None)
  232. if not uidContent:
  233. return response.json(444, {'param': 'uidContent'})
  234. try:
  235. add_success_flag = False # 添加成功标识
  236. exception_flag = False # 异常标识
  237. exists_flag = False # 已存在标识
  238. uid_content_list = eval(uidContent)
  239. print('uidContent: ', uid_content_list)
  240. re_uid = re.compile(r'^[A-Za-z0-9]{14,20}$')
  241. for uid_content in uid_content_list:
  242. exception_flag = False # 重置异常标识
  243. exists_flag = False # 已存在标识
  244. UID = uid_content['uid']
  245. NickName = uid_content['nickName']
  246. Type = uid_content['type']
  247. ChannelIndex = uid_content['channelIndex']
  248. version = uid_content['version']
  249. isCheckMainUser = uid_content['isCheckMainUser']
  250. View_Account = uid_content['viewAccount']
  251. encryptPassword = uid_content['encryptPassword']
  252. View_Password = self.decode_pwd(encryptPassword)
  253. if not all([UID, NickName, View_Account, Type, ChannelIndex]): # Type和ChannelIndex可能为0
  254. return response.json(444, {'param': 'UID, NickName, View_Account, Type, ChannelIndex'})
  255. if not re_uid.match(UID): # 检查uid长度
  256. return response.json(444, {'error uid length': UID})
  257. device_info_qs = Device_Info.objects.filter(UID=UID, userID_id=userID)
  258. if device_info_qs:
  259. # 判断设备是否已存在
  260. if device_info_qs[0].isExist == 1:
  261. exists_res = {UID: 'device already exists!'}
  262. exists_flag = True
  263. continue
  264. else:
  265. device_info_qs.delete()
  266. id = CommonService.getUserID(getUser=False)
  267. userName = Device_User.objects.get(userID=userID).username
  268. main_exist = Device_Info.objects.filter(UID=UID)
  269. main_exist = main_exist.filter(~Q(vodPrimaryUserID='')).values('vodPrimaryUserID', 'vodPrimaryMaster')
  270. vodPrimaryUserID = userID
  271. vodPrimaryMaster = userName
  272. primaryUserID = ''
  273. primaryMaster = ''
  274. isShare = False
  275. is_bind = Device_Info.objects.filter(UID=UID, isShare=False).values('userID__userID', 'primaryUserID', 'primaryMaster')
  276. if main_exist.exists():
  277. vodPrimaryUserID = main_exist[0]['vodPrimaryUserID']
  278. vodPrimaryMaster = main_exist[0]['vodPrimaryMaster']
  279. if is_bind.exists():
  280. primaryUserID = is_bind[0]['primaryUserID']
  281. primaryMaster = is_bind[0]['primaryMaster']
  282. isShare = True
  283. isusermain = False
  284. if (vodPrimaryUserID != userID and vodPrimaryUserID != '') or (primaryUserID != userID and primaryUserID != ''):
  285. isusermain = True
  286. # 判断是否有已绑定用户
  287. if isCheckMainUser == 1 and isusermain:
  288. res = {
  289. 'id': id,
  290. 'userID': userID,
  291. 'NickName': NickName,
  292. 'UID': UID,
  293. 'View_Account': View_Account,
  294. 'View_Password': View_Password,
  295. 'ChannelIndex': ChannelIndex,
  296. 'Type': Type,
  297. 'isShare': isShare,
  298. 'primaryUserID': primaryUserID,
  299. 'primaryMaster': primaryMaster,
  300. 'vodPrimaryUserID': vodPrimaryUserID,
  301. 'vodPrimaryMaster': vodPrimaryMaster,
  302. 'data_joined': '',
  303. 'version': version,
  304. 'isVod': 0,
  305. 'isExist': 1,
  306. 'userID__userEmail': ''
  307. }
  308. res['vod'] = [
  309. {
  310. "status": 1,
  311. "channel": ChannelIndex,
  312. "endTime": '',
  313. "bucket__content": '',
  314. "uid": UID
  315. }
  316. ]
  317. res['isMainUserExists'] = 1
  318. continue
  319. # 判断是否有用户绑定
  320. nowTime = int(time.time())
  321. us_qs = UidSetModel.objects.filter(uid=UID)
  322. if us_qs.exists():
  323. us_qs.update(nickname=NickName)
  324. UidSet_id = us_qs.first().id
  325. else:
  326. ip = CommonService.get_ip_address(request)
  327. region_id = Device_Region().get_device_region(ip)
  328. region_alexa = 'CN' if region_id == 1 else 'ALL'
  329. uid_set_create_dict = {
  330. 'uid': UID,
  331. 'addTime': nowTime,
  332. 'updTime': nowTime,
  333. 'ip': CommonService.get_ip_address(request_dict),
  334. 'channel': ChannelIndex,
  335. 'nickname': NickName,
  336. 'version': version,
  337. 'region_alexa': region_alexa,
  338. }
  339. UidSet = UidSetModel.objects.create(**uid_set_create_dict)
  340. UidSet_id = UidSet.id
  341. # 查询uid_channel表有无该uid的数据
  342. uid_channel_set = UidChannelSetModel.objects.filter(uid_id=UidSet_id)
  343. if not uid_channel_set.exists():
  344. # 多通道设备设置通道名
  345. multi_channel_list = [1, 2, 3, 4, 10001]
  346. if Type in multi_channel_list:
  347. UidChannelSet_bulk = []
  348. for i in range(1, ChannelIndex+1):
  349. channel_name = 'channel'+str(i) # channel1,channel2...
  350. UidChannelSet = UidChannelSetModel(uid_id=UidSet_id, channel=i, channel_name=channel_name)
  351. UidChannelSet_bulk.append(UidChannelSet)
  352. UidChannelSetModel.objects.bulk_create(UidChannelSet_bulk)
  353. userDevice = Device_Info(id=id, userID_id=userID, UID=UID, NickName=NickName, View_Account=View_Account,
  354. View_Password=View_Password, Type=Type, ChannelIndex=ChannelIndex, version=version,
  355. vodPrimaryUserID=vodPrimaryUserID, vodPrimaryMaster=vodPrimaryMaster)
  356. userDevice.save()
  357. uid_serial_qs = UIDCompanySerialModel.objects.filter(uid__uid=UID)
  358. if uid_serial_qs.exists():
  359. uid_serial = uid_serial_qs[0]
  360. Device_Info.objects.filter(UID=UID).update(vodPrimaryUserID=vodPrimaryUserID,
  361. vodPrimaryMaster=vodPrimaryMaster,
  362. serial_number=uid_serial.company_serial.serial_number + uid_serial.company_serial.company.mark)
  363. else:
  364. Device_Info.objects.filter(UID=UID).update(vodPrimaryUserID=vodPrimaryUserID,
  365. vodPrimaryMaster=vodPrimaryMaster)
  366. if not us_qs.exists():
  367. us_qs = UidSetModel.objects.filter(uid=UID)
  368. if us_qs.exists() and us_qs[0].is_alexa == 1:
  369. if us_qs[0].channel > 1:
  370. data_list = []
  371. uid_channel_set_qs = UidChannelSetModel.objects.filter(uid_id=us_qs[0].id).\
  372. values('channel', 'channel_name')
  373. if uid_channel_set_qs.exists():
  374. # 多通道设备名为 UidChannelSetModel 的 channel_name
  375. for uid_channel_set in uid_channel_set_qs:
  376. data_list.append({'userID': userID, 'UID': UID, 'uid_nick': uid_channel_set['channel_name'],
  377. 'channel': uid_channel_set['channel'], 'password': encryptPassword})
  378. else:
  379. data_list = [{'userID': userID, 'UID': UID, 'uid_nick': NickName, 'password': encryptPassword}]
  380. # 请求Alexa服务器更新事件网关
  381. data_list = json.dumps(data_list)
  382. data = {'data_list': data_list}
  383. url = 'https://www.zositech.xyz/deviceStatus/addOrUpdateV2'
  384. requests.post(url, data=data, timeout=2)
  385. dvqs = Device_Info.objects.filter(id=id).values('id', 'userID', 'NickName', 'UID',
  386. 'View_Account',
  387. 'View_Password', 'ChannelIndex', 'Type',
  388. 'isShare',
  389. 'primaryUserID', 'primaryMaster',
  390. 'vodPrimaryUserID', 'vodPrimaryMaster',
  391. 'userID__userEmail',
  392. 'data_joined', 'version',
  393. 'isVod', 'isExist', 'isCameraOpenCloud', 'serial_number')
  394. dvql = CommonService.qs_to_list(dvqs)
  395. ubqs = UID_Bucket.objects.filter(uid=UID). \
  396. values('bucket__content', 'status', 'channel', 'endTime', 'uid')
  397. success_res = dvql[0]
  398. success_res['vod'] = list(ubqs)
  399. iotqs = iotdeviceInfoModel.objects.filter(serial_number=dvql[0]['serial_number'])
  400. if iotqs.exists():
  401. success_res['iot'] = {'endpoint': iotqs[0].endpoint, 'token_iot_number': iotqs[0].endpoint}
  402. add_success_flag = True
  403. except Exception as e:
  404. print(e)
  405. error_res = repr(e)
  406. exception_flag = True
  407. pass
  408. finally:
  409. if add_success_flag: # 有一台添加成功则返回成功
  410. return response.json(0, success_res)
  411. if exists_flag: # 全部设备已存在
  412. return response.json(174, exists_res)
  413. if exception_flag:
  414. return response.json(500, error_res)
  415. return response.json(0, res)
  416. def do_modify(self, userID, request_dict, response, request):
  417. token = request_dict.get('token', None)
  418. deviceContent = request_dict.get('content', None)
  419. id = request_dict.get('id', None)
  420. if not deviceContent or not id:
  421. return response.json(444, 'content,id')
  422. tko = TokenObject(token)
  423. response.lang = tko.lang
  424. if tko.code != 0:
  425. return response.json(tko.code)
  426. userID = tko.userID
  427. if userID is None:
  428. return response.json(309)
  429. try:
  430. deviceData = eval(deviceContent)
  431. if deviceData.__contains__('userID_id'):
  432. asy = threading.Thread(target=ModelService.update_log,
  433. args=(CommonService.get_ip_address(request), userID, 'modifyV3', deviceData, id))
  434. asy.start()
  435. return response.json(10, '110')
  436. if deviceData.__contains__('UID'):
  437. del deviceData['UID']
  438. # print(deviceData['View_Password'])
  439. if deviceData.__contains__('View_Password'):
  440. encrypt_pwd = deviceData['View_Password']
  441. deviceData['View_Password'] = self.decode_pwd(deviceData['View_Password'])
  442. dev_info_qs = Device_Info.objects.filter(userID_id=userID, id=id)
  443. dev_info_qs.update(**deviceData)
  444. except Exception as e:
  445. print(e)
  446. return response.json(177, repr(e))
  447. else:
  448. qs = Device_Info.objects.filter(userID_id=userID, id=id)
  449. res = CommonService.qs_to_dict(qs)
  450. if qs.exists():
  451. uid = qs[0].UID
  452. nickname = qs[0].NickName
  453. # 增加设备影子信息修改昵称 start
  454. us_qs = UidSetModel.objects.filter(uid=uid)
  455. if us_qs.exists():
  456. if deviceData.__contains__('NickName'):
  457. us_qs.update(nickname=nickname)
  458. else:
  459. ChannelIndex = qs[0].ChannelIndex
  460. nowTime = int(time.time())
  461. uid_set_create_dict = {
  462. 'uid': uid,
  463. 'addTime': nowTime,
  464. 'updTime': nowTime,
  465. # 'ip': CommonService.get_ip_address(request),
  466. 'channel': ChannelIndex,
  467. 'nickname': nickname,
  468. }
  469. UidSetModel.objects.create(**uid_set_create_dict)
  470. di_qs = Device_Info.objects.filter(UID=uid)
  471. di_qs.update(NickName=nickname)
  472. if deviceData is not None and deviceData.__contains__('NickName') and us_qs[0].is_alexa == 1:
  473. # 请求Alexa服务器更新事件网关
  474. url = 'https://www.zositech.xyz/deviceStatus/addOrUpdateV2'
  475. password = encrypt_pwd if deviceData.__contains__('View_Password') else ''
  476. data_list = [{'userID': userID, 'UID': uid, 'uid_nick': nickname, 'password': password}]
  477. data_list = json.dumps(data_list)
  478. data = {'data_list': data_list}
  479. requests.post(url, data=data, timeout=2)
  480. return response.json(0, res)
  481. # 编辑通道名
  482. def do_modify_channel_name(self, userID, request_dict, response):
  483. uid = request_dict.get('uid', None)
  484. channel = request_dict.get('channel', None)
  485. channel_name = request_dict.get('channel_name', None)
  486. if not all([uid, channel, channel_name]):
  487. return response.json(444)
  488. # 更新通道名
  489. UidChannelSetModel.objects.filter(uid__uid=uid).update(channel_name=channel_name)
  490. return response.json(0)
  491. # 新查询设备字段
  492. def do_query(self, userID, request_dict, response):
  493. token = request_dict.get('token', None)
  494. page = request_dict.get('page', None)
  495. line = request_dict.get('line', None)
  496. NickName = request_dict.get('NickName', None)
  497. if not token or not page or not line:
  498. return response.json(444)
  499. page = int(page)
  500. line = int(line)
  501. uid = request_dict.get('uid', None)
  502. tko = TokenObject(token)
  503. response.lang = tko.lang
  504. if page <= 0:
  505. return response.json(0)
  506. if tko.code != 0:
  507. return response.json(tko.code)
  508. userID = tko.userID
  509. dvqs = Device_Info.objects.filter(userID_id=userID)
  510. # # 过滤已重置的设备
  511. dvqs = dvqs.filter(~Q(isExist=2))
  512. dvql = dvqs.values('id', 'userID', 'NickName', 'UID', 'View_Account','View_Password', 'ChannelIndex',
  513. 'Type', 'isShare', 'primaryUserID', 'primaryMaster', 'data_joined', 'vodPrimaryUserID',
  514. 'vodPrimaryMaster', 'userID__userEmail', 'version', 'isVod', 'isExist', 'NotificationMode',
  515. 'isCameraOpenCloud', 'serial_number')
  516. dvls = CommonService.qs_to_list(dvql)
  517. uid_list = []
  518. serial_number_list = []
  519. for dvl in dvls:
  520. if dvl['primaryUserID'] and dvl['id'] == dvl['primaryUserID']:
  521. dvl['isPrimaryUser'] = 1
  522. else:
  523. dvl['isPrimaryUser'] = 0
  524. uid_list.append(dvl['UID'])
  525. serial_number_list.append(dvl['serial_number'][0:6])
  526. # 新增获取IOT证书内容
  527. iotqs = iotdeviceInfoModel.objects.filter(serial_number__in=serial_number_list)
  528. ubqs = UID_Bucket.objects.filter(uid__in=uid_list). \
  529. values('bucket__content', 'status', 'channel', 'endTime', 'uid')
  530. upqs = UID_Preview.objects.filter(uid__in=uid_list).order_by('channel').values('id', 'uid', 'channel')
  531. auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
  532. bucket = oss2.Bucket(auth, 'oss-cn-hongkong.aliyuncs.com', 'statres')
  533. nowTime = int(time.time())
  534. data = []
  535. # 设备拓展信息表
  536. us_qs = UidSetModel.objects.filter(uid__in=uid_list).values('id', 'uid', 'version', 'nickname', 'ucode',
  537. 'detect_status', 'detect_group',
  538. 'detect_interval',
  539. 'region_alexa', 'is_alexa', 'deviceModel',
  540. 'TimeZone', 'TimeStatus', 'SpaceUsable',
  541. 'SpaceSum', 'MirrorType', 'RecordType',
  542. 'OutdoorModel', 'WIFIName', 'isDetector',
  543. 'DetectorRank', 'is_human', 'is_custom_voice', 'is_ptz', 'double_wifi')
  544. uv_dict = {}
  545. for us in us_qs:
  546. uv_dict[us['uid']] = {
  547. 'version': us['version'],
  548. 'nickname': us['nickname'],
  549. 'ucode': us['ucode'],
  550. 'detect_interval': us['detect_interval'],
  551. 'detect_group': us['detect_group'],
  552. 'detect_status': us['detect_status'],
  553. 'region_alexa': us['region_alexa'],
  554. 'is_alexa': us['is_alexa'],
  555. 'deviceModel': us['deviceModel'],
  556. 'TimeZone': us['TimeZone'],
  557. 'TimeStatus': us['TimeStatus'],
  558. 'SpaceUsable': us['SpaceUsable'],
  559. 'SpaceSum': us['SpaceSum'],
  560. 'MirrorType': us['MirrorType'],
  561. 'RecordType': us['RecordType'],
  562. 'OutdoorModel': us['OutdoorModel'],
  563. 'WIFIName': us['WIFIName'],
  564. 'isDetector': us['isDetector'],
  565. 'DetectorRank': us['DetectorRank'],
  566. 'is_human': us['is_human'],
  567. 'is_custom_voice': us['is_custom_voice'],
  568. 'is_ptz': us['is_ptz'],
  569. 'double_wifi': us['double_wifi']
  570. }
  571. # 从uid_channel里面取出通道配置信息
  572. ucs_qs = UidChannelSetModel.objects.filter(uid__id=us['id']).values('channel', 'channel_name',
  573. 'pir_audio', 'mic_audio',
  574. 'battery_status', 'battery_level',
  575. 'sleep_status', 'sleep_time',
  576. 'light_night_model',
  577. 'light_alarm_type',
  578. 'light_alarm_level',
  579. 'light_alarm_man_en',
  580. 'light_alarm_vol',
  581. 'light_long_light'
  582. )
  583. channels = []
  584. for ucs in ucs_qs:
  585. channels_dict = {
  586. 'channel': ucs['channel'],
  587. 'channel_name': ucs['channel_name'],
  588. 'pir_audio': ucs['pir_audio'],
  589. 'mic_audio': ucs['mic_audio'],
  590. 'battery_status': ucs['battery_status'],
  591. 'battery_level': ucs['battery_level'],
  592. 'sleep_status': ucs['sleep_status'],
  593. 'sleep_time': ucs['sleep_time'],
  594. 'light_night_model': ucs['light_night_model'],
  595. 'light_alarm_type': ucs['light_alarm_type'],
  596. 'light_alarm_level': ucs['light_alarm_level'],
  597. 'light_alarm_man_en': ucs['light_alarm_man_en'],
  598. 'light_alarm_vol': ucs['light_alarm_vol'],
  599. 'light_long_light': ucs['light_long_light']
  600. }
  601. channels.append(channels_dict)
  602. uv_dict[us['uid']]['channels'] = channels
  603. for p in dvls:
  604. # 新增IOT
  605. p['iot'] = []
  606. for iot in iotqs:
  607. if p['serial_number'][0:6] == iot.serial_number:
  608. p['iot'].append(
  609. {
  610. 'endpoint': iot.endpoint,
  611. 'token_iot_number': iot.token_iot_number
  612. }
  613. )
  614. p['vod'] = []
  615. for dm in ubqs:
  616. if p['UID'] == dm['uid']:
  617. if dm['endTime'] > nowTime:
  618. p['vod'].append(dm)
  619. p['preview'] = []
  620. for up in upqs:
  621. if p['UID'] == up['uid']:
  622. obj = 'uid_preview/{uid}/channel_{channel}.png'.format(uid=up['uid'], channel=up['channel'])
  623. img_sign = bucket.sign_url('GET', obj, 300)
  624. p['preview'].append(img_sign)
  625. p_uid = p['UID']
  626. # 返回设备初始化字符
  627. uid_qs = UIDModel.objects.filter(uid=p_uid).values('platform', 'init_string', 'init_string_app')
  628. if uid_qs.exists():
  629. p['platform'] = uid_qs[0]['platform']
  630. p['initString'] = uid_qs[0]['init_string']
  631. p['initStringApp'] = uid_qs[0]['init_string_app']
  632. if p_uid in uv_dict:
  633. # 设备版本号
  634. uidversion = uv_dict[p_uid]['version']
  635. if len(uidversion) >6:
  636. uidversion = uidversion[0 : uidversion.rfind('.')]
  637. p['uid_version'] = uidversion
  638. p['ucode'] = uv_dict[p_uid]['ucode']
  639. p['detect_interval'] = uv_dict[p_uid]['detect_interval']
  640. p['detect_status'] = uv_dict[p_uid]['detect_status']
  641. p['detect_group'] = uv_dict[p_uid]['detect_group']
  642. p['region_alexa'] = uv_dict[p_uid]['region_alexa']
  643. p['is_alexa'] = uv_dict[p_uid]['is_alexa']
  644. p['deviceModel'] = uv_dict[p_uid]['deviceModel']
  645. p['TimeZone'] = uv_dict[p_uid]['TimeZone']
  646. p['TimeStatus'] = uv_dict[p_uid]['TimeStatus']
  647. p['SpaceUsable'] = uv_dict[p_uid]['SpaceUsable']
  648. p['SpaceSum'] = uv_dict[p_uid]['SpaceSum']
  649. p['MirrorType'] = uv_dict[p_uid]['MirrorType']
  650. p['RecordType'] = uv_dict[p_uid]['RecordType']
  651. p['OutdoorModel'] = uv_dict[p_uid]['OutdoorModel']
  652. p['WIFIName'] = uv_dict[p_uid]['WIFIName']
  653. p['isDetector'] = uv_dict[p_uid]['isDetector']
  654. p['DetectorRank'] = uv_dict[p_uid]['DetectorRank']
  655. p['is_human'] = uv_dict[p_uid]['is_human']
  656. p['is_custom_voice'] = uv_dict[p_uid]['is_custom_voice']
  657. p['is_ptz'] = uv_dict[p_uid]['is_ptz']
  658. p['channels'] = uv_dict[p_uid]['channels']
  659. p['double_wifi'] = uv_dict[p_uid]['double_wifi']
  660. # 设备昵称 调用影子信息昵称,先阶段不可
  661. if uv_dict[p_uid]['nickname']:
  662. p['NickName'] = uv_dict[p_uid]['nickname']
  663. else:
  664. # 设备版本号
  665. p['uid_version'] = ''
  666. p['ucode'] = ''
  667. data.append(p)
  668. result = data
  669. if NickName:
  670. # print('NickName搜索缓存')
  671. data = []
  672. for index, item in enumerate(result):
  673. if NickName == item['NickName']:
  674. # 加密
  675. item['View_Password'] = self.encrypt_pwd(item['View_Password'])
  676. data.append(item)
  677. return response.json(0, data)
  678. if uid:
  679. # print('uid搜索缓存')
  680. data = []
  681. for index, item in enumerate(result):
  682. if uid == item['UID']:
  683. # 加密
  684. item['View_Password'] = self.encrypt_pwd(item['View_Password'])
  685. data.append(item)
  686. return response.json(0, data)
  687. items = []
  688. # print('缓存分页')
  689. for index, item in enumerate(result):
  690. if (page - 1) * line <= index:
  691. if index < page * line:
  692. # 加密
  693. item['View_Password'] = self.encrypt_pwd(item['View_Password'])
  694. print(item)
  695. items.append(item)
  696. print(items)
  697. return response.json(0, items)
  698. def do_fuzzy_query(self, userID, request_dict, response):
  699. fuzzy = request_dict.get('fuzzy', None)
  700. page = request_dict.get('page', None)
  701. line = request_dict.get('line', None)
  702. if page and line:
  703. page = int(page)
  704. line = int(line)
  705. device_qs = Device_Info.objects.filter(userID=userID)
  706. device_qs = device_qs.filter(~Q(isExist=2))
  707. if device_qs.exists():
  708. if fuzzy:
  709. device_qs = device_qs.filter(Q(UID__icontains=fuzzy) | Q(NickName__icontains=fuzzy))
  710. device_qs = device_qs.values('id', 'userID', 'NickName', 'UID', 'View_Account',
  711. 'View_Password', 'ChannelIndex', 'Type', 'isShare',
  712. 'primaryUserID', 'primaryMaster', 'data_joined', 'vodPrimaryUserID',
  713. 'vodPrimaryMaster', 'userID__userEmail',
  714. 'version', 'isVod', 'isExist', 'NotificationMode', 'isCameraOpenCloud',
  715. 'serial_number')
  716. dvls = CommonService.qs_to_list(device_qs)
  717. uid_list = []
  718. serial_number_list = []
  719. for dvl in dvls:
  720. uid_list.append(dvl['UID'])
  721. serial_number_list.append(dvl['serial_number'][0:6])
  722. # 新增获取IOT证书内容
  723. iotqs = iotdeviceInfoModel.objects.filter(serial_number__in=serial_number_list)
  724. ubqs = UID_Bucket.objects.filter(uid__in=uid_list). \
  725. values('bucket__content', 'status', 'channel', 'endTime', 'uid')
  726. upqs = UID_Preview.objects.filter(uid__in=uid_list).order_by('channel').values('id', 'uid', 'channel')
  727. auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
  728. bucket = oss2.Bucket(auth, 'oss-cn-hongkong.aliyuncs.com', 'statres')
  729. nowTime = int(time.time())
  730. data = []
  731. # 设备拓展信息表
  732. us_qs = UidSetModel.objects.filter(uid__in=uid_list).values('id', 'uid', 'version', 'nickname', 'ucode',
  733. 'detect_status', 'detect_group',
  734. 'detect_interval',
  735. 'region_alexa', 'is_alexa', 'deviceModel',
  736. 'TimeZone', 'TimeStatus', 'SpaceUsable',
  737. 'SpaceSum', 'MirrorType', 'RecordType',
  738. 'OutdoorModel', 'WIFIName', 'isDetector',
  739. 'DetectorRank')
  740. uv_dict = {}
  741. for us in us_qs:
  742. uv_dict[us['uid']] = {
  743. 'version': us['version'],
  744. 'nickname': us['nickname'],
  745. 'ucode': us['ucode'],
  746. 'detect_interval': us['detect_interval'],
  747. 'detect_group': us['detect_group'],
  748. 'detect_status': us['detect_status'],
  749. 'region_alexa': us['region_alexa'],
  750. 'is_alexa': us['is_alexa'],
  751. 'deviceModel': us['deviceModel'],
  752. 'TimeZone': us['TimeZone'],
  753. 'TimeStatus': us['TimeStatus'],
  754. 'SpaceUsable': us['SpaceUsable'],
  755. 'SpaceSum': us['SpaceSum'],
  756. 'MirrorType': us['MirrorType'],
  757. 'RecordType': us['RecordType'],
  758. 'OutdoorModel': us['OutdoorModel'],
  759. 'WIFIName': us['WIFIName'],
  760. 'isDetector': us['isDetector'],
  761. 'DetectorRank': us['DetectorRank']
  762. }
  763. # 从uid_channel里面取出通道配置信息
  764. ucs_qs = UidChannelSetModel.objects.filter(uid__id=us['id']).values()
  765. channels = []
  766. for ucs in ucs_qs:
  767. channel = {
  768. 'channel': ucs['channel'],
  769. 'channel_name': ucs['channel_name'],
  770. 'pir_audio': ucs['pir_audio'],
  771. 'mic_audio': ucs['mic_audio'],
  772. 'battery_status': ucs['battery_status'],
  773. 'battery_level': ucs['battery_level'],
  774. 'sleep_status': ucs['sleep_status'],
  775. 'sleep_time': ucs['sleep_time'],
  776. 'light_night_model': ucs['light_night_model'],
  777. 'light_alarm_type': ucs['light_alarm_type'],
  778. 'light_alarm_level': ucs['light_alarm_level'],
  779. 'light_alarm_man_en': ucs['light_alarm_man_en'],
  780. 'light_alarm_vol': ucs['light_alarm_vol'],
  781. 'light_long_light': ucs['light_long_light']
  782. }
  783. channels.append(channel)
  784. uv_dict[us['uid']]['channels'] = channels
  785. for p in dvls:
  786. # 新增IOT
  787. p['iot'] = []
  788. for iot in iotqs:
  789. if p['serial_number'][0:6] == iot.serial_number:
  790. p['iot'].append(
  791. {
  792. 'endpoint': iot.endpoint,
  793. 'token_iot_number': iot.token_iot_number
  794. }
  795. )
  796. p['vod'] = []
  797. for dm in ubqs:
  798. if p['UID'] == dm['uid']:
  799. if dm['endTime'] > nowTime:
  800. p['vod'].append(dm)
  801. p['preview'] = []
  802. for up in upqs:
  803. if p['UID'] == up['uid']:
  804. obj = 'uid_preview/{uid}/channel_{channel}.png'.format(uid=up['uid'], channel=up['channel'])
  805. img_sign = bucket.sign_url('GET', obj, 300)
  806. p['preview'].append(img_sign)
  807. p_uid = p['UID']
  808. if p_uid in uv_dict:
  809. # 设备版本号
  810. p['uid_version'] = uv_dict[p_uid]['version']
  811. p['ucode'] = uv_dict[p_uid]['ucode']
  812. p['detect_interval'] = uv_dict[p_uid]['detect_interval']
  813. p['detect_status'] = uv_dict[p_uid]['detect_status']
  814. p['detect_group'] = uv_dict[p_uid]['detect_group']
  815. p['region_alexa'] = uv_dict[p_uid]['region_alexa']
  816. p['is_alexa'] = uv_dict[p_uid]['is_alexa']
  817. p['deviceModel'] = uv_dict[p_uid]['deviceModel']
  818. p['TimeZone'] = uv_dict[p_uid]['TimeZone']
  819. p['TimeStatus'] = uv_dict[p_uid]['TimeStatus']
  820. p['SpaceUsable'] = uv_dict[p_uid]['SpaceUsable']
  821. p['SpaceSum'] = uv_dict[p_uid]['SpaceSum']
  822. p['MirrorType'] = uv_dict[p_uid]['MirrorType']
  823. p['RecordType'] = uv_dict[p_uid]['RecordType']
  824. p['OutdoorModel'] = uv_dict[p_uid]['OutdoorModel']
  825. p['WIFIName'] = uv_dict[p_uid]['WIFIName']
  826. p['isDetector'] = uv_dict[p_uid]['isDetector']
  827. p['DetectorRank'] = uv_dict[p_uid]['DetectorRank']
  828. p['channels'] = uv_dict[p_uid]['channels']
  829. # 设备昵称 调用影子信息昵称,先阶段不可
  830. if uv_dict[p_uid]['nickname']:
  831. p['NickName'] = uv_dict[p_uid]['nickname']
  832. else:
  833. # 设备版本号
  834. p['uid_version'] = ''
  835. p['ucode'] = ''
  836. data.append(p)
  837. result = data
  838. items = []
  839. # print('缓存分页')
  840. for index, item in enumerate(result):
  841. if (page - 1) * line <= index:
  842. if index < page * line:
  843. # 加密
  844. item['View_Password'] = self.encrypt_pwd(item['View_Password'])
  845. print(item)
  846. items.append(item)
  847. print(items)
  848. return response.json(0, items)
  849. else:
  850. return response.json(0, [])
  851. else:
  852. return response.json(444)
  853. # 加密
  854. def encrypt_pwd(self, userPwd):
  855. for i in range(1, 4):
  856. if i == 1:
  857. userPwd = RandomStr(3, False) + userPwd + RandomStr(3, False)
  858. userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
  859. if i == 2:
  860. userPwd = RandomStr(2, False) + str(userPwd) + RandomStr(2, False)
  861. userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
  862. if i == 3:
  863. userPwd = RandomStr(1, False) + str(userPwd) + RandomStr(1, False)
  864. userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
  865. return userPwd
  866. # 解密
  867. def decode_pwd(self, password):
  868. for i in range(1, 4):
  869. if i == 1:
  870. # 第一次先解密
  871. password = base64.b64decode(password)
  872. password = password.decode('utf-8')
  873. # 截去第一位,最后一位
  874. password = password[1:-1]
  875. if i == 2:
  876. # 第2次先解密
  877. password = base64.b64decode(password)
  878. password = password.decode('utf-8')
  879. # 去前2位,后2位
  880. password = password[2:-2]
  881. if i == 3:
  882. # 第3次先解密
  883. password = base64.b64decode(password)
  884. password = password.decode('utf-8')
  885. # 去前3位,后3位
  886. password = password[3:-3]
  887. return password
  888. def do_mainUserDevice(self, request_dict, response):
  889. UID = request_dict.get('UID')
  890. dvq = Device_Info.objects.filter(UID=UID)
  891. dvq = dvq.filter(~Q(vodPrimaryUserID='')).values('vodPrimaryUserID')
  892. qs = {}
  893. if dvq.exists():
  894. qs = Device_User.objects.filter(userID=dvq[0]['vodPrimaryUserID']).values('userID', 'NickName', 'username',
  895. 'userEmail', 'phone')
  896. NickName = qs[0]['username']
  897. userEmail = qs[0]['userEmail']
  898. phone = qs[0]['phone']
  899. username = qs[0]['username']
  900. qs = CommonService.qs_to_list(qs)
  901. if NickName =='':
  902. qs[0]['NickName'] = username
  903. # if userEmail =='':
  904. # qs[0]['userEmail'] = NickName
  905. if phone =='':
  906. qs[0]['phone'] = NickName
  907. # if not qs:
  908. # uidq = UIDMainUser.objects.filter(UID=UID).values('user_id')
  909. # if uidq.exists():
  910. # qs = Device_User.objects.filter(userID=uidq[0]['user_id']).values('userID', 'NickName', 'username', 'userEmail', 'phone')
  911. # qs = CommonService.qs_to_list(qs)
  912. return response.json(0, qs)
  913. def not_login_do_mainUserDevice(self, request_dict, response):
  914. UID = request_dict.get('UID')
  915. token = request_dict.get('token', None)
  916. time_stamp = request_dict.get('time_stamp', None)
  917. if not all([token, time_stamp]):
  918. return response.json(444)
  919. token = int(CommonService.decode_data(token))
  920. time_stamp = int(time_stamp)
  921. now_time = int(time.time())
  922. distance = now_time - time_stamp
  923. if token != time_stamp or distance > 60000 or distance < -60000: # 为了全球化时间控制在一天内
  924. return response.json(404)
  925. dvq = Device_Info.objects.filter(UID=UID)
  926. dvq = dvq.filter(~Q(vodPrimaryUserID='')).values('vodPrimaryUserID')
  927. qs = {}
  928. if dvq.exists():
  929. qs = Device_User.objects.filter(userID=dvq[0]['vodPrimaryUserID']).values('userID', 'NickName', 'username',
  930. 'userEmail', 'phone')
  931. NickName = qs[0]['username']
  932. phone = qs[0]['phone']
  933. username = qs[0]['username']
  934. qs = CommonService.qs_to_list(qs)
  935. if NickName =='':
  936. qs[0]['NickName'] = username
  937. if phone =='':
  938. qs[0]['phone'] = NickName
  939. return response.json(0, qs)
  940. def do_get_device_features(self, request_dict, response):
  941. uid = request_dict.get('uid', None)
  942. if uid:
  943. uid = CommonService.decode_data(uid)
  944. if uid:
  945. uid_qs = UidSetModel.objects.filter(uid=uid)
  946. if uid_qs.exists():
  947. uid_qs = uid_qs.values('is_alexa', 'is_human', 'is_custom_voice', 'double_wifi')
  948. return response.json(0, uid_qs[0])
  949. else:
  950. return response.json(173)
  951. else:
  952. return response.json(444)
  953. else:
  954. return response.json(444)