|
@@ -11,8 +11,6 @@
|
|
|
@file: DetectController.py
|
|
|
@Contact: chanjunkai@163.com
|
|
|
"""
|
|
|
-import calendar
|
|
|
-import datetime
|
|
|
import json
|
|
|
import logging
|
|
|
import os
|
|
@@ -23,7 +21,6 @@ import apns2
|
|
|
import boto3
|
|
|
import botocore
|
|
|
import jpush as jpush
|
|
|
-import pendulum
|
|
|
from botocore import client
|
|
|
from django.http import JsonResponse
|
|
|
from django.views.generic.base import View
|
|
@@ -154,6 +151,7 @@ class NotificationView(View):
|
|
|
|
|
|
if is_st == 1 or is_st == 3: # 使用aws s3
|
|
|
aws_s3_client = s3_client(region=region)
|
|
|
+ bucket = 'foreignpush' if region == 1 else 'push'
|
|
|
kwag_args = {
|
|
|
'uid': uid,
|
|
|
'channel': channel,
|
|
@@ -232,7 +230,13 @@ class NotificationView(View):
|
|
|
if not have_dkey:
|
|
|
logger.info('准备推送:{}, {}'.format(uid, request_dict))
|
|
|
if (is_st == 1 or is_st == 3) and (push_type == 0 or push_type == 1):
|
|
|
- push_thread = threading.Thread(target=self.push_thread_test, args=(push_type, aws_s3_client, uid, appBundleId, token_val, event_type, n_time, msg_title, msg_text, channel))
|
|
|
+ if is_st == 1:
|
|
|
+ key = '{}/{}/{}.jpeg'.format(uid, channel, n_time)
|
|
|
+ else:
|
|
|
+ key = '{}/{}/{}_0.jpeg'.format(uid, channel, n_time)
|
|
|
+ push_thread = threading.Thread(target=self.push_thread_test, args=(
|
|
|
+ push_type, aws_s3_client, bucket, key, uid, appBundleId, token_val, event_type, n_time,
|
|
|
+ msg_title, msg_text, channel))
|
|
|
push_thread.start()
|
|
|
if push_type == 0: # ios apns
|
|
|
do_apns_code = self.do_apns(**kwag_args)
|
|
@@ -338,28 +342,22 @@ class NotificationView(View):
|
|
|
}
|
|
|
return JsonResponse(status=200, data=json.dumps(data), safe=False)
|
|
|
|
|
|
- def push_thread(self, push_type, aws_s3_client, region, thumbspng, uid, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
|
|
|
- time.sleep(3)
|
|
|
- bucket = 'foreignpush' if region == 1 else 'push'
|
|
|
- image_url = aws_s3_client.generate_presigned_url('get_object', Params={'Bucket': bucket, 'Key': thumbspng}, ExpiresIn=300)
|
|
|
- if push_type == 0:
|
|
|
- GatewayPushService.ios_apns_push(uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text, image_url)
|
|
|
- elif push_type == 1:
|
|
|
- GatewayPushService.android_fcm_push(uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text, image_url)
|
|
|
-
|
|
|
- def push_thread_test(self, push_type, aws_s3_client, uid, appBundleId, token_val, event_type, n_time, msg_title, msg_text, channel):
|
|
|
+ def push_thread_test(self, push_type, aws_s3_client, bucket, key, uid, appBundleId, token_val, event_type, n_time,
|
|
|
+ msg_title, msg_text, channel):
|
|
|
logger = logging.getLogger('info')
|
|
|
- logger.info('推送图片测试:{} {} {} {} {} {} {} {}'.format(push_type, uid, appBundleId, token_val, event_type, n_time, msg_title, msg_text))
|
|
|
+ logger.info('推送图片测试:{} {} {} {} {} {} {} {}'.format(push_type, uid, appBundleId, token_val, event_type, n_time,
|
|
|
+ msg_title, msg_text))
|
|
|
time.sleep(3)
|
|
|
- bucket = 'ansjerfilemanager'
|
|
|
- thumbspng = 'app/test_image/1635081937159.jpg'
|
|
|
try:
|
|
|
- image_url = aws_s3_client.generate_presigned_url('get_object', Params={'Bucket': bucket, 'Key': thumbspng}, ExpiresIn=86400)
|
|
|
+ image_url = aws_s3_client.generate_presigned_url('get_object', Params={'Bucket': bucket, 'Key': key},
|
|
|
+ ExpiresIn=86400)
|
|
|
logger.info('推送图片url:{}'.format(image_url))
|
|
|
if push_type == 0:
|
|
|
- GatewayPushService.ios_apns_push(uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text, uid, channel, image_url)
|
|
|
+ GatewayPushService.ios_apns_push(uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text,
|
|
|
+ uid, channel, image_url)
|
|
|
elif push_type == 1:
|
|
|
- GatewayPushService.android_fcm_push(uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text, uid, channel, image_url)
|
|
|
+ GatewayPushService.android_fcm_push(uid, appBundleId, token_val, n_time, event_type, msg_title,
|
|
|
+ msg_text, uid, channel, image_url)
|
|
|
except Exception as e:
|
|
|
logger.info('推送图片测试异常:{}'.format(e))
|
|
|
|