DevicePushService.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. # -*- encoding: utf-8 -*-
  2. """
  3. @File : DevicePushService.py
  4. @Time : 2022/11/23 11:40
  5. @Author : stephen
  6. @Email : zhangdongming@asj6.wecom.work
  7. @Software: PyCharm
  8. """
  9. import hashlib
  10. import json
  11. import logging
  12. import os
  13. import threading
  14. import time
  15. import apns2
  16. import jpush as jpush
  17. import requests
  18. from pyfcm import FCMNotification
  19. from AnsjerPush.config import JPUSH_CONFIG, FCM_CONFIG, APNS_CONFIG, BASE_DIR, APNS_MODE, APP_BUNDLE_DICT, \
  20. XMPUSH_CONFIG, VIVOPUSH_CONFIG, OPPOPUSH_CONFIG, MEIZUPUSH_CONFIG
  21. from AnsjerPush.config import SERVER_TYPE
  22. from Model.models import UidPushModel, SysMsgModel
  23. from Object.ETkObject import ETkObject
  24. from Object.RedisObject import RedisObject
  25. from Object.UidTokenObject import UidTokenObject
  26. from Object.utils import LocalDateTimeUtil
  27. from Service.CommonService import CommonService
  28. from Service.EquipmentInfoService import EquipmentInfoService
  29. from Service.HuaweiPushService.HuaweiPushService import HuaweiPushObject
  30. from Service.PushService import PushObject
  31. from Service.VivoPushService.push_admin.APIMessage import PushMessage
  32. from Service.VivoPushService.push_admin.APISender import APISender
  33. LOGGING = logging.getLogger('info')
  34. class DevicePushService:
  35. @staticmethod
  36. def decode_uid(etk, uidToken):
  37. """
  38. 解密UID,优先解密etk 否则判断uidToken
  39. """
  40. # 解密获取uid
  41. if etk:
  42. eto = ETkObject(etk)
  43. uid = eto.uid
  44. else:
  45. uto = UidTokenObject(uidToken)
  46. uid = uto.UID
  47. LOGGING.info('消息推送-当前UID:{}'.format(uid))
  48. return uid
  49. @classmethod
  50. def query_uid_push(cls, uid):
  51. """
  52. 查询uid_set与push数据列表
  53. """
  54. uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
  55. values('token_val', 'app_type', 'appBundleId', 'm_code', 'push_type', 'userID_id', 'userID__NickName',
  56. 'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
  57. 'uid_set__channel', 'uid_set__ai_type', 'uid_set__new_detect_interval')
  58. return uid_push_qs
  59. @staticmethod
  60. def cache_uid_push(uid_push_qs):
  61. """
  62. 将uid_push 信息进行缓存
  63. @param uid_push_qs: uid_set & uid_push 列表对象
  64. @return: uid_set_list
  65. """
  66. uid_set_list = []
  67. for qs in uid_push_qs:
  68. uid_set_list.append(qs)
  69. # redis_obj.set_data(key=name, val=str(redis_list), expire=expire)
  70. return uid_set_list
  71. @staticmethod
  72. def cache_push_detect_interval(redis_obj, name, detect_interval, new_detect_interval):
  73. """
  74. 缓存设置推送消息的时间间隔
  75. @param redis_obj: redis对象
  76. @param name: redis key
  77. @param detect_interval: 原推送时间间隔
  78. @param new_detect_interval: 新推送时间间隔
  79. """
  80. if SERVER_TYPE != 'Ansjer.cn_config.cn_formal_settings':
  81. detect_interval = new_detect_interval if new_detect_interval > 0 else detect_interval
  82. detect_interval = 60 if detect_interval < 60 else detect_interval
  83. redis_obj.set_data(key=name, val=1, expire=detect_interval - 5)
  84. LOGGING.info('消息推送-缓存设置APP推送间隔:{}s'.format(detect_interval))
  85. @classmethod
  86. def save_msg_push(cls, uid_set_push_list, **params):
  87. """
  88. APP消息推送以及报警消息存库
  89. @nickname 设备名称
  90. @channel 通道
  91. @event_type 事件类型
  92. """
  93. new_device_info_list = []
  94. sys_msg_list = []
  95. userID_ids = []
  96. kwag_args = params['kwag_args']
  97. code_data = {'do_apns_code': '', 'do_fcm_code': '', 'do_jpush_code': ''}
  98. local_date_time = ''
  99. push_permission = True
  100. for up in uid_set_push_list:
  101. appBundleId = up['appBundleId']
  102. token_val = up['token_val']
  103. lang = up['lang']
  104. tz = up['tz']
  105. if tz is None or tz == '':
  106. tz = 0
  107. # 发送标题
  108. msg_title = cls.get_msg_title(nickname=params['nickname'])
  109. # 发送内容
  110. msg_text = cls.get_msg_text(channel=params['channel'], n_time=params['n_time'], lang=lang,
  111. tz=tz, event_type=params['event_type'],
  112. electricity=params['electricity'])
  113. kwag_args['appBundleId'] = appBundleId
  114. kwag_args['token_val'] = token_val
  115. kwag_args['msg_title'] = msg_title
  116. kwag_args['msg_text'] = msg_text
  117. LOGGING.info('推送要的数据: {}'.format(kwag_args))
  118. local_date_time = CommonService.get_now_time_str(n_time=params['n_time'], tz=tz, lang='cn')
  119. LOGGING.info('<<<<<根据时区计算后日期={},时区={}'.format(local_date_time, tz))
  120. local_date_time = local_date_time[0:10]
  121. LOGGING.info('<<<<<切片后的日期={}'.format(local_date_time))
  122. # 以下是存库
  123. userID_id = up["userID_id"]
  124. if userID_id not in userID_ids:
  125. now_time = int(time.time())
  126. if params['is_sys_msg']:
  127. sys_msg_text = cls.get_msg_text(channel=params['channel'], n_time=params['n_time'], lang=lang,
  128. tz=tz,
  129. event_type=params['event_type'], electricity=params['electricity'],
  130. is_sys=1)
  131. sys_msg_list.append(SysMsgModel(userID_id=userID_id, msg=sys_msg_text, addTime=now_time,
  132. updTime=now_time, uid=params['uid'],
  133. eventType=params['event_type']))
  134. else:
  135. LOGGING.info('分表存数据start------')
  136. params['userID_id'] = userID_id
  137. push_permission = DevicePushService.check_share_permission(userID_id, params['channel'],
  138. params['uid'])
  139. if push_permission:
  140. new_device_info_list.append(cls.created_device_vo(local_date_time, **params))
  141. userID_ids.append(userID_id)
  142. params['appBundleId'] = appBundleId
  143. params['token_val'] = token_val
  144. params['lang'] = lang
  145. params['tz'] = tz
  146. params['kwag_args'] = kwag_args
  147. code_data = cls.send_app_msg_push(up['push_type'], **params) if push_permission else code_data
  148. return {'code_date': code_data, 'new_device_info_list': new_device_info_list, 'sys_msg_list': sys_msg_list,
  149. 'local_date_time': local_date_time}
  150. @classmethod
  151. def send_app_msg_push(cls, push_type, **param):
  152. """
  153. 发送app消息推送
  154. """
  155. try:
  156. kwargs = param['kwag_args']
  157. result = {'do_apns_code': '', 'do_fcm_code': '', 'do_jpush_code': '', 'do_xmpush_code': '',
  158. 'do_vivopush_code': '', 'do_meizupush_code': '', 'do_oppopush_code': ''}
  159. # 判断是否进行APP消息推送,如app_push不为空,则不进行推送
  160. if not param['app_push']:
  161. LOGGING.info('APP准备推送:{}, {}'.format(param['uid'], param))
  162. # 推送显示图片
  163. if (param['is_st'] == 1 or param['is_st'] == 3) and \
  164. (push_type == 0 or push_type == 1 or push_type == 3):
  165. if param['is_st'] == 1:
  166. key = '{}/{}/{}.jpeg'.format(param['uid'], param['channel'], param['n_time'])
  167. else:
  168. key = '{}/{}/{}_0.jpeg'.format(param['uid'], param['channel'], param['n_time'])
  169. push_thread = threading.Thread(target=cls.async_send_picture_push, args=(
  170. push_type, param['aws_s3_client'], param['bucket'], key, param['uid'], param['appBundleId'],
  171. param['token_val'], param['event_type'], param['n_time'],
  172. param['kwag_args']['msg_title'], param['kwag_args']['msg_text'], param['channel']))
  173. push_thread.start()
  174. else:
  175. if push_type == 0: # ios apns
  176. result['do_apns_code'] = cls.do_apns(**kwargs)
  177. elif push_type == 1: # android gcm
  178. result['do_fcm_code'] = cls.do_fcm(**kwargs)
  179. elif push_type == 2: # android jpush
  180. result['do_jpush_code'] = cls.do_jpush(**kwargs)
  181. elif push_type == 3:
  182. huawei_push_object = HuaweiPushObject()
  183. huawei_push_object.send_push_notify_message(**kwargs)
  184. elif push_type == 4: # android xmpush
  185. result['do_xmpush_code'] = cls.do_xmpush(**kwargs)
  186. elif push_type == 5: # android vivopush
  187. result['do_vivopush_code'] = PushObject.android_vivopush(**kwargs)
  188. elif push_type == 6: # android oppopush
  189. result['do_oppopush_code'] = cls.do_oppopush(**kwargs)
  190. elif push_type == 7: # android meizupush
  191. result['do_meizupush_code'] = PushObject.android_meizupush(**kwargs)
  192. return result
  193. except Exception as e:
  194. LOGGING.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
  195. return None
  196. @classmethod
  197. def save_sys_msg(cls, is_sys_msg, local_date_time, sys_msg_list, new_device_info_list):
  198. """
  199. 保存系统消息&设备推送消息存库
  200. """
  201. if is_sys_msg:
  202. SysMsgModel.objects.bulk_create(sys_msg_list)
  203. else:
  204. # new 分表批量存储 设备信息
  205. if new_device_info_list and len(new_device_info_list) > 0:
  206. # 根据日期获得星期几
  207. week = LocalDateTimeUtil.date_to_week(local_date_time)
  208. EquipmentInfoService.equipment_info_bulk_create(week, new_device_info_list)
  209. LOGGING.info('设备信息分表批量保存end------')
  210. return True
  211. @classmethod
  212. def created_device_vo(cls, local_date_time, **params):
  213. """
  214. 获取设备推送表对象
  215. """
  216. return EquipmentInfoService.get_equipment_info_obj(
  217. local_date_time,
  218. device_user_id=params['userID_id'],
  219. event_time=params['n_time'],
  220. event_type=params['event_type'],
  221. device_uid=params['uid'],
  222. device_nick_name=params['nickname'],
  223. channel=params['channel'],
  224. alarm='Motion \tChannel:{channel}'.format(channel=params['channel']),
  225. is_st=params['is_st'],
  226. receive_time=params['n_time'],
  227. add_time=int(time.time()),
  228. storage_location=2,
  229. border_coords='',
  230. )
  231. @staticmethod
  232. def get_msg_title(nickname):
  233. """
  234. 获取消息标题
  235. """""
  236. return nickname
  237. @staticmethod
  238. def get_msg_text(channel, n_time, lang, tz, event_type, electricity='', is_sys=0):
  239. """
  240. 获取消息文本
  241. """
  242. n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang=lang)
  243. etype = int(event_type)
  244. if lang == 'cn':
  245. if etype == 704:
  246. msg_type = '剩余电量 ' + electricity
  247. elif etype == 702:
  248. msg_type = '摄像头休眠'
  249. elif etype == 703:
  250. msg_type = '摄像头唤醒'
  251. else:
  252. msg_type = ''
  253. if is_sys:
  254. send_text = '{msg_type} 通道:{channel}'.format(msg_type=msg_type, channel=channel)
  255. else:
  256. send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
  257. else:
  258. if etype == 704:
  259. msg_type = 'Battery remaining ' + electricity
  260. elif etype == 702:
  261. msg_type = 'Camera sleep'
  262. elif etype == 703:
  263. msg_type = 'Camera wake'
  264. else:
  265. msg_type = ''
  266. if is_sys:
  267. send_text = '{msg_type} channel:{channel}'. \
  268. format(msg_type=msg_type, channel=channel)
  269. else:
  270. send_text = '{msg_type} channel:{channel} date:{date}'. \
  271. format(msg_type=msg_type, channel=channel, date=n_date)
  272. return send_text
  273. @staticmethod
  274. def do_jpush(uid, channel, appBundleId, token_val, event_type, n_time,
  275. msg_title, msg_text):
  276. """
  277. android 国内极光APP消息提醒推送
  278. """
  279. app_key = JPUSH_CONFIG[appBundleId]['Key']
  280. master_secret = JPUSH_CONFIG[appBundleId]['Secret']
  281. _jpush = jpush.JPush(app_key, master_secret)
  282. push = _jpush.create_push()
  283. push.audience = jpush.registration_id(token_val)
  284. push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  285. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
  286. android = jpush.android(alert=msg_text, priority=1, style=1, alert_type=7,
  287. big_text=msg_text, title=msg_title,
  288. extras=push_data)
  289. push.notification = jpush.notification(android=android)
  290. push.platform = jpush.all_
  291. res = push.send()
  292. print(res)
  293. return res.status_code
  294. @staticmethod
  295. def do_fcm(uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
  296. """
  297. android 谷歌APP消息提醒推送
  298. """
  299. try:
  300. serverKey = FCM_CONFIG[appBundleId]
  301. except Exception as e:
  302. LOGGING.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
  303. return 'serverKey abnormal'
  304. push_service = FCMNotification(api_key=serverKey)
  305. data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  306. "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
  307. result = push_service.notify_single_device(registration_id=token_val, message_title=msg_title,
  308. message_body=msg_text, data_message=data,
  309. extra_kwargs={
  310. 'default_vibrate_timings': True,
  311. 'default_sound': True,
  312. 'default_light_settings': True
  313. })
  314. return result
  315. @staticmethod
  316. def do_apns(uid, channel, appBundleId, token_val, event_type, n_time, msg_title,
  317. msg_text):
  318. """
  319. ios 消息提醒推送
  320. """
  321. LOGGING.info("进来do_apns函数了")
  322. LOGGING.info(token_val)
  323. LOGGING.info(APNS_MODE)
  324. LOGGING.info(os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
  325. try:
  326. cli = apns2.APNSClient(
  327. mode=APNS_MODE, client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
  328. push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
  329. "received_at": n_time, "sound": "", "uid": uid, "zpush": "1", "channel": channel}
  330. alert = apns2.PayloadAlert(body=msg_text, title=msg_title)
  331. payload = apns2.Payload(alert=alert, custom=push_data, sound="default")
  332. # return uid, channel, appBundleId, str(token_val), event_type, n_time, msg_title,msg_text
  333. n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
  334. res = cli.push(n=n, device_token=token_val, topic=appBundleId)
  335. print(res.status_code)
  336. LOGGING.info("apns_推送状态:")
  337. LOGGING.info(res.status_code)
  338. if res.status_code == 200:
  339. return res.status_code
  340. else:
  341. print('apns push fail')
  342. print(res.reason)
  343. LOGGING.info('apns push fail')
  344. LOGGING.info(res.reason)
  345. return res.status_code
  346. except (ValueError, ArithmeticError):
  347. return 'The program has a numeric format exception, one of the arithmetic exceptions'
  348. except Exception as e:
  349. print(repr(e))
  350. print('do_apns函数错误行号', e.__traceback__.tb_lineno)
  351. LOGGING.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
  352. return repr(e)
  353. @staticmethod
  354. def do_xmpush(uid, channel, appBundleId, token_val, event_type, n_time,
  355. msg_title, msg_text):
  356. """
  357. android 国内小米APP消息提醒推送
  358. """
  359. url = 'https://api.xmpush.xiaomi.com/v3/message/regid'
  360. app_secret = XMPUSH_CONFIG[appBundleId]
  361. payload = {'alert': 'Motion', 'msg': '', 'sound': 'sound.aif', 'zpush': '1',
  362. 'received_at': n_time, 'event_time': n_time, 'event_type': event_type,
  363. 'uid': uid, 'channel': channel
  364. }
  365. data = {
  366. 'title': msg_title,
  367. 'description': msg_text,
  368. 'payload': 'payload',
  369. 'restricted_package_name': appBundleId,
  370. 'registration_id': token_val,
  371. }
  372. headers = {
  373. 'Authorization': 'key={}'.format(app_secret)
  374. }
  375. response = requests.post(url, data=data, headers=headers)
  376. if response.status_code == 200:
  377. return response.json()
  378. @classmethod
  379. def do_oppopush(cls, uid, channel, appBundleId, token_val, event_type, n_time,
  380. msg_title, msg_text):
  381. """
  382. android 国内oppo APP消息提醒推送
  383. """
  384. app_key = OPPOPUSH_CONFIG[appBundleId]['Key']
  385. master_secret = OPPOPUSH_CONFIG[appBundleId]['Secret']
  386. url = 'https://api.push.oppomobile.com/'
  387. now_time = str(round(time.time() * 1000))
  388. # 1、实例化一个sha256对象
  389. sha256 = hashlib.sha256()
  390. # 2、调用update方法进行加密
  391. sha256.update((app_key + now_time + master_secret).encode('utf-8'))
  392. # 3、调用hexdigest方法,获取加密结果
  393. sign = sha256.hexdigest()
  394. # 获取auth_token
  395. get_token_url = url + 'server/v1/auth'
  396. post_data = {
  397. 'app_key': app_key,
  398. 'sign': sign,
  399. 'timestamp': now_time
  400. }
  401. headers = {'Content-Type': 'application/x-www-form-urlencoded'}
  402. response = requests.post(get_token_url, data=post_data, headers=headers)
  403. result = response.json()
  404. # 发送推送
  405. push_url = url + 'server/v1/message/notification/unicast'
  406. extra_data = {'alert': 'Motion', 'msg': '', 'sound': 'sound.aif', 'zpush': '1',
  407. 'received_at': n_time, 'event_time': n_time, 'event_type': event_type,
  408. 'uid': uid, 'channel': channel}
  409. message = {
  410. "target_type": 2,
  411. "target_value": token_val,
  412. "notification": {
  413. "title": msg_title,
  414. "content": msg_text,
  415. }
  416. }
  417. push_data = {
  418. 'auth_token': result['data']['auth_token'],
  419. 'message': json.dumps(message)
  420. }
  421. response = requests.post(push_url, data=push_data, headers=headers)
  422. if response.status_code == 200:
  423. return response.json()
  424. @classmethod
  425. def async_send_picture_push(cls, push_type, aws_s3_client, bucket, key, uid, appBundleId,
  426. token_val, event_type, n_time, msg_title, msg_text, channel):
  427. """
  428. 异步APP图片推送
  429. """
  430. try:
  431. image_url = aws_s3_client.generate_presigned_url('get_object',
  432. Params={'Bucket': bucket, 'Key': key},
  433. ExpiresIn=3600)
  434. LOGGING.info('推送图片url:{}'.format(image_url))
  435. if push_type == 0:
  436. PushObject.ios_apns_push(uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text,
  437. uid, channel, image_url)
  438. elif push_type == 1:
  439. PushObject.android_fcm_push(uid, appBundleId, token_val, n_time, event_type, msg_title,
  440. msg_text, uid, channel, image_url)
  441. elif push_type == 3:
  442. huawei_push_object = HuaweiPushObject()
  443. huawei_push_object.send_push_notify_message(token_val=token_val, msg_title=msg_title, msg_text=msg_text,
  444. image_url=image_url)
  445. except Exception as e:
  446. LOGGING.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
  447. @staticmethod
  448. def get_push_url(**params):
  449. """
  450. 获取推送URL,设备根本当前返回结果进行数据上传
  451. @return: re_data
  452. """
  453. re_data = {'code': 0, 'msg': 'success'}
  454. if params['is_st'] == 0 or params['is_st'] == 2:
  455. re_data['msg'] = 'success 0 or 2'
  456. for up in params['uid_set_push_list']:
  457. if up['push_type'] == 0: # ios apns
  458. up['do_apns_code'] = params['code_dict']['code_date']['do_apns_code']
  459. elif up['push_type'] == 1: # android gcm
  460. up['do_fcm_code'] = params['code_dict']['code_date']['do_fcm_code']
  461. elif up['push_type'] == 2: # android jpush
  462. up['do_jpush_code'] = params['code_dict']['code_date']['do_jpush_code']
  463. elif up['push_type'] == 4: # android jpush
  464. up['do_xmpush_code'] = params['code_dict']['code_date']['do_xmpush_code']
  465. elif up['push_type'] == 5: # android jpush
  466. up['do_vivopush_code'] = params['code_dict']['code_date']['do_vivopush_code']
  467. elif up['push_type'] == 7: # android jpush
  468. up['do_meizupush_code'] = params['code_dict']['code_date']['do_meizupush_code']
  469. del up['push_type']
  470. del up['userID_id']
  471. del up['userID__NickName']
  472. del up['lang']
  473. del up['tz']
  474. del up['uid_set__nickname']
  475. del up['uid_set__detect_interval']
  476. del up['uid_set__detect_group']
  477. re_data['re_list'] = params['uid_set_push_list']
  478. elif params['is_st'] == 1:
  479. key_name = '{uid}/{channel}/{filename}.jpeg' \
  480. .format(uid=params['uid'], channel=params['channel'], filename=params['n_time'])
  481. re_args = {'Key': key_name}
  482. if params['region'] == 2: # 2:国内
  483. re_args['Bucket'] = 'push'
  484. else: # 1:国外
  485. re_args['Bucket'] = 'foreignpush'
  486. response_url = DevicePushService.generate_s3_url(params['aws_s3_client'], re_args)
  487. re_data['img_push'] = response_url
  488. elif params['is_st'] == 3:
  489. img_url_list = []
  490. if params['region'] == 2: # 2:国内
  491. re_args = {'Bucket': 'push'}
  492. else: # 1:国外
  493. re_args = {'Bucket': 'foreignpush'}
  494. for i in range(params['is_st']):
  495. key_name = '{uid}/{channel}/{filename}_{st}.jpeg'. \
  496. format(uid=params['uid'], channel=params['channel'], filename=params['n_time'], st=i)
  497. re_args['Key'] = key_name
  498. response_url = DevicePushService.generate_s3_url(params['aws_s3_client'], re_args)
  499. img_url_list.append(response_url)
  500. re_data['img_url_list'] = img_url_list
  501. re_data['msg'] = 'success 3'
  502. return re_data
  503. @staticmethod
  504. def generate_s3_url(aws_s3_client, params):
  505. """
  506. 获取S3对象URL
  507. """
  508. response_url = aws_s3_client.generate_presigned_url(
  509. ClientMethod='put_object',
  510. Params=params,
  511. ExpiresIn=3600
  512. )
  513. return response_url