Переглянути джерело

Merge remote-tracking branch 'origin/test'

locky 3 роки тому
батько
коміт
236049e63f

+ 4 - 1
Ansjer/cn_config/config_formal.py

@@ -125,7 +125,10 @@ TUTK_PUSH_DOMAIN = 'http://push.iotcplatform.com/tpns'
 
 
 # aws api key
 # aws api key
 AWS_ARN_S3 = 'arn:aws-cn:s3'
 AWS_ARN_S3 = 'arn:aws-cn:s3'
-AVATAR_BUCKET = 'avatar-cn'
 REGION_NAME = 'cn-northwest-1'
 REGION_NAME = 'cn-northwest-1'
 ACCESS_KEY_ID = 'AKIA2MMWBR4DSFG67DTG'
 ACCESS_KEY_ID = 'AKIA2MMWBR4DSFG67DTG'
 SECRET_ACCESS_KEY = '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'
 SECRET_ACCESS_KEY = 'aI9gxcAKPmiGgPy9axrtFKzjYGbvpuytEX4xWweL'
+
+# 存储桶名
+AVATAR_BUCKET = 'avatar-cn'         # 头像存储桶
+LOG_BUCKET = 'ansjer-statres'       # 日志存储桶

+ 4 - 1
Ansjer/cn_config/config_test.py

@@ -137,7 +137,10 @@ TUTK_PUSH_DOMAIN = 'http://push.iotcplatform.com/tpns'
 
 
 # aws api key
 # aws api key
 AWS_ARN_S3 = 'arn:aws-cn:s3'
 AWS_ARN_S3 = 'arn:aws-cn:s3'
-AVATAR_BUCKET = 'avatar-cn'
 REGION_NAME = 'cn-northwest-1'
 REGION_NAME = 'cn-northwest-1'
 ACCESS_KEY_ID = 'AKIA2MMWBR4DSFG67DTG'
 ACCESS_KEY_ID = 'AKIA2MMWBR4DSFG67DTG'
 SECRET_ACCESS_KEY = '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'
 SECRET_ACCESS_KEY = 'aI9gxcAKPmiGgPy9axrtFKzjYGbvpuytEX4xWweL'
+
+# 存储桶名
+AVATAR_BUCKET = 'avatar-cn'         # 头像存储桶
+LOG_BUCKET = 'ansjer-statres'       # 日志存储桶

+ 4 - 1
Ansjer/local_config/config_local.py

@@ -58,7 +58,10 @@ TUTK_PUSH_DOMAIN = 'http://push.iotcplatform.com/tpns'
 
 
 # aws api key
 # aws api key
 AWS_ARN_S3 = 'arn:aws-cn:s3'
 AWS_ARN_S3 = 'arn:aws-cn:s3'
-AVATAR_BUCKET = 'avatar-cn'
 REGION_NAME = 'cn-northwest-1'
 REGION_NAME = 'cn-northwest-1'
 ACCESS_KEY_ID = 'AKIA2MMWBR4DSFG67DTG'
 ACCESS_KEY_ID = 'AKIA2MMWBR4DSFG67DTG'
 SECRET_ACCESS_KEY = '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'
 SECRET_ACCESS_KEY = 'aI9gxcAKPmiGgPy9axrtFKzjYGbvpuytEX4xWweL'
+
+# 存储桶名
+AVATAR_BUCKET = 'avatar-cn'         # 头像存储桶
+LOG_BUCKET = 'ansjer-statres'       # 日志存储桶

+ 4 - 1
Ansjer/us_config/config_formal.py

@@ -125,7 +125,10 @@ TUTK_PUSH_DOMAIN = 'http://push.iotcplatform.com/tpns'
 
 
 # aws api key
 # aws api key
 AWS_ARN_S3 = 'arn:aws:s3'
 AWS_ARN_S3 = 'arn:aws:s3'
-AVATAR_BUCKET = 'avatar-us'
 REGION_NAME = 'us-east-1'
 REGION_NAME = 'us-east-1'
 ACCESS_KEY_ID = 'AKIA2E67UIMD45Y3HL53'
 ACCESS_KEY_ID = 'AKIA2E67UIMD45Y3HL53'
 SECRET_ACCESS_KEY = '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'
 SECRET_ACCESS_KEY = 'ckYLg4Lo9ZXJIcJEAKkzf2rWvs8Xth1FCjqiAqUw'
+
+# 存储桶名
+AVATAR_BUCKET = 'avatar-us'         # 头像存储桶
+LOG_BUCKET = 'ansjer-statres'       # 日志存储桶

+ 4 - 1
Ansjer/us_config/config_test.py

@@ -136,7 +136,10 @@ TUTK_PUSH_DOMAIN = 'http://push.iotcplatform.com/tpns'
 
 
 # aws api key
 # aws api key
 AWS_ARN_S3 = 'arn:aws:s3'
 AWS_ARN_S3 = 'arn:aws:s3'
-AVATAR_BUCKET = 'avatar-us'
 REGION_NAME = 'us-east-1'
 REGION_NAME = 'us-east-1'
 ACCESS_KEY_ID = 'AKIA2E67UIMD45Y3HL53'
 ACCESS_KEY_ID = 'AKIA2E67UIMD45Y3HL53'
 SECRET_ACCESS_KEY = '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'
 SECRET_ACCESS_KEY = 'ckYLg4Lo9ZXJIcJEAKkzf2rWvs8Xth1FCjqiAqUw'
+
+# 存储桶名
+AVATAR_BUCKET = 'avatar-us'         # 头像存储桶
+LOG_BUCKET = 'ansjer-statres'       # 日志存储桶

+ 3 - 2
Controller/AppLogController.py

@@ -7,7 +7,8 @@ import botocore
 import oss2
 import oss2
 from django.views.generic.base import View
 from django.views.generic.base import View
 
 
-from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, REGION_NAME, ACCESS_KEY_ID, SECRET_ACCESS_KEY
+from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, REGION_NAME, ACCESS_KEY_ID, SECRET_ACCESS_KEY, \
+    LOG_BUCKET
 from Model.models import AppLogModel
 from Model.models import AppLogModel
 from Object.ResponseObject import ResponseObject
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.TokenObject import TokenObject
@@ -66,7 +67,7 @@ class AppLogView(View):
         response_url = aws_s3_client.generate_presigned_url(
         response_url = aws_s3_client.generate_presigned_url(
             ClientMethod='put_object',
             ClientMethod='put_object',
             Params={
             Params={
-                'Bucket': 'ansjer-statres',
+                'Bucket': LOG_BUCKET,
                 'Key': obj
                 'Key': obj
             },
             },
             ExpiresIn=3600
             ExpiresIn=3600

+ 7 - 15
Controller/IotCoreController.py

@@ -74,13 +74,9 @@ class IotCoreView(View):
         if not all([token, time_stamp, device_version, language]):
         if not all([token, time_stamp, device_version, language]):
             return response.json(444, {'param': 'token, uid_code, time_stamp, device_version, language'})
             return response.json(444, {'param': 'token, uid_code, time_stamp, device_version, language'})
 
 
-        # token时间戳校验
-        token = int(CommonService.decode_data(token))
-        time_stamp = int(time_stamp)
-        now_time = int(time.time())
-        distance = now_time - time_stamp
-        if token != time_stamp or distance > 60000 or distance < -60000:  # 为了全球化时间控制在一天内
-            return response.json(404)
+        # 时间戳token校验
+        if not CommonService.check_time_stamp_token(token, time_stamp):
+            return response.json(13)
 
 
         if not uid:
         if not uid:
             # 使用序列号
             # 使用序列号
@@ -120,7 +116,7 @@ class IotCoreView(View):
 
 
             iotClient = IOTClient(region_id)
             iotClient = IOTClient(region_id)
             res = iotClient.create_keys_and_certificate(ThingNameSuffix, thingGroup, response)
             res = iotClient.create_keys_and_certificate(ThingNameSuffix, thingGroup, response)
-            token_iot_number = hashlib.md5((str(uuid.uuid1()) + str(now_time)).encode('utf-8')).hexdigest()
+            token_iot_number = hashlib.md5((str(uuid.uuid1()) + str(int(time.time()))).encode('utf-8')).hexdigest()
 
 
             iotdeviceInfoModel.objects.create(uid=uid,
             iotdeviceInfoModel.objects.create(uid=uid,
                                               serial_number=serial,
                                               serial_number=serial,
@@ -164,13 +160,9 @@ class IotCoreView(View):
         if not all([token, language, time_stamp, device_version]):
         if not all([token, language, time_stamp, device_version]):
             return response.json(444, {'param: token, language, time_stamp, device_version'})
             return response.json(444, {'param: token, language, time_stamp, device_version'})
 
 
-        # 封装token认证
-        token = int(CommonService.decode_data(token))
-        time_stamp = int(time_stamp)
-        now_time = int(time.time())
-        distance = now_time - time_stamp
-        if token != time_stamp or distance > 60000 or distance < -60000:  # 为了全球化时间控制在一天内
-            return response.json(404)
+        # 时间戳token校验
+        if not CommonService.check_time_stamp_token(token, time_stamp):
+            return response.json(13)
 
 
         ip = CommonService.get_ip_address(request)
         ip = CommonService.get_ip_address(request)
         region_id = Device_Region().get_device_region(ip)
         region_id = Device_Region().get_device_region(ip)

+ 4 - 2
Controller/SysManage.py

@@ -12,6 +12,7 @@
 @Contact: chanjunkai@163.com
 @Contact: chanjunkai@163.com
 """
 """
 import os
 import os
+import time
 
 
 from django.http import HttpResponse
 from django.http import HttpResponse
 from django.views.decorators.csrf import csrf_exempt
 from django.views.decorators.csrf import csrf_exempt
@@ -103,9 +104,10 @@ def initMsgFunc(request):
     response.lang = tko.lang
     response.lang = tko.lang
     if tko.code == 0:
     if tko.code == 0:
         userID = tko.userID
         userID = tko.userID
+        seven_days_ago = int(time.time()) - 3600 * 24 * 7   # 过滤七天前数据
         sm_count = SysMsgModel.objects.filter(userID_id=userID, status=0).count()
         sm_count = SysMsgModel.objects.filter(userID_id=userID, status=0).count()
-        eq_count = Equipment_Info.objects.filter(userID_id=userID).filter(status=False).count()
-        rq_count = Equipment_Info.objects.filter(userID_id=userID).filter(eventType=57, status=False,).count()
+        eq_count = Equipment_Info.objects.filter(userID_id=userID, eventTime__gt=seven_days_ago, status=False).count()
+        rq_count = Equipment_Info.objects.filter(userID_id=userID, eventTime__gt=seven_days_ago, eventType=57, status=False,).count()
         uid_reset_count = Device_Info.objects.filter(userID_id=userID, isExist=2).count()
         uid_reset_count = Device_Info.objects.filter(userID_id=userID, isExist=2).count()
         res = {
         res = {
             'sm_count': sm_count,  # 系统消息未读数量
             'sm_count': sm_count,  # 系统消息未读数量

+ 2 - 0
Object/ResponseObject.py

@@ -13,6 +13,7 @@ class ResponseObject(object):
             5: 'Please try again one minute later!',
             5: 'Please try again one minute later!',
             10: res,
             10: res,
             12: 'You are not the primary user of the device!',
             12: 'You are not the primary user of the device!',
+            13: 'Timestamp token verification failed',
             14: 'Device is not belong to you',
             14: 'Device is not belong to you',
             15: 'Device has been bound',
             15: 'Device has been bound',
             16: 'WeChat has been bound, please log in and unbind using WeChat',
             16: 'WeChat has been bound, please log in and unbind using WeChat',
@@ -109,6 +110,7 @@ class ResponseObject(object):
             5: '请一分钟后再尝试',
             5: '请一分钟后再尝试',
             10: res,
             10: res,
             12: '非设备主用户',
             12: '非设备主用户',
+            13: '时间戳token校验失败',
             14: '设备不属于您',
             14: '设备不属于您',
             15: '设备已被绑定',
             15: '设备已被绑定',
             16: '微信已被绑定,请使用微信登录并解绑',
             16: '微信已被绑定,请使用微信登录并解绑',

+ 15 - 0
Service/CommonService.py

@@ -432,6 +432,21 @@ class CommonService:
     def encode_data_without_salt(content):
     def encode_data_without_salt(content):
         return base64.b64encode(str(content).encode("utf-8")).decode('utf8')
         return base64.b64encode(str(content).encode("utf-8")).decode('utf8')
 
 
+    @staticmethod
+    def check_time_stamp_token(token, time_stamp):
+        # 时间戳token校验
+        try:
+            token = int(CommonService.decode_data(token))
+            time_stamp = int(time_stamp)
+            now_time = int(time.time())
+            distance = now_time - time_stamp
+            if token != time_stamp or distance > 60000 or distance < -60000:  # 为了全球化时间控制在一天内
+                return False
+            return True
+        except Exception as e:
+            print(e)
+            return False
+
     @staticmethod
     @staticmethod
     def rsa_sign(Token):
     def rsa_sign(Token):
         # 私钥签名Token
         # 私钥签名Token