chenjunkai 6 years ago
parent
commit
5b4c2603ef

+ 5 - 2
Ansjer/config.py

@@ -32,7 +32,7 @@ OAUTH_ACCESS_TOKEN_SECRET = 'a+jbgnw%@1%zy^=@dn62%'
 OAUTH_REFRESH_TOKEN_SECRET = 'r+jbgnw%@1%zy^=@dn62%'
 # access_token超时
 # OAUTH_ACCESS_TOKEN_TIME = datetime.timedelta(hours=1)
-OAUTH_ACCESS_TOKEN_TIME = datetime.timedelta(days=7)
+OAUTH_ACCESS_TOKEN_TIME = datetime.timedelta(days=507)
 # refresh_token超时
 OAUTH_REFRESH_TOKEN_TIME = datetime.timedelta(days=7)
 # 腾讯验证,短信发送
@@ -45,11 +45,14 @@ AuthCode_Expire = 600
 RTMP_PUSH_URL = 'http://13.56.215.252:8091/hls'
 # 根路径
 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+# uid token key
+UID_TOKEN_KEY = 'c+565*j@%^'
+
 
 if SERVER_TYPE == 'Ansjer.local_settings':
     NGINX_RTMP_STAT = 'http://192.168.136.45:8077/stat'
     SERVER_DOMAIN = 'http://192.168.136.45:8077'
-    DATABASE_DATA = 'Ansjer'
+    DATABASE_DATA = 'AnsjerLocal'
     SERVER_HOST = '192.168.136.45'
     DOMAIN_HOST = '192.168.136.45'
     RTMP_PUSH_URL = 'rtmp://192.168.136.45:1935/hls'

+ 3 - 3
Ansjer/test/oss.py

@@ -28,14 +28,14 @@ auth = Auth(accessid, accesskey)
 bucket = Bucket(auth, host, bucket_name)
 ######################
 # 生成oss签名url
-url = bucket.sign_url('GET', 'vod/1543561927/1543561927.m3u8', 60 * 60, params={'x-oss-process': 'hls/sign'})
+# url = bucket.sign_url('GET', 'vod/1543561927/1543561927.m3u8', 60 * 60, params={'x-oss-process': 'hls/sign'})
 
 # url = bucket.sign_url('GET', 'vod/1543561897/1543561897.m3u8', 60 * 60, params={'x-oss-process': 'hls/sign'})
-# url = bucket.sign_url('GET', 'vod/1543561865/1543561865.m3u8', 60 * 60, params={'x-oss-process': 'hls/sign'})
+url = bucket.sign_url('GET', 'vod/1543902118/1543902118.m3u8', 60 * 60, params={'x-oss-process': 'hls/sign'})
 
 # url = urllib.parse.unquote(url, encoding='utf-8', errors='replace')
 
-# url=urllib.parse.unquote(url)
+url=urllib.parse.unquote(url)
 print(url)
 exit()
 # 播放m3u8

+ 2 - 1
Ansjer/test/osstest.py

@@ -14,9 +14,10 @@ bucket = oss2.Bucket(auth, host, bucket_name)
 
 # 设置Delimiter参数为正斜线(/)。
 # for obj in oss2.ObjectIterator(bucket, delimiter='/',prefix='vod/'):
-for obj in oss2.ObjectIterator(bucket, prefix='vod/'):
+for obj in oss2.ObjectIterator(bucket, delimiter='/vod/'):
     # 通过is_prefix方法判断obj是否为文件夹。
     if obj.is_prefix():  # 文件夹
         print('directory: ' + obj.key)
     else:  # 文件
+        pass
         print('file: ' + obj.key)

+ 0 - 0
Ansjer/test/ttsqiniu.py


+ 55 - 2
Controller/EquipmentInfo.py

@@ -8,7 +8,8 @@ import traceback
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from django.views.generic import TemplateView
-
+from Ansjer.config import UID_TOKEN_KEY
+import jwt
 '''
 http://192.168.136.45:8077/equipment/info?token=test&devUid=2N1K3LE78TYJ38CE111A&Channel=0&eventType=1&eventTime=1234567890&operation=add&alarm=21342134&receiveTime=1234567891234567
 http://test.dvema.com/equipment/info?token=test&operation=query&page=1&line=10
@@ -278,4 +279,56 @@ class AddDetectionView(TemplateView):
             print(1)
             Equipment_Info.objects.bulk_create(qs_list)
             print(2)
-            return response.json(0)
+            return response.json(0)
+
+
+#设备推送开关
+class DetectStatusView(View):
+    @method_decorator(csrf_exempt)
+    def dispatch(self, *args, **kwargs):
+        return super(DetectStatusView, self).dispatch(*args, **kwargs)
+
+    def get(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        return self.validation(request_dict=request.GET)
+
+    def post(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        return self.validation(request_dict=request.POST)
+
+    def validation(self, request_dict, *args, **kwargs):
+        token = request_dict.get('token', None)
+        status = request_dict.get('status', None)
+        response = ResponseObject()
+        if token is None:
+            return response.json(309)
+        tko = TokenObject(token)
+        tko.valid()
+        response.lang = tko.lang
+        if tko.code != 0:
+            return response.json(tko.code)
+        userID = tko.userID
+        if userID is None or status is None:
+            return response.json(444,'status or userId not in')
+        return self.do_update(userID,status,response)
+
+
+    def do_update(self, userID,status,response):
+        qs = Device_Info.objects.filter(userID=userID)
+        if qs.exists():
+            return
+        own_permission = ModelService.check_permission(userID=userID, permID=230)
+        if own_permission is not True:
+            return response.json(404)
+        ev = Equipment_Version.objects.filter(eid=eid)
+        if not ev.exists():
+            return response.json(10,'ev none')
+        status = request_dict.get('status', None)
+        try:
+            update_time = timezone.localtime(timezone.now())
+            ev.update(status=status, update_time=update_time)
+        except Exception as e:
+            print(repr(e))
+            pass
+        else:
+            return response.json(0, {'update_time': str(update_time)})

+ 2 - 0
Controller/EquipmentManager.py

@@ -8,6 +8,8 @@ import simplejson as json
 from Object.TokenObject import TokenObject
 from Object.ResponseObject import ResponseObject
 import re
+from Ansjer.config import UID_TOKEN_KEY
+import jwt
 
 
 def addNewUserEquipment(userID, deviceContent, response):

+ 7 - 2
Controller/EquipmentStatus.py

@@ -15,8 +15,12 @@ from django.views.decorators.csrf import csrf_exempt
 from Model.models import Device_Info
 from django.utils import timezone
 from Service.CommonService import CommonService
-from Object.TokenObject import TokenObject
+from django.views.generic.base import View
 from Object.ResponseObject import ResponseObject
+from Ansjer.config import UID_TOKEN_KEY
+import jwt
+from django.utils.decorators import method_decorator
+from Object.TokenObject import TokenObject
 '''
 http://192.168.136.45:8077/device/online?UID=C2887N9EBS87ZAT1111A
 http://192.168.136.45:8077/device/offline?UID=C2887N9EBS87ZAT1111A
@@ -86,4 +90,5 @@ def updateIP(request):
             print(repr(e))
         return response.json(0,{'area': area})
     else:
-        return response.json(13)
+        return response.json(13)
+

+ 0 - 0
Model/__init__.py


+ 55 - 9
Model/models.py

@@ -160,7 +160,7 @@ class Role(models.Model):
 
 class Device_User(AbstractBaseUser):
     userID = models.CharField(blank=True, max_length=32, primary_key=True,
-                              verbose_name=u'用户ID', unique=True, default=CommonService.getUserID(getUser=True))
+                              verbose_name=u'用户ID', unique=True)
     role = models.ManyToManyField(to='Role', blank=True, verbose_name=u'用户角色', db_table='user_role')
 
     username = models.CharField(max_length=40, verbose_name=u'用户名', default='', blank=True)
@@ -294,10 +294,10 @@ class Device_User(AbstractBaseUser):
         return self.is_superuser
 
 
+# 设备表是建项目开发者设计的,自己看着办
 class Device_Info(models.Model):
     id = models.CharField(blank=True, max_length=32, primary_key=True)
-    userID = models.ForeignKey(Device_User, blank=True, to_field='userID',
-                               on_delete=models.CASCADE)
+    userID = models.ForeignKey(Device_User, blank=True, to_field='userID', on_delete=models.CASCADE)
     NickName = models.CharField(blank=True, max_length=32, verbose_name=u'设备名称')
     UID = models.CharField(blank=True, max_length=32, verbose_name=u'设备UID')
     SID = models.CharField(blank=True, max_length=32, verbose_name=u'服务器ID')
@@ -420,14 +420,11 @@ class Equipment_Info(models.Model):
     devNickName = models.CharField(blank=True, max_length=32, default='', verbose_name=u'设备昵称')
     Channel = models.IntegerField(null=True, blank=True, verbose_name=u'设备通道')
     eventType = models.IntegerField(null=True, blank=True, verbose_name=u'事件类型')
-    viewAccont = models.CharField(blank=True, null=True, max_length=32, verbose_name=u'设备账户')
-    viewPwd = models.CharField(blank=True, null=True, max_length=32, verbose_name=u'设备密码')
     status = models.BooleanField(blank=True, default=False, verbose_name=u'事件状态')
     alarm = models.CharField(blank=True, max_length=256, verbose_name=u'报警信息')
     eventTime = models.CharField(blank=True, null=True, max_length=16, verbose_name=u'设备报警时间')
     receiveTime = models.CharField(blank=True, null=True, max_length=16, verbose_name=u'接收到报警时间')
-    userID = models.ForeignKey(Device_User, null=True, blank=True, to_field='userID',
-                               on_delete=models.CASCADE)
+    userID = models.ForeignKey(Device_User, null=True, blank=True, to_field='userID', on_delete=models.CASCADE)
 
     def __str__(self):
         return self.id
@@ -445,7 +442,7 @@ class Feedback_Info(models.Model):
     status = models.BooleanField(blank=True, default=False, verbose_name=u'状态:0未解决/解决')
     content = models.TextField(blank=True, null=True, verbose_name=u'反馈描述')
     add_time = models.DateTimeField(blank=True, null=True, verbose_name=u'加入时间/反馈时间', auto_now_add=True)
-    update_time = models.DateTimeField(blank=True, null=True,verbose_name=u'更新时间', auto_now=True)
+    update_time = models.DateTimeField(blank=True, null=True, verbose_name=u'更新时间', auto_now=True)
 
     def __str__(self):
         return self.id
@@ -515,7 +512,7 @@ class Equipment_Version(models.Model):
     fileMd5 = models.CharField(blank=True, max_length=32, null=True, verbose_name=u'上传文件MD5加密')
     status = models.BooleanField(blank=True, default=True, verbose_name=u'是否开启更新状态')
     update_time = models.DateTimeField(blank=True, verbose_name=u'更新时间', auto_now=True)
-    lang = models.CharField(blank=True,default='en', max_length=32, verbose_name=u'ota包内置语言')
+    lang = models.CharField(blank=True, default='en', max_length=32, verbose_name=u'ota包内置语言')
 
     def __str__(self):
         return self.eid
@@ -547,3 +544,52 @@ class App_Info(models.Model):
         verbose_name = u'app信息表'
         verbose_name_plural = verbose_name
         ordering = ('id',)
+
+
+# class UID_Model(models.Model):
+#     id = models.AutoField(primary_key=True, verbose_name=u'自增标记ID')
+#     UID = models.CharField(blank=True, unique=True, max_length=32, verbose_name=u'设备UID')
+#     NickName = models.CharField(blank=True, max_length=32, verbose_name=u'设备名称')
+#     SID = models.CharField(blank=True, max_length=32, verbose_name=u'服务器ID')
+#     View_Account = models.CharField(blank=True, max_length=32, verbose_name=u'设备用户名称')
+#     View_Password = models.CharField(blank=True, max_length=32, verbose_name=u'设备密码')
+#     AudioFormat = models.IntegerField(blank=True, default=1, verbose_name=u'初始化影像')
+#     EventNotification = models.IntegerField(blank=True, verbose_name=u'报警类型')
+#     ChannelIndex = models.IntegerField(blank=True, verbose_name=u'通道号')
+#     Online = models.BooleanField(blank=True, default=False, verbose_name=u'设备是否在线')
+#     mMonitorIndex = models.IntegerField(blank=True, default=-1)
+#     Type = models.IntegerField(blank=True)
+#     DebugMode = models.IntegerField(blank=True, verbose_name=u'调试模式')
+#     NotificationMode = models.IntegerField(blank=True, verbose_name=u'是否报警')
+#     qvgaLevel = models.BooleanField(blank=True, verbose_name=u'SD与HD画面', default=0)  # 0代表:SD、1代表:HD
+#     isShare = models.BooleanField(blank=True, verbose_name=u'共享设备', default=False)
+#     primaryUserID = models.CharField(blank=True, verbose_name='主用户', max_length=32, default='')
+#     data_joined = models.DateTimeField(blank=True, verbose_name=u'设备添加时间', auto_now_add=True)
+#     update_time = models.DateTimeField(blank=True, verbose_name=u'更新时间', auto_now=True, null=True)
+#     ip = models.CharField(blank=True, max_length=20, null=True, verbose_name=u'设备区域ip')
+#     area = models.CharField(blank=True, max_length=100, null=True, verbose_name=u'设备区域area')
+#     # ios要求新增字段
+#     version = models.CharField(blank=True, max_length=20, null=True, verbose_name=u'版本号')
+#     SpaceUsable = models.CharField(blank=True, max_length=20, null=True, verbose_name=u'可用空间')
+#     SpaceSum = models.CharField(blank=True, max_length=20, null=True, verbose_name=u'总空间')
+#     WIFIName = models.CharField(blank=True, max_length=50, null=True, verbose_name=u'无线名称')
+#     WIFIIP = models.CharField(blank=True, max_length=20, null=True, verbose_name=u'无线ip')
+#     WIFIPwd = models.CharField(blank=True, max_length=50, null=True, verbose_name=u'无线密码')
+#     isDetector = models.BooleanField(blank=True, verbose_name=u'侦测开关', default=False)  # 0:关闭,1:开启
+#     DetectorRank = models.IntegerField(blank=True, default=0, verbose_name=u'侦测灵敏度')  # 1:低,2:中,3:高4:最高
+#     iSNotification = models.BooleanField(blank=True, verbose_name=u'报警通知', default=False)  # 0:关闭,1:开启)
+#     MirrorType = models.IntegerField(blank=True, default=0, verbose_name=u'镜像类型')  # 0:关闭镜像,1:上下镜像,2:左右镜像,3:上下左右镜像
+#     RecordType = models.IntegerField(blank=True, default=0, verbose_name=u'录像模式')  # (0:关闭,1:全是录像,3:报警录像)
+#     TimeZone = models.CharField(blank=True, max_length=50, null=True, verbose_name=u'时区')
+#     user_model = models.ManyToManyField(to='Device_User', blank=True, verbose_name=u'用户关联设备', db_table='user_uid')
+#
+#     REQUIRED_FIELDS = []
+#
+#     def __str__(self):
+#         return self.NickName
+#
+#     class Meta:
+#         db_table = 'UID'
+#         ordering = ('-data_joined',)
+#         verbose_name = u'设备信息表'
+#         verbose_name_plural = verbose_name

+ 7 - 6
Object/TokenObject.py

@@ -16,11 +16,12 @@ from Ansjer.config import OAUTH_ACCESS_TOKEN_SECRET, OAUTH_REFRESH_TOKEN_SECRET,
 import jwt, time
 from Model.models import Device_User
 
+
 class TokenObject:
 
     def __init__(self, token=None):
-        if token == 'debug':
-            token = 'x'
+        if token == 'local':
+            token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySUQiOiIxNTE1NDc4NjczNDUxNjM2MTM4MDAxMzgwMDEiLCJsYW5nIjoiZW4iLCJleHAiOjE1NDQ0OTg2MzR9.Be5g7FFVle8wPOSSk4SOfbsP5Wy0uQMQmYXud33Lgpo'
         if token == 'test':
             token = 'x'
         self.token = token
@@ -56,11 +57,11 @@ class TokenObject:
             now_stamp = int(time.time())
             access_data = data
             refresh_data = data
-            access_data['exp'] = access_expire+now_stamp
-            refresh_data['exp'] = refresh_expire+now_stamp
+            access_data['exp'] = access_expire + now_stamp
+            refresh_data['exp'] = refresh_expire + now_stamp
             access_token = jwt.encode(access_data,
-                OAUTH_ACCESS_TOKEN_SECRET,
-                algorithm='HS256')
+                                      OAUTH_ACCESS_TOKEN_SECRET,
+                                      algorithm='HS256')
             refresh_token = jwt.encode(
                 refresh_data,
                 OAUTH_REFRESH_TOKEN_SECRET,