DetectControllerV2.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. import json
  2. import logging
  3. import os
  4. import threading
  5. import time
  6. import apns2
  7. import boto3
  8. import botocore
  9. import jpush as jpush
  10. from botocore import client
  11. from django.http import JsonResponse
  12. from django.views.generic.base import View
  13. from pyfcm import FCMNotification
  14. from AnsjerPush.config import AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
  15. from AnsjerPush.config import JPUSH_CONFIG, FCM_CONFIG, APNS_CONFIG, BASE_DIR, APNS_MODE
  16. from AnsjerPush.config import SERVER_TYPE
  17. from Model.models import UidPushModel, SysMsgModel
  18. from Object.ETkObject import ETkObject
  19. from Object.RedisObject import RedisObject
  20. from Object.UidTokenObject import UidTokenObject
  21. from Object.utils import LocalDateTimeUtil
  22. from Service.CommonService import CommonService
  23. from Service.EquipmentInfoService import EquipmentInfoService
  24. from Service.GatewayService import GatewayPushService
  25. # 移动侦测V2接口
  26. class NotificationV2View(View):
  27. def get(self, request, *args, **kwargs):
  28. request.encoding = 'utf-8'
  29. return self.validation(request.GET)
  30. def post(self, request, *args, **kwargs):
  31. request.encoding = 'utf-8'
  32. return self.validation(request.POST)
  33. def validation(self, request_dict):
  34. logger = logging.getLogger('info')
  35. logger.info("移动侦测V2接口参数:{}".format(request_dict))
  36. uidToken = request_dict.get('uidToken', None)
  37. etk = request_dict.get('etk', None)
  38. channel = request_dict.get('channel', '1')
  39. n_time = request_dict.get('n_time', None)
  40. event_type = request_dict.get('event_type', None)
  41. is_st = request_dict.get('is_st', None)
  42. region = request_dict.get('region', None)
  43. electricity = request_dict.get('electricity', '')
  44. if not all([channel, n_time]):
  45. return JsonResponse(status=200, data={
  46. 'code': 444,
  47. 'msg': 'param is wrong'})
  48. if not region or not is_st:
  49. return JsonResponse(status=200, data={'code': 404, 'msg': 'no region or is_st'})
  50. try:
  51. is_st = int(is_st)
  52. region = int(region)
  53. # 解密获取uid
  54. if etk:
  55. eto = ETkObject(etk)
  56. uid = eto.uid
  57. else:
  58. uto = UidTokenObject(uidToken)
  59. uid = uto.UID
  60. # uid = request_dict.get('uid', None) # 调试
  61. # 判断uid长度
  62. if len(uid) != 20 and len(uid) != 14:
  63. return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong uid'})
  64. logger.info('调用推送接口的uid:{}'.format(uid))
  65. pkey = '{uid}_{channel}_{event_type}_ptl'.format(uid=uid, channel=channel, event_type=event_type)
  66. ykey = '{uid}_redis_qs'.format(uid=uid)
  67. is_sys_msg = self.is_sys_msg(int(event_type))
  68. if is_sys_msg:
  69. dkey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, channel=channel, event_type=event_type)
  70. else:
  71. dkey = '{uid}_{channel}_flag'.format(uid=uid, channel=channel)
  72. redisObj = RedisObject(db=6)
  73. have_ykey = redisObj.get_data(key=ykey) # uid_set 数据库缓存
  74. have_pkey = redisObj.get_data(key=pkey) # 一分钟限制key
  75. have_dkey = redisObj.get_data(key=dkey) # 推送消息时间间隔
  76. logger.info('ykey:{}, pkey: {}, dkey: {}'.format(have_ykey, have_pkey, have_dkey))
  77. # 一分钟内不推送
  78. if have_pkey:
  79. return JsonResponse(status=200, data={'code': 0, 'msg': 'Push again in one minute'})
  80. redisObj.set_data(key=pkey, val=1, expire=60)
  81. # 查询推送数据
  82. uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
  83. values('token_val', 'app_type', 'appBundleId', 'm_code', 'push_type', 'userID_id', 'userID__NickName',
  84. 'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
  85. 'uid_set__channel', 'uid_set__ai_type', 'uid_set__new_detect_interval')
  86. if not uid_push_qs.exists():
  87. logger.info('uid_push 数据不存在')
  88. return JsonResponse(status=200, data={'code': 176, 'msg': 'no uid_push data'})
  89. ai_type = uid_push_qs.first()['uid_set__ai_type']
  90. event_type = self.get_combo_msg_type(ai_type, int(event_type))
  91. redis_list = []
  92. for qs in uid_push_qs:
  93. redis_list.append(qs)
  94. # 修改redis数据,并设置过期时间为10分钟
  95. redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
  96. nickname = redis_list[0]['uid_set__nickname']
  97. detect_interval = redis_list[0]['uid_set__detect_interval']
  98. if not nickname:
  99. nickname = uid
  100. if not have_dkey:
  101. # 设置推送消息的时间间隔
  102. if SERVER_TYPE != 'Ansjer.cn_formal_settings':
  103. new_detect_interval = redis_list[0]['uid_set__new_detect_interval']
  104. detect_interval = new_detect_interval if new_detect_interval > 0 else detect_interval
  105. detect_interval = 60 if detect_interval < 60 else detect_interval
  106. redisObj.set_data(key=dkey, val=1, expire=detect_interval - 5)
  107. logger.info('APP消息推送间隔:{}s'.format(detect_interval))
  108. if is_st == 1 or is_st == 3: # 使用aws s3
  109. aws_s3_client = s3_client(region=region)
  110. bucket = 'foreignpush' if region == 1 else 'push'
  111. kwag_args = {
  112. 'uid': uid,
  113. 'channel': channel,
  114. 'event_type': event_type,
  115. 'n_time': n_time,
  116. }
  117. sys_msg_list = []
  118. userID_ids = []
  119. do_apns_code = ''
  120. do_fcm_code = ''
  121. do_jpush_code = ''
  122. logger.info('进入手机推送------')
  123. logger.info('uid={}'.format(uid))
  124. logger.info(redis_list)
  125. new_device_info_list = []
  126. local_date_time = ''
  127. for up in redis_list:
  128. push_type = up['push_type']
  129. appBundleId = up['appBundleId']
  130. token_val = up['token_val']
  131. lang = up['lang']
  132. tz = up['tz']
  133. if tz is None or tz == '':
  134. tz = 0
  135. # 发送标题
  136. msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
  137. # 发送内容
  138. msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
  139. event_type=event_type, electricity=electricity)
  140. kwag_args['appBundleId'] = appBundleId
  141. kwag_args['token_val'] = token_val
  142. kwag_args['msg_title'] = msg_title
  143. kwag_args['msg_text'] = msg_text
  144. logger.info('推送要的数据: {}'.format(kwag_args))
  145. local_date_time = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang='cn')
  146. logger.info('<<<<<根据时区计算后日期={},时区={}'.format(local_date_time, tz))
  147. local_date_time = local_date_time[0:10]
  148. logger.info('<<<<<切片后的日期={}'.format(local_date_time))
  149. # 以下是存库
  150. userID_id = up["userID_id"]
  151. if userID_id not in userID_ids:
  152. now_time = int(time.time())
  153. if is_sys_msg:
  154. sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
  155. event_type=event_type, electricity=electricity, is_sys=1)
  156. sys_msg_list.append(SysMsgModel(
  157. userID_id=userID_id,
  158. msg=sys_msg_text,
  159. addTime=now_time,
  160. updTime=now_time,
  161. uid=uid,
  162. eventType=event_type))
  163. else:
  164. # start 根据设备侦测时间为准进行分表存储数据
  165. logger.info('分表存数据start------')
  166. new_device_info_list.append(EquipmentInfoService.get_equipment_info_obj(
  167. local_date_time,
  168. device_user_id=userID_id,
  169. event_time=n_time,
  170. event_type=event_type,
  171. device_uid=uid,
  172. device_nick_name=nickname,
  173. channel=channel,
  174. alarm='Motion \tChannel:{channel}'.format(channel=channel),
  175. is_st=is_st,
  176. receive_time=n_time,
  177. add_time=now_time,
  178. storage_location=2,
  179. border_coords='',
  180. ))
  181. # end
  182. userID_ids.append(userID_id)
  183. try:
  184. # 推送消息
  185. if not have_dkey:
  186. logger.info('APP准备推送:{}, {}'.format(uid, request_dict))
  187. if (is_st == 1 or is_st == 3) and (push_type == 0 or push_type == 1): # 推送显示图片
  188. if is_st == 1:
  189. key = '{}/{}/{}.jpeg'.format(uid, channel, n_time)
  190. else:
  191. key = '{}/{}/{}_0.jpeg'.format(uid, channel, n_time)
  192. push_thread = threading.Thread(target=self.push_thread_test, args=(
  193. push_type, aws_s3_client, bucket, key, uid, appBundleId, token_val, event_type, n_time,
  194. msg_title, msg_text, channel))
  195. push_thread.start()
  196. else:
  197. if push_type == 0: # ios apns
  198. do_apns_code = self.do_apns(**kwag_args)
  199. elif push_type == 1: # android gcm
  200. do_fcm_code = self.do_fcm(**kwag_args)
  201. elif push_type == 2: # android jpush
  202. do_jpush_code = self.do_jpush(**kwag_args)
  203. except Exception as e:
  204. logger.info(
  205. "errLine={errLine}, errMsg={errMsg}".format(errLine=e.__traceback__.tb_lineno, errMsg=repr(e)))
  206. continue
  207. if is_sys_msg:
  208. SysMsgModel.objects.bulk_create(sys_msg_list)
  209. else:
  210. # new 分表批量存储 设备信息
  211. if new_device_info_list and len(new_device_info_list) > 0:
  212. # 根据日期获得星期几
  213. week = LocalDateTimeUtil.date_to_week(local_date_time)
  214. EquipmentInfoService.equipment_info_bulk_create(week, new_device_info_list)
  215. logger.info('设备信息分表批量保存end------')
  216. if is_st == 0 or is_st == 2:
  217. for up in redis_list:
  218. if up['push_type'] == 0: # ios apns
  219. up['do_apns_code'] = do_apns_code
  220. elif up['push_type'] == 1: # android gcm
  221. up['do_fcm_code'] = do_fcm_code
  222. elif up['push_type'] == 2: # android jpush
  223. up['do_jpush_code'] = do_jpush_code
  224. del up['push_type']
  225. del up['userID_id']
  226. del up['userID__NickName']
  227. del up['lang']
  228. del up['tz']
  229. del up['uid_set__nickname']
  230. del up['uid_set__detect_interval']
  231. del up['uid_set__detect_group']
  232. return JsonResponse(status=200, data={'code': 0, 'msg': 'success 0 or 2', 're_list': redis_list})
  233. elif is_st == 1:
  234. thumbspng = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
  235. Params = {'Key': thumbspng}
  236. if region == 2: # 2:国内
  237. Params['Bucket'] = 'push'
  238. else: # 1:国外
  239. Params['Bucket'] = 'foreignpush'
  240. response_url = generate_s3_url(aws_s3_client, Params)
  241. for up in redis_list:
  242. up['do_apns_code'] = do_apns_code
  243. up['do_fcm_code'] = do_fcm_code
  244. up['do_jpush_code'] = do_jpush_code
  245. del up['push_type']
  246. del up['userID_id']
  247. del up['userID__NickName']
  248. del up['lang']
  249. del up['tz']
  250. del up['uid_set__nickname']
  251. del up['uid_set__detect_interval']
  252. del up['uid_set__detect_group']
  253. res_data = {'code': 0, 'img_push': response_url, 'msg': 'success'}
  254. return JsonResponse(status=200, data=res_data)
  255. elif is_st == 3:
  256. img_url_list = []
  257. if region == 2: # 2:国内
  258. Params = {'Bucket': 'push'}
  259. else: # 1:国外
  260. Params = {'Bucket': 'foreignpush'}
  261. for i in range(is_st):
  262. thumbspng = '{uid}/{channel}/{filename}_{st}.jpeg'. \
  263. format(uid=uid, channel=channel, filename=n_time, st=i)
  264. Params['Key'] = thumbspng
  265. response_url = generate_s3_url(aws_s3_client, Params)
  266. img_url_list.append(response_url)
  267. for up in redis_list:
  268. up['do_apns_code'] = do_apns_code
  269. up['do_fcm_code'] = do_fcm_code
  270. up['do_jpush_code'] = do_jpush_code
  271. del up['push_type']
  272. del up['userID_id']
  273. del up['userID__NickName']
  274. del up['lang']
  275. del up['tz']
  276. del up['uid_set__nickname']
  277. del up['uid_set__detect_interval']
  278. del up['uid_set__detect_group']
  279. res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3'}
  280. return JsonResponse(status=200, data=res_data)
  281. except Exception as e:
  282. logger.info('移动侦测接口异常: {}'.format(e))
  283. logger.info('错误文件', e.__traceback__.tb_frame.f_globals['__file__'])
  284. logger.info('错误行号', e.__traceback__.tb_lineno)
  285. data = {
  286. 'errLine': e.__traceback__.tb_lineno,
  287. 'errMsg': repr(e),
  288. }
  289. return JsonResponse(status=200, data=json.dumps(data), safe=False)
  290. @classmethod
  291. def get_combo_msg_type(cls, ai_type, event_type):
  292. """
  293. 获取组合类型,ai_type == 47 支持算法小店,需判断组合类型
  294. """
  295. logger = logging.getLogger('info')
  296. try:
  297. if ai_type != 47:
  298. return event_type
  299. logger.info('LOG------算法小店组合类型十进制值:{}'.format(event_type))
  300. # 如触发一个事件,则匹配已用类型 1替换后变成51代表移动侦测 1:移动侦测,2:人形,4:车型,8:人脸
  301. event_dict = {
  302. 1: 51,
  303. 2: 57,
  304. 4: 58,
  305. 16: 59,
  306. 8: 60,
  307. 32: 61
  308. }
  309. event_val = event_dict.get(event_type, 0)
  310. # event_val == 0 没有匹配到单个值则认为组合类型
  311. # 如是3,则转为二进制11,代表(1+2)触发了移动侦测+人形侦测
  312. if event_val == 0:
  313. val = cls.dec_to_bin(event_type)
  314. return int(val)
  315. else:
  316. return int(event_val)
  317. except Exception as e:
  318. logger.info('推送错误异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
  319. return event_type
  320. @staticmethod
  321. def dec_to_bin(num):
  322. """
  323. 十进制转二进制
  324. """
  325. result = ""
  326. while num != 0:
  327. ret = num % 2
  328. num //= 2
  329. result = str(ret) + result
  330. return result
  331. def push_thread_test(self, push_type, aws_s3_client, bucket, key, uid, appBundleId, token_val, event_type, n_time,
  332. msg_title, msg_text, channel):
  333. logger = logging.getLogger('info')
  334. logger.info('推送图片测试:{} {} {} {} {} {} {} {}'.format(push_type, uid, appBundleId, token_val, event_type, n_time,
  335. msg_title, msg_text))
  336. try:
  337. image_url = aws_s3_client.generate_presigned_url('get_object', Params={'Bucket': bucket, 'Key': key},
  338. ExpiresIn=300)
  339. logger.info('推送图片url:{}'.format(image_url))
  340. if push_type == 0:
  341. GatewayPushService.ios_apns_push(uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text,
  342. uid, channel, image_url)
  343. elif push_type == 1:
  344. GatewayPushService.android_fcm_push(uid, appBundleId, token_val, n_time, event_type, msg_title,
  345. msg_text, uid, channel, image_url)
  346. except Exception as e:
  347. logger.info('推送图片测试异常:{}'.format(e))
  348. def get_msg_title(self, appBundleId, nickname):
  349. package_title_config = {
  350. 'com.ansjer.customizedd_a': 'DVS',
  351. 'com.ansjer.zccloud_a': 'ZosiSmart',
  352. 'com.ansjer.zccloud_ab': '周视',
  353. 'com.ansjer.adcloud_a': 'ADCloud',
  354. 'com.ansjer.adcloud_ab': 'ADCloud',
  355. 'com.ansjer.accloud_a': 'ACCloud',
  356. 'com.ansjer.loocamccloud_a': 'Loocam',
  357. 'com.ansjer.loocamdcloud_a': 'Anlapus',
  358. 'com.ansjer.customizedb_a': 'COCOONHD',
  359. 'com.ansjer.customizeda_a': 'Guardian365',
  360. 'com.ansjer.customizedc_a': 'PatrolSecure',
  361. }
  362. if appBundleId in package_title_config.keys():
  363. return package_title_config[appBundleId] + '(' + nickname + ')'
  364. else:
  365. return nickname
  366. def is_sys_msg(self, event_type):
  367. event_type_list = [702, 703, 704]
  368. if event_type in event_type_list:
  369. return True
  370. return False
  371. def get_msg_text(self, channel, n_time, lang, tz, event_type, electricity='', is_sys=0):
  372. n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang=lang)
  373. etype = int(event_type)
  374. if lang == 'cn':
  375. if etype == 704:
  376. msg_type = '剩余电量:' + electricity
  377. elif etype == 702:
  378. msg_type = '摄像头休眠'
  379. elif etype == 703:
  380. msg_type = '摄像头唤醒'
  381. else:
  382. msg_type = ''
  383. if is_sys:
  384. send_text = '{msg_type} 通道:{channel}'.format(msg_type=msg_type, channel=channel)
  385. else:
  386. send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
  387. else:
  388. if etype == 704:
  389. msg_type = 'Battery remaining:' + electricity
  390. elif etype == 702:
  391. msg_type = 'Camera sleep'
  392. elif etype == 703:
  393. msg_type = 'Camera wake'
  394. else:
  395. msg_type = ''
  396. if is_sys:
  397. send_text = '{msg_type} channel:{channel}'. \
  398. format(msg_type=msg_type, channel=channel)
  399. else:
  400. send_text = '{msg_type} channel:{channel} date:{date}'. \
  401. format(msg_type=msg_type, channel=channel, date=n_date)
  402. return send_text
  403. def do_jpush(self, uid, channel, appBundleId, token_val, event_type, n_time,
  404. msg_title, msg_text):
  405. app_key = JPUSH_CONFIG[appBundleId]['Key']
  406. master_secret = JPUSH_CONFIG[appBundleId]['Secret']
  407. _jpush = jpush.JPush(app_key, master_secret)
  408. push = _jpush.create_push()
  409. push.audience = jpush.registration_id(token_val)
  410. push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  411. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
  412. android = jpush.android(alert=msg_text, priority=1, style=1, alert_type=7,
  413. big_text=msg_text, title=msg_title,
  414. extras=push_data)
  415. push.notification = jpush.notification(android=android)
  416. push.platform = jpush.all_
  417. res = push.send()
  418. print(res)
  419. return res.status_code
  420. def do_fcm(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
  421. logger = logging.getLogger('info')
  422. try:
  423. serverKey = FCM_CONFIG[appBundleId]
  424. except Exception as e:
  425. logger.info('------fcm_error:{}'.format(repr(e)))
  426. return 'serverKey abnormal'
  427. push_service = FCMNotification(api_key=serverKey)
  428. data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  429. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
  430. result = push_service.notify_single_device(registration_id=token_val, message_title=msg_title,
  431. message_body=msg_text, data_message=data,
  432. extra_kwargs={
  433. 'default_vibrate_timings': True,
  434. 'default_sound': True,
  435. 'default_light_settings': True
  436. })
  437. return result
  438. def do_apns(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title,
  439. msg_text):
  440. logger = logging.getLogger('info')
  441. logger.info("进来do_apns函数了")
  442. logger.info(token_val)
  443. logger.info(APNS_MODE)
  444. logger.info(os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
  445. try:
  446. cli = apns2.APNSClient(mode=APNS_MODE,
  447. client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
  448. push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  449. "received_at": n_time, "sound": "", "uid": uid, "zpush": "1", "channel": channel}
  450. alert = apns2.PayloadAlert(body=msg_text, title=msg_title)
  451. payload = apns2.Payload(alert=alert, custom=push_data, sound="default")
  452. # return uid, channel, appBundleId, str(token_val), event_type, n_time, msg_title,msg_text
  453. n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
  454. res = cli.push(n=n, device_token=token_val, topic=appBundleId)
  455. print(res.status_code)
  456. logger.info("apns_推送状态:")
  457. logger.info(res.status_code)
  458. if res.status_code == 200:
  459. return res.status_code
  460. else:
  461. print('apns push fail')
  462. print(res.reason)
  463. logger.info('apns push fail')
  464. logger.info(res.reason)
  465. return res.status_code
  466. except (ValueError, ArithmeticError):
  467. return 'The program has a numeric format exception, one of the arithmetic exceptions'
  468. except Exception as e:
  469. print(repr(e))
  470. print('do_apns函数错误行号', e.__traceback__.tb_lineno)
  471. logger.info('do_apns错误:{}'.format(repr(e)))
  472. return repr(e)
  473. def s3_client(region):
  474. if region == 2: # 国内
  475. aws_s3_client = boto3.client(
  476. 's3',
  477. aws_access_key_id=AWS_ACCESS_KEY_ID[0],
  478. aws_secret_access_key=AWS_SECRET_ACCESS_KEY[0],
  479. config=botocore.client.Config(signature_version='s3v4'),
  480. region_name='cn-northwest-1'
  481. )
  482. else: # 国外
  483. aws_s3_client = boto3.client(
  484. 's3',
  485. aws_access_key_id=AWS_ACCESS_KEY_ID[1],
  486. aws_secret_access_key=AWS_SECRET_ACCESS_KEY[1],
  487. config=botocore.client.Config(signature_version='s3v4'),
  488. region_name='us-east-1'
  489. )
  490. return aws_s3_client
  491. def generate_s3_url(aws_s3_client, Params):
  492. response_url = aws_s3_client.generate_presigned_url(
  493. ClientMethod='put_object',
  494. Params=Params,
  495. ExpiresIn=3600
  496. )
  497. return response_url