DetectControllerV2.py 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  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 calendar
  15. import datetime
  16. import json
  17. import logging
  18. import os
  19. import time
  20. import apns2
  21. import boto3
  22. import botocore
  23. import jpush as jpush
  24. import pendulum
  25. from botocore import client
  26. from django.http import JsonResponse
  27. from django.views.generic.base import View
  28. from pyfcm import FCMNotification
  29. from AnsjerPush.config import AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
  30. from AnsjerPush.config import JPUSH_CONFIG, FCM_CONFIG, \
  31. APNS_CONFIG, BASE_DIR, APNS_MODE
  32. from AnsjerPush.config import SERVER_TYPE
  33. from Model.models import Equipment_Info, UidPushModel, SysMsgModel
  34. from Object.ETkObject import ETkObject
  35. from Object.RedisObject import RedisObject
  36. from Object.UidTokenObject import UidTokenObject
  37. from Object.utils import LocalDateTimeUtil
  38. from Service.CommonService import CommonService
  39. from Service.EquipmentInfoService import EquipmentInfoService
  40. '''
  41. http://push.dvema.com/notify/push?etk=Y2lTRXhMTjBWS01sWlpURTVJU0ZWTlJ6RXhNVUU9T3o=&n_time=1526845794&channel=1&event_type=704&is_st=0
  42. http://push.dvema.com/deviceShadow/generateUTK?username=debug_user&password=debug_password&uid=VVDHCVBYDKFMJRWA111A
  43. '''
  44. # 移动侦测接口
  45. class NotificationView(View):
  46. def get(self, request, *args, **kwargs):
  47. request.encoding = 'utf-8'
  48. return self.validation(request.GET)
  49. def post(self, request, *args, **kwargs):
  50. request.encoding = 'utf-8'
  51. operation = kwargs.get('operation')
  52. if operation == 'test_apns':
  53. return self.test_apns(request.POST)
  54. return self.validation(request.POST)
  55. def validation(self, request_dict):
  56. logger = logging.getLogger('info')
  57. logger.info("进来推送接口了")
  58. logger.info(request_dict)
  59. logger.info('使用配置: {}'.format(SERVER_TYPE))
  60. uidToken = request_dict.get('uidToken', None)
  61. etk = request_dict.get('etk', None)
  62. channel = request_dict.get('channel', '1')
  63. n_time = request_dict.get('n_time', None)
  64. event_type = request_dict.get('event_type', None)
  65. is_st = request_dict.get('is_st', None)
  66. company_secrete = request_dict.get('company_secrete', None)
  67. region = request_dict.get('region', None)
  68. electricity = request_dict.get('electricity', '')
  69. if not all([channel, n_time]):
  70. return JsonResponse(status=200, data={
  71. 'code': 444,
  72. 'msg': 'param is wrong'})
  73. if not region or not is_st:
  74. return JsonResponse(status=200, data={'code': 404, 'msg': 'no region or is_st'})
  75. try:
  76. is_st = int(is_st)
  77. region = int(region)
  78. # 解密获取uid
  79. if etk:
  80. eto = ETkObject(etk)
  81. uid = eto.uid
  82. else:
  83. uto = UidTokenObject(uidToken)
  84. uid = uto.UID
  85. # uid = request_dict.get('uid', None) # 调试
  86. # 判断uid长度
  87. if len(uid) != 20 and len(uid) != 14:
  88. return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong uid'})
  89. logger.info('调用推送接口的uid:{}'.format(uid))
  90. pkey = '{uid}_{channel}_{event_type}_ptl'.format(uid=uid, channel=channel, event_type=event_type)
  91. ykey = '{uid}_redis_qs'.format(uid=uid)
  92. is_sys_msg = self.is_sys_msg(int(event_type))
  93. if is_sys_msg:
  94. dkey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, channel=channel, event_type=event_type)
  95. else:
  96. dkey = '{uid}_{channel}_flag'.format(uid=uid, channel=channel)
  97. redisObj = RedisObject(db=6)
  98. have_ykey = redisObj.get_data(key=ykey) # uid_set 数据库缓存
  99. have_pkey = redisObj.get_data(key=pkey) # 一分钟限制key
  100. have_dkey = redisObj.get_data(key=dkey) # 推送消息时间间隔
  101. logger.info('ykey:{}, pkey: {}, dkey: {},'.format(have_ykey, have_pkey, have_dkey))
  102. # 一分钟内不推送
  103. if have_pkey:
  104. return JsonResponse(status=200, data={'code': 0, 'msg': 'Push again in one minute'})
  105. redisObj.set_data(key=pkey, val=1, expire=60)
  106. # 查询推送数据
  107. uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
  108. values('token_val', 'app_type', 'appBundleId', 'm_code', 'push_type', 'userID_id', 'userID__NickName',
  109. 'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
  110. 'uid_set__channel')
  111. if not uid_push_qs.exists():
  112. logger.info('uid_push 数据不存在')
  113. return JsonResponse(status=200, data={'code': 176, 'msg': 'no uid_push data'})
  114. redis_list = []
  115. for qs in uid_push_qs:
  116. redis_list.append(qs)
  117. # 修改redis数据,并设置过期时间为10分钟
  118. redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
  119. nickname = redis_list[0]['uid_set__nickname']
  120. detect_interval = redis_list[0]['uid_set__detect_interval']
  121. detect_group = redis_list[0]['uid_set__detect_group']
  122. if not nickname:
  123. nickname = uid
  124. if not have_dkey:
  125. # 设置推送消息的时间间隔
  126. if detect_group == '0' or detect_group == '':
  127. redisObj.set_data(key=dkey, val=1, expire=detect_interval)
  128. else:
  129. detect_group_list = detect_group.split(',')
  130. if event_type in detect_group_list:
  131. if detect_interval < 60:
  132. detect_interval = 60
  133. redisObj.set_data(key=dkey, val=1, expire=detect_interval)
  134. if is_st == 1 or is_st == 3: # 使用aws s3
  135. aws_s3_client = s3_client(region=region)
  136. kwag_args = {
  137. 'uid': uid,
  138. 'channel': channel,
  139. 'event_type': event_type,
  140. 'n_time': n_time,
  141. }
  142. eq_list = []
  143. sys_msg_list = []
  144. userID_ids = []
  145. do_apns_code = ''
  146. do_fcm_code = ''
  147. do_jpush_code = ''
  148. logger.info('进入手机推送------')
  149. logger.info('uid={}'.format(uid))
  150. logger.info(redis_list)
  151. new_device_info_list = []
  152. local_date_time = ''
  153. for up in redis_list:
  154. push_type = up['push_type']
  155. appBundleId = up['appBundleId']
  156. token_val = up['token_val']
  157. lang = up['lang']
  158. tz = up['tz']
  159. if tz is None or tz == '':
  160. tz = 0
  161. # 发送标题
  162. msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
  163. # 发送内容
  164. msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
  165. event_type=event_type, electricity=electricity)
  166. kwag_args['appBundleId'] = appBundleId
  167. kwag_args['token_val'] = token_val
  168. kwag_args['msg_title'] = msg_title
  169. kwag_args['msg_text'] = msg_text
  170. logger.info('推送要的数据: {}'.format(kwag_args))
  171. local_date_time = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang='cn')
  172. logger.info('<<<<<根据时区计算后日期={},时区={}'.format(local_date_time, tz))
  173. local_date_time = local_date_time[0:10]
  174. logger.info('<<<<<切片后的日期={}'.format(local_date_time))
  175. # 以下是存库
  176. userID_id = up["userID_id"]
  177. if userID_id not in userID_ids:
  178. now_time = int(time.time())
  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, electricity=electricity, 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. else:
  190. # eq_list.append(Equipment_Info(
  191. # userID_id=userID_id,
  192. # eventTime=n_time,
  193. # eventType=event_type,
  194. # devUid=uid,
  195. # devNickName=nickname,
  196. # Channel=channel,
  197. # alarm='Motion \tChannel:{channel}'.format(channel=channel),
  198. # is_st=is_st,
  199. # receiveTime=n_time,
  200. # addTime=now_time,
  201. # storage_location=2,
  202. # borderCoords='',
  203. # ))
  204. # start 根据设备侦测时间为准进行分表存储数据
  205. logger.info('分表存数据start------')
  206. new_device_info_list.append(EquipmentInfoService.get_equipment_info_obj(
  207. local_date_time,
  208. device_user_id=userID_id,
  209. event_time=n_time,
  210. event_type=event_type,
  211. device_uid=uid,
  212. device_nick_name=nickname,
  213. channel=channel,
  214. alarm='Motion \tChannel:{channel}'.format(channel=channel),
  215. is_st=is_st,
  216. receive_time=n_time,
  217. add_time=now_time,
  218. storage_location=2,
  219. border_coords='',
  220. ))
  221. # end
  222. userID_ids.append(userID_id)
  223. try:
  224. # 推送消息
  225. if not have_dkey:
  226. if push_type == 0: # ios apns
  227. do_apns_code = self.do_apns(**kwag_args)
  228. logger.info('进入do_apns,uid={}'.format(uid))
  229. logger.info('do_apns_code===={}'.format(do_apns_code))
  230. elif push_type == 1: # android gcm
  231. do_fcm_code = self.do_fcm(**kwag_args)
  232. elif push_type == 2: # android jpush
  233. do_jpush_code = self.do_jpush(**kwag_args)
  234. except Exception as e:
  235. logger.info(
  236. "errLine={errLine}, errMsg={errMsg}".format(errLine=e.__traceback__.tb_lineno, errMsg=repr(e)))
  237. continue
  238. if is_sys_msg:
  239. SysMsgModel.objects.bulk_create(sys_msg_list)
  240. else:
  241. # Equipment_Info.objects.bulk_create(eq_list)
  242. # new 分表批量存储 设备信息
  243. if new_device_info_list and len(new_device_info_list) > 0:
  244. # 根据日期获得星期几
  245. week = LocalDateTimeUtil.date_to_week(local_date_time)
  246. EquipmentInfoService.equipment_info_bulk_create(week, new_device_info_list)
  247. logger.info('设备信息分表批量保存end------')
  248. if is_st == 0 or is_st == 2:
  249. for up in redis_list:
  250. if up['push_type'] == 0: # ios apns
  251. up['do_apns_code'] = do_apns_code
  252. elif up['push_type'] == 1: # android gcm
  253. up['do_fcm_code'] = do_fcm_code
  254. elif up['push_type'] == 2: # android jpush
  255. up['do_jpush_code'] = do_jpush_code
  256. up['test_or_www'] = SERVER_TYPE
  257. del up['push_type']
  258. del up['userID_id']
  259. del up['userID__NickName']
  260. del up['lang']
  261. del up['tz']
  262. del up['uid_set__nickname']
  263. del up['uid_set__detect_interval']
  264. del up['uid_set__detect_group']
  265. return JsonResponse(status=200, data={'code': 0, 'msg': 'success 0 or 2', 're_list': redis_list})
  266. elif is_st == 1:
  267. thumbspng = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
  268. Params = {'Key': thumbspng}
  269. if region == 2: # 2:国内
  270. Params['Bucket'] = 'push'
  271. else: # 1:国外
  272. Params['Bucket'] = 'foreignpush'
  273. response_url = generate_s3_url(aws_s3_client, Params)
  274. for up in redis_list:
  275. up['do_apns_code'] = do_apns_code
  276. up['do_fcm_code'] = do_fcm_code
  277. up['do_jpush_code'] = do_jpush_code
  278. up['test_or_www'] = SERVER_TYPE
  279. del up['push_type']
  280. del up['userID_id']
  281. del up['userID__NickName']
  282. del up['lang']
  283. del up['tz']
  284. del up['uid_set__nickname']
  285. del up['uid_set__detect_interval']
  286. del up['uid_set__detect_group']
  287. res_data = {'code': 0, 'img_push': response_url, 'msg': 'success'}
  288. return JsonResponse(status=200, data=res_data)
  289. elif is_st == 3:
  290. img_url_list = []
  291. if region == 2: # 2:国内
  292. Params = {'Bucket': 'push'}
  293. else: # 1:国外
  294. Params = {'Bucket': 'foreignpush'}
  295. for i in range(is_st):
  296. thumbspng = '{uid}/{channel}/{filename}_{st}.jpeg'. \
  297. format(uid=uid, channel=channel, filename=n_time, st=i)
  298. Params['Key'] = thumbspng
  299. response_url = generate_s3_url(aws_s3_client, Params)
  300. img_url_list.append(response_url)
  301. for up in redis_list:
  302. up['do_apns_code'] = do_apns_code
  303. up['do_fcm_code'] = do_fcm_code
  304. up['do_jpush_code'] = do_jpush_code
  305. up['test_or_www'] = SERVER_TYPE
  306. del up['push_type']
  307. del up['userID_id']
  308. del up['userID__NickName']
  309. del up['lang']
  310. del up['tz']
  311. del up['uid_set__nickname']
  312. del up['uid_set__detect_interval']
  313. del up['uid_set__detect_group']
  314. res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3'}
  315. return JsonResponse(status=200, data=res_data)
  316. except Exception as e:
  317. logger.info('移动侦测接口异常: {}'.format(e))
  318. logger.info('错误文件', e.__traceback__.tb_frame.f_globals['__file__'])
  319. logger.info('错误行号', e.__traceback__.tb_lineno)
  320. data = {
  321. 'errLine': e.__traceback__.tb_lineno,
  322. 'errMsg': repr(e),
  323. }
  324. return JsonResponse(status=200, data=json.dumps(data), safe=False)
  325. def test_apns(self, request_dict):
  326. kwag_args = {
  327. 'uid': request_dict.get('uid', None),
  328. 'channel': request_dict.get('channel', None),
  329. 'event_type': request_dict.get('event_type', None),
  330. 'n_time': request_dict.get('n_time', None),
  331. 'appBundleId': request_dict.get('appBundleId', None),
  332. 'token_val': request_dict.get('token_val', None),
  333. 'msg_title': request_dict.get('msg_title', None),
  334. 'msg_text': request_dict.get('msg_text', None),
  335. }
  336. do_apns_code = self.do_apns(**kwag_args)
  337. return JsonResponse(status=500, data={'do_apns_code': do_apns_code})
  338. def get_msg_title(self, appBundleId, nickname):
  339. package_title_config = {
  340. 'com.ansjer.customizedd_a': 'DVS',
  341. 'com.ansjer.zccloud_a': 'ZosiSmart',
  342. 'com.ansjer.zccloud_ab': '周视',
  343. 'com.ansjer.adcloud_a': 'ADCloud',
  344. 'com.ansjer.adcloud_ab': 'ADCloud',
  345. 'com.ansjer.accloud_a': 'ACCloud',
  346. 'com.ansjer.loocamccloud_a': 'Loocam',
  347. 'com.ansjer.loocamdcloud_a': 'Anlapus',
  348. 'com.ansjer.customizedb_a': 'COCOONHD',
  349. 'com.ansjer.customizeda_a': 'Guardian365',
  350. 'com.ansjer.customizedc_a': 'PatrolSecure',
  351. }
  352. if appBundleId in package_title_config.keys():
  353. return package_title_config[appBundleId] + '(' + nickname + ')'
  354. else:
  355. return nickname
  356. def is_sys_msg(self, event_type):
  357. event_type_list = [702, 703, 704]
  358. if event_type in event_type_list:
  359. return True
  360. return False
  361. def get_msg_text(self, channel, n_time, lang, tz, event_type, electricity='', is_sys=0):
  362. n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang=lang)
  363. etype = int(event_type)
  364. if lang == 'cn':
  365. if etype == 704:
  366. msg_type = '剩余电量:' + electricity
  367. elif etype == 702:
  368. msg_type = '摄像头休眠'
  369. elif etype == 703:
  370. msg_type = '摄像头唤醒'
  371. else:
  372. msg_type = ''
  373. if is_sys:
  374. send_text = '{msg_type} 通道:{channel}'.format(msg_type=msg_type, channel=channel)
  375. else:
  376. send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
  377. # send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
  378. else:
  379. if etype == 704:
  380. msg_type = 'Battery remaining:' + electricity
  381. elif etype == 702:
  382. msg_type = 'Camera sleep'
  383. elif etype == 703:
  384. msg_type = 'Camera wake'
  385. else:
  386. msg_type = ''
  387. if is_sys:
  388. send_text = '{msg_type} channel:{channel}'. \
  389. format(msg_type=msg_type, channel=channel)
  390. else:
  391. send_text = '{msg_type} channel:{channel} date:{date}'. \
  392. format(msg_type=msg_type, channel=channel, date=n_date)
  393. return send_text
  394. def do_jpush(self, uid, channel, appBundleId, token_val, event_type, n_time,
  395. msg_title, msg_text):
  396. app_key = JPUSH_CONFIG[appBundleId]['Key']
  397. master_secret = JPUSH_CONFIG[appBundleId]['Secret']
  398. # 此处换成各自的app_key和master_secre
  399. _jpush = jpush.JPush(app_key, master_secret)
  400. push = _jpush.create_push()
  401. # if you set the logging level to "DEBUG",it will show the debug logging.
  402. # _jpush.set_logging("DEBUG")
  403. # push.audience = jpush.all_
  404. push.audience = jpush.registration_id(token_val)
  405. push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  406. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
  407. android = jpush.android(alert=msg_text, priority=1, style=1, alert_type=7,
  408. big_text=msg_text, title=msg_title,
  409. extras=push_data)
  410. push.notification = jpush.notification(android=android)
  411. push.platform = jpush.all_
  412. res = push.send()
  413. print(res)
  414. return res.status_code
  415. # try:
  416. # res = push.send()
  417. # print(res)
  418. # except Exception as e:
  419. # print("jpush fail")
  420. # print("Exception")
  421. # print(repr(e))
  422. # return
  423. # else:
  424. # print("jpush success")
  425. # return
  426. def do_fcm(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
  427. logger = logging.getLogger('info')
  428. try:
  429. serverKey = FCM_CONFIG[appBundleId]
  430. except Exception as e:
  431. logger.info('------fcm_error:{}'.format(repr(e)))
  432. return 'serverKey abnormal'
  433. push_service = FCMNotification(api_key=serverKey)
  434. data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  435. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
  436. result = push_service.notify_single_device(registration_id=token_val, message_title=msg_title,
  437. message_body=msg_text, data_message=data,
  438. extra_kwargs={
  439. 'default_vibrate_timings': True,
  440. 'default_sound': True,
  441. 'default_light_settings': True
  442. })
  443. logger.info('------fcm_status:')
  444. logger.info(result)
  445. print('fcm push ing')
  446. print(result)
  447. return result
  448. def do_apns(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title,
  449. msg_text):
  450. logger = logging.getLogger('info')
  451. logger.info("进来do_apns函数了")
  452. logger.info(token_val)
  453. logger.info(APNS_MODE)
  454. logger.info(os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
  455. try:
  456. cli = apns2.APNSClient(mode=APNS_MODE,
  457. client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
  458. push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  459. "received_at": n_time, "sound": "", "uid": uid, "zpush": "1", "channel": channel}
  460. alert = apns2.PayloadAlert(body=msg_text, title=msg_title)
  461. payload = apns2.Payload(alert=alert, custom=push_data, sound="default")
  462. # return uid, channel, appBundleId, str(token_val), event_type, n_time, msg_title,msg_text
  463. n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
  464. res = cli.push(n=n, device_token=token_val, topic=appBundleId)
  465. print(res.status_code)
  466. logger.info("apns_推送状态:")
  467. logger.info(res.status_code)
  468. # 200, 推送成功。
  469. #   400, 请求有问题。
  470. #   403, 证书或Token有问题。
  471. #   405, 请求方式不正确, 只支持POST请求
  472. #   410, 设备的Token与证书不一致
  473. if res.status_code == 200:
  474. return res.status_code
  475. else:
  476. print('apns push fail')
  477. print(res.reason)
  478. logger.info('apns push fail')
  479. logger.info(res.reason)
  480. return res.status_code
  481. except (ValueError, ArithmeticError):
  482. return 'The program has a numeric format exception, one of the arithmetic exceptions'
  483. except Exception as e:
  484. print(repr(e))
  485. print('do_apns函数错误行号', e.__traceback__.tb_lineno)
  486. logger.info('do_apns错误:{}'.format(repr(e)))
  487. return repr(e)
  488. def do_update_detect_interval(self, uid, channel, redisObject, detect_interval):
  489. if channel == 0:
  490. channel = 17
  491. else:
  492. channel += 1
  493. for i in range(1, channel):
  494. tmpDKey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=51, channel=i)
  495. if tmpDKey is not False:
  496. llt = redisObject.get_ttl(tmpDKey)
  497. if llt > detect_interval:
  498. redisObject.set_data(key=tmpDKey, val=1, expire=detect_interval)
  499. tmpDKey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=54, channel=i)
  500. if tmpDKey is not False:
  501. llt = redisObject.get_ttl(tmpDKey)
  502. if llt > detect_interval:
  503. redisObject.set_data(key=tmpDKey, val=1, expire=detect_interval)
  504. # http://test.dvema.com/detect/add?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
  505. # 移动侦测接口
  506. class PushNotificationView(View):
  507. def get(self, request, *args, **kwargs):
  508. request.encoding = 'utf-8'
  509. # operation = kwargs.get('operation')
  510. return self.validation(request.GET)
  511. def post(self, request, *args, **kwargs):
  512. request.encoding = 'utf-8'
  513. # operation = kwargs.get('operation')
  514. return self.validation(request.POST)
  515. def validation(self, request_dict):
  516. etk = request_dict.get('etk', None)
  517. channel = request_dict.get('channel', '1')
  518. n_time = request_dict.get('n_time', None)
  519. event_type = request_dict.get('event_type', None)
  520. is_st = request_dict.get('is_st', None)
  521. region = request_dict.get('region', '2')
  522. region = int(region)
  523. eto = ETkObject(etk)
  524. uid = eto.uid
  525. if len(uid) == 20:
  526. redisObj = RedisObject(db=6)
  527. # pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
  528. pkey = '{uid}_ptl'.format(uid=uid)
  529. ykey = '{uid}_redis_qs'.format(uid=uid)
  530. if redisObj.get_data(key=pkey):
  531. res_data = {'code': 0, 'msg': 'success,!33333333333'}
  532. return JsonResponse(status=200, data=res_data)
  533. else:
  534. redisObj.set_data(key=pkey, val=1, expire=60)
  535. ##############
  536. redis_data = redisObj.get_data(key=ykey)
  537. if redis_data:
  538. redis_list = eval(redis_data)
  539. else:
  540. # 设置推送时间为60秒一次
  541. redisObj.set_data(key=pkey, val=1, expire=60)
  542. print("从数据库查到数据")
  543. # 从数据库查询出来
  544. uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
  545. values('token_val', 'app_type', 'appBundleId',
  546. 'push_type', 'userID_id', 'lang', 'm_code',
  547. 'tz', 'uid_set__nickname')
  548. # 新建一个list接收数据
  549. redis_list = []
  550. # 把数据库数据追加进redis_list
  551. for qs in uid_push_qs:
  552. redis_list.append(qs)
  553. # 修改redis数据,并设置过期时间为10分钟
  554. if redis_list:
  555. redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
  556. # auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
  557. # bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
  558. aws_s3_guonei = boto3.client(
  559. 's3',
  560. aws_access_key_id=AWS_ACCESS_KEY_ID[0],
  561. aws_secret_access_key=AWS_SECRET_ACCESS_KEY[0],
  562. config=botocore.client.Config(signature_version='s3v4'),
  563. region_name='cn-northwest-1'
  564. )
  565. aws_s3_guowai = boto3.client(
  566. 's3',
  567. aws_access_key_id=AWS_ACCESS_KEY_ID[1],
  568. aws_secret_access_key=AWS_SECRET_ACCESS_KEY[1],
  569. config=botocore.client.Config(signature_version='s3v4'),
  570. region_name='us-east-1'
  571. )
  572. self.do_bulk_create_info(redis_list, n_time, channel, event_type, is_st, uid)
  573. if is_st == '0' or is_st == '2':
  574. return JsonResponse(status=200, data={'code': 0, 'msg': 'success44444444444444444'})
  575. elif is_st == '1':
  576. # Endpoint以杭州为例,其它Region请按实际情况填写。
  577. # obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
  578. # 设置此签名URL在60秒内有效。
  579. # url = bucket.sign_url('PUT', obj, 7200)
  580. thumbspng = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
  581. if region == 2: # 2:国内
  582. response_url = aws_s3_guonei.generate_presigned_url(
  583. ClientMethod='put_object',
  584. Params={
  585. 'Bucket': 'push',
  586. 'Key': thumbspng
  587. },
  588. ExpiresIn=3600
  589. )
  590. else: # 1:国外
  591. response_url = aws_s3_guowai.generate_presigned_url(
  592. ClientMethod='put_object',
  593. Params={
  594. 'Bucket': 'foreignpush',
  595. 'Key': thumbspng
  596. },
  597. ExpiresIn=3600
  598. )
  599. # res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
  600. # response_url = response_url[:4] + response_url[5:]
  601. res_data = {'code': 0, 'img_push': response_url, 'msg': 'success'}
  602. return JsonResponse(status=200, data=res_data)
  603. elif is_st == '3':
  604. # 人形检测带动图
  605. img_url_list = []
  606. for i in range(int(is_st)):
  607. # obj = '{uid}/{channel}/{filename}_{st}.jpeg'. \
  608. # format(uid=uid, channel=channel, filename=n_time, st=i)
  609. # 设置此签名URL在60秒内有效。
  610. # url = bucket.sign_url('PUT', obj, 7200)
  611. thumbspng = '{uid}/{channel}/{filename}_{st}.jpeg'. \
  612. format(uid=uid, channel=channel, filename=n_time, st=i)
  613. if region == 2: # 2:国内
  614. response_url = aws_s3_guonei.generate_presigned_url(
  615. ClientMethod='put_object',
  616. Params={
  617. 'Bucket': 'push',
  618. 'Key': thumbspng
  619. },
  620. ExpiresIn=3600
  621. )
  622. else: # 1:国外
  623. response_url = aws_s3_guowai.generate_presigned_url(
  624. ClientMethod='put_object',
  625. Params={
  626. 'Bucket': 'foreignpush',
  627. 'Key': thumbspng
  628. },
  629. ExpiresIn=3600
  630. )
  631. # response_url = response_url[:4] + response_url[5:]
  632. img_url_list.append(response_url)
  633. # img_url_list.append(url)
  634. res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success'}
  635. return JsonResponse(status=200, data=res_data)
  636. else:
  637. return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
  638. else:
  639. return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong etk'})
  640. def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
  641. now_time = int(time.time())
  642. # 设备昵称
  643. userID_ids = []
  644. sys_msg_list = []
  645. is_sys_msg = self.is_sys_msg(int(event_type))
  646. is_st = int(is_st)
  647. eq_list = []
  648. nickname = uaqs[0]['uid_set__nickname']
  649. if not nickname:
  650. nickname = uid
  651. for ua in uaqs:
  652. lang = ua['lang']
  653. tz = ua['tz']
  654. userID_id = ua["userID_id"]
  655. if userID_id not in userID_ids:
  656. if is_sys_msg:
  657. sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
  658. event_type=event_type, is_sys=1)
  659. sys_msg_list.append(SysMsgModel(
  660. userID_id=userID_id,
  661. msg=sys_msg_text,
  662. addTime=now_time,
  663. updTime=now_time,
  664. uid=uid,
  665. eventType=event_type))
  666. else:
  667. eq_list.append(Equipment_Info(
  668. userID_id=userID_id,
  669. eventTime=n_time,
  670. eventType=event_type,
  671. devUid=uid,
  672. devNickName=nickname,
  673. Channel=channel,
  674. alarm='Motion \tChannel:{channel}'.format(channel=channel),
  675. is_st=is_st,
  676. receiveTime=n_time,
  677. addTime=now_time,
  678. storage_location=2,
  679. borderCoords='',
  680. ))
  681. if eq_list:
  682. print('eq_list')
  683. Equipment_Info.objects.bulk_create(eq_list)
  684. if is_sys_msg:
  685. print('sys_msg')
  686. SysMsgModel.objects.bulk_create(sys_msg_list)
  687. return True
  688. def is_sys_msg(self, event_type):
  689. event_type_list = [702, 703, 704]
  690. if event_type in event_type_list:
  691. return True
  692. return False
  693. def get_msg_text(self, channel, n_time, lang, tz, event_type, is_sys=0):
  694. n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz)
  695. etype = int(event_type)
  696. if lang == 'cn':
  697. if etype == 704:
  698. msg_type = '剩余电量:'
  699. elif etype == 702:
  700. msg_type = '摄像头休眠'
  701. elif etype == 703:
  702. msg_type = '摄像头唤醒'
  703. else:
  704. msg_type = ''
  705. if is_sys:
  706. send_text = '{msg_type} 通道:{channel}'.format(msg_type=msg_type, channel=channel)
  707. else:
  708. send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
  709. else:
  710. if etype == 704:
  711. msg_type = 'Battery remaining:'
  712. elif etype == 702:
  713. msg_type = 'Camera sleep'
  714. elif etype == 703:
  715. msg_type = 'Camera wake'
  716. else:
  717. msg_type = ''
  718. if is_sys:
  719. send_text = '{msg_type} channel:{channel}'. \
  720. format(msg_type=msg_type, channel=channel)
  721. else:
  722. send_text = '{msg_type} channel:{channel} date:{date}'. \
  723. format(msg_type=msg_type, channel=channel, date=n_date)
  724. return send_text
  725. # 低电量推送接口
  726. class PWnotificationView(View):
  727. def get(self, request, *args, **kwargs):
  728. request.encoding = 'utf-8'
  729. return self.validation(request.GET)
  730. def post(self, request, *args, **kwargs):
  731. request.encoding = 'utf-8'
  732. return self.validation(request.POST)
  733. def validation(self, request_dict):
  734. logger = logging.getLogger('info')
  735. uid = request_dict.get('uid', None)
  736. channel = request_dict.get('channel', None)
  737. electricity = request_dict.get('electricity', None)
  738. logger.info('调用低电量推送接口的uid: {},electricity: {}'.format(uid, electricity))
  739. try:
  740. uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid). \
  741. values('token_val', 'app_type', 'appBundleId', 'm_code',
  742. 'push_type', 'userID_id', 'userID__NickName',
  743. 'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
  744. 'uid_set__channel')
  745. if not uid_push_qs.exists():
  746. res_data = {'code': 173, 'msg': 'uid push data not exit!'}
  747. return JsonResponse(status=200, data=res_data)
  748. print(uid_push_qs)
  749. # 新建一个list接收数据
  750. redis_list = []
  751. # 把数据库数据追加进redis_list
  752. for qs in uid_push_qs:
  753. redis_list.append(qs)
  754. if not redis_list:
  755. res_data = {'code': 0, 'msg': 'no redis_list success!'}
  756. return JsonResponse(status=200, data=res_data)
  757. nickname = redis_list[0]['uid_set__nickname']
  758. if not nickname:
  759. nickname = uid
  760. now_time = int(time.time())
  761. channel = channel
  762. event_type = 704
  763. sys_msg_list = []
  764. userID_ids = []
  765. kwag_args = {
  766. 'uid': uid,
  767. 'channel': channel,
  768. 'event_type': event_type,
  769. 'n_time': now_time,
  770. }
  771. for up in redis_list:
  772. push_type = up['push_type']
  773. appBundleId = up['appBundleId']
  774. token_val = up['token_val']
  775. lang = up['lang']
  776. tz = up['tz']
  777. if tz is None or tz == '':
  778. tz = 0
  779. # 发送标题
  780. msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
  781. # 发送内容
  782. msg_text = self.get_msg_text(channel=channel, n_time=now_time, lang=lang, tz=tz,
  783. event_type=event_type, electricity=electricity)
  784. kwag_args['appBundleId'] = appBundleId
  785. kwag_args['token_val'] = token_val
  786. kwag_args['msg_title'] = msg_title
  787. kwag_args['msg_text'] = msg_text
  788. if push_type == 0: # ios apns
  789. do_apns_code = self.do_apns(**kwag_args)
  790. elif push_type == 1: # android gcm
  791. print('do_fcm')
  792. do_fcm_code = self.do_fcm(**kwag_args)
  793. elif push_type == 2: # android jpush
  794. print('do_jpush')
  795. do_jpush_code = self.do_jpush(**kwag_args)
  796. # 以下是存库
  797. userID_id = up["userID_id"]
  798. if userID_id not in userID_ids:
  799. sys_msg_text = self.get_msg_text(channel=channel, n_time=now_time, lang=lang, tz=tz,
  800. event_type=event_type, is_sys=1, electricity=electricity)
  801. sys_msg_list.append(SysMsgModel(
  802. userID_id=userID_id,
  803. msg=sys_msg_text,
  804. addTime=now_time,
  805. updTime=now_time,
  806. uid=uid,
  807. eventType=event_type,
  808. ))
  809. userID_ids.append(userID_id)
  810. SysMsgModel.objects.bulk_create(sys_msg_list)
  811. return JsonResponse(status=200, data={'code': 0})
  812. except Exception as e:
  813. logger.info('低电量推送接口异常: {}'.format(e))
  814. return JsonResponse(status=500)
  815. def get_msg_title(self, appBundleId, nickname):
  816. package_title_config = {
  817. 'com.ansjer.customizedd_a': 'DVS',
  818. 'com.ansjer.zccloud_a': 'ZosiSmart',
  819. 'com.ansjer.zccloud_ab': '周视',
  820. 'com.ansjer.adcloud_a': 'ADCloud',
  821. 'com.ansjer.adcloud_ab': 'ADCloud',
  822. 'com.ansjer.accloud_a': 'ACCloud',
  823. 'com.ansjer.loocamccloud_a': 'Loocam',
  824. 'com.ansjer.loocamdcloud_a': 'Anlapus',
  825. 'com.ansjer.customizedb_a': 'COCOONHD',
  826. 'com.ansjer.customizeda_a': 'Guardian365',
  827. 'com.ansjer.customizedc_a': 'PatrolSecure',
  828. }
  829. if appBundleId in package_title_config.keys():
  830. return package_title_config[appBundleId] + '(' + nickname + ')'
  831. else:
  832. return nickname
  833. def is_sys_msg(self, event_type):
  834. event_type_list = [702, 703, 704]
  835. if event_type in event_type_list:
  836. return True
  837. return False
  838. def get_msg_text(self, channel, n_time, lang, tz, event_type, electricity, is_sys=0):
  839. n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang=lang)
  840. etype = int(event_type)
  841. if lang == 'cn':
  842. if etype == 704:
  843. msg_type = '剩余电量:' + electricity
  844. elif etype == 702:
  845. msg_type = '摄像头休眠'
  846. elif etype == 703:
  847. msg_type = '摄像头唤醒'
  848. else:
  849. msg_type = ''
  850. if is_sys:
  851. send_text = '{msg_type} 通道:{channel}'.format(msg_type=msg_type, channel=channel)
  852. else:
  853. send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
  854. # send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
  855. else:
  856. if etype == 704:
  857. msg_type = 'Battery remaining:' + electricity
  858. elif etype == 702:
  859. msg_type = 'Camera sleep'
  860. elif etype == 703:
  861. msg_type = 'Camera wake'
  862. else:
  863. msg_type = ''
  864. if is_sys:
  865. send_text = '{msg_type} channel:{channel}'. \
  866. format(msg_type=msg_type, channel=channel)
  867. else:
  868. send_text = '{msg_type} channel:{channel} date:{date}'. \
  869. format(msg_type=msg_type, channel=channel, date=n_date)
  870. return send_text
  871. def do_jpush(self, uid, channel, appBundleId, token_val, event_type, n_time,
  872. msg_title, msg_text):
  873. app_key = JPUSH_CONFIG[appBundleId]['Key']
  874. master_secret = JPUSH_CONFIG[appBundleId]['Secret']
  875. # 此处换成各自的app_key和master_secre
  876. _jpush = jpush.JPush(app_key, master_secret)
  877. push = _jpush.create_push()
  878. # if you set the logging level to "DEBUG",it will show the debug logging.
  879. # _jpush.set_logging("DEBUG")
  880. # push.audience = jpush.all_
  881. push.audience = jpush.registration_id(token_val)
  882. push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  883. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
  884. android = jpush.android(alert=msg_text, priority=1, style=1, alert_type=7,
  885. big_text=msg_text, title=msg_title,
  886. extras=push_data)
  887. push.notification = jpush.notification(android=android)
  888. push.platform = jpush.all_
  889. res = push.send()
  890. print(res)
  891. return res.status_code
  892. # try:
  893. # res = push.send()
  894. # print(res)
  895. # except Exception as e:
  896. # print("jpush fail")
  897. # print("Exception")
  898. # print(repr(e))
  899. # return
  900. # else:
  901. # print("jpush success")
  902. # return
  903. def do_fcm(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
  904. try:
  905. serverKey = FCM_CONFIG[appBundleId]
  906. except Exception as e:
  907. return 'serverKey abnormal'
  908. push_service = FCMNotification(api_key=serverKey)
  909. data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  910. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
  911. result = push_service.notify_single_device(registration_id=token_val, message_title=msg_title,
  912. message_body=msg_text, data_message=data,
  913. extra_kwargs={
  914. 'default_vibrate_timings': True,
  915. 'default_sound': True,
  916. 'default_light_settings': True
  917. })
  918. print('fcm push ing')
  919. print(result)
  920. return result
  921. def do_apns(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title,
  922. msg_text):
  923. logger = logging.getLogger('info')
  924. logger.info("进来do_apns函数了")
  925. logger.info(token_val)
  926. logger.info(APNS_MODE)
  927. logger.info(os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
  928. try:
  929. cli = apns2.APNSClient(mode=APNS_MODE,
  930. client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
  931. push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  932. "received_at": n_time, "sound": "", "uid": uid, "zpush": "1", "channel": channel}
  933. alert = apns2.PayloadAlert(body=msg_text, title=msg_title)
  934. payload = apns2.Payload(alert=alert, custom=push_data, sound="default")
  935. # return uid, channel, appBundleId, str(token_val), event_type, n_time, msg_title,msg_text
  936. n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
  937. res = cli.push(n=n, device_token=token_val, topic=appBundleId)
  938. print(res.status_code)
  939. logger.info("推送状态:")
  940. logger.info(res.status_code)
  941. # 200, 推送成功。
  942. #   400, 请求有问题。
  943. #   403, 证书或Token有问题。
  944. #   405, 请求方式不正确, 只支持POST请求
  945. #   410, 设备的Token与证书不一致
  946. if res.status_code == 200:
  947. return res.status_code
  948. else:
  949. print('apns push fail')
  950. print(res.reason)
  951. logger.info('apns push fail')
  952. logger.info(res.reason)
  953. return res.status_code
  954. except (ValueError, ArithmeticError):
  955. return 'The program has a numeric format exception, one of the arithmetic exceptions'
  956. except Exception as e:
  957. print(repr(e))
  958. logger.info(repr(e))
  959. return repr(e)
  960. def do_update_detect_interval(self, uid, channel, redisObject, detect_interval):
  961. if channel == 0:
  962. channel = 17
  963. else:
  964. channel += 1
  965. for i in range(1, channel):
  966. tmpDKey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=51, channel=i)
  967. if tmpDKey is not False:
  968. llt = redisObject.get_ttl(tmpDKey)
  969. if llt > detect_interval:
  970. redisObject.set_data(key=tmpDKey, val=1, expire=detect_interval)
  971. tmpDKey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=54, channel=i)
  972. if tmpDKey is not False:
  973. llt = redisObject.get_ttl(tmpDKey)
  974. if llt > detect_interval:
  975. redisObject.set_data(key=tmpDKey, val=1, expire=detect_interval)
  976. def s3_client(region):
  977. if region == 2: # 国内
  978. aws_s3_client = boto3.client(
  979. 's3',
  980. aws_access_key_id=AWS_ACCESS_KEY_ID[0],
  981. aws_secret_access_key=AWS_SECRET_ACCESS_KEY[0],
  982. config=botocore.client.Config(signature_version='s3v4'),
  983. region_name='cn-northwest-1'
  984. )
  985. else: # 国外
  986. aws_s3_client = boto3.client(
  987. 's3',
  988. aws_access_key_id=AWS_ACCESS_KEY_ID[1],
  989. aws_secret_access_key=AWS_SECRET_ACCESS_KEY[1],
  990. config=botocore.client.Config(signature_version='s3v4'),
  991. region_name='us-east-1'
  992. )
  993. return aws_s3_client
  994. def generate_s3_url(aws_s3_client, Params):
  995. response_url = aws_s3_client.generate_presigned_url(
  996. ClientMethod='put_object',
  997. Params=Params,
  998. ExpiresIn=3600
  999. )
  1000. return response_url