瀏覽代碼

push info

chenjunkai 6 年之前
父節點
當前提交
a22cafdde3
共有 2 個文件被更改,包括 43 次插入1 次删除
  1. 30 0
      Controller/DetectController.py
  2. 13 1
      templates/testttt.py

+ 30 - 0
Controller/DetectController.py

@@ -31,6 +31,7 @@ from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.UidTokenObject import UidTokenObject
 from django.http import JsonResponse
+from Service.CommonService import CommonService
 
 
 # http://192.168.136.40:8077/detect/changeStatus?uid=JW3684H8BSHG9TTM111A&token_val=18071adc03536302f34&appBundleId=com.ansjer.zccloud_ab&push_type=2&token=local&status=1
@@ -59,11 +60,40 @@ class DetectControllerView(View):
             userID = tko.userID
             if operation == 'changeStatus':
                 return self.do_change_status(userID, request_dict, response)
+            if operation == 'queryInfo':
+                return self.do_query(request_dict, response, userID)
             else:
                 return response.json(414)
         else:
             return response.json(tko.code)
 
+    def do_query(self, request_dict, response, userID):
+        page = int(request_dict.get('page', None))
+        line = int(request_dict.get('line', None))
+        if not page or not line:
+            return response.json(444, 'page,line')
+        qs = Equipment_Info.objects.filter(userID_id=userID)
+        uid = request_dict.get('uid', None)
+        if uid:
+            qs.filter(devUid=uid)
+        if not qs.exists():
+            return response.json(0, {'datas': [], 'count': 0})
+        qs = qs.values('id', 'devUid', 'devNickName', 'Channel', 'eventType', 'status', 'alarm', 'eventTime',
+                       'receiveTime')
+        count = qs.count()
+        qr = qs[(page - 1) * line:page * line]
+        # send_json = CommonService.qs_to_dict(res)
+        res = []
+        import oss2
+        auth = oss2.Auth('LTAIyMkGfEdogyL9', '71uIjpsqVOmF7DAITRyRuc259jHOjO')
+        bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
+        for p in qr:
+            p['img'] = bucket.sign_url('GET',
+                                       '{uid}/{channel}/{time}.jpeg'.format(uid=p['devUid'], channel=p['Channel'],
+                                                                            time=p['time']), 300)
+            res.append(p)
+        return response.json(0, {'datas': res, 'count': count})
+
     def do_change_status(self, userID, request_dict, response):
         uid = request_dict.get('uid', None)
         token_val = request_dict.get('token_val', None)

+ 13 - 1
templates/testttt.py

@@ -22,13 +22,25 @@
 # udt = uuid.uuid1()
 # print(udt)
 # exit()
+import oss2
+
+# 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
+auth = oss2.Auth('LTAIyMkGfEdogyL9', '71uIjpsqVOmF7DAITRyRuc259jHOjO')
+# Endpoint以杭州为例,其它Region请按实际情况填写。
+bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
 
+# 设置此签名URL在60秒内有效。
+# url = bucket.sign_url('PUT', 'wupengyangceshi.png', 60)
+url = bucket.sign_url('GET', 'ADD2JGTZG22XBL2S111A/9/1546545891.jpeg', 60)
+print(url)
+
+exit()
 
 import requests
 
 
 didir = 'D:/13.56.215.252/git/AnsjerFormal/templates/adf.jpg'
-url = 'http://apg.oss-cn-shenzhen.aliyuncs.com/TN7MPE3211UE76AP111A%2F9%2F1234561234.jpeg?OSSAccessKeyId=LTAIyMkGfEdogyL9&Expires=1554798738&Signature=YDt9q5IEjor7sSzyYleQe9fRye4%3D'
+url = 'http://apg.oss-cn-shenzhen.aliyuncs.com/ADD2JGTZG22XBL2S111A%2F3%2F1546545891.jpeg?Expires=1554801938&Signature=UlZ5pCeBwYlVm07gdL2gp2UOFuU%3D&OSSAccessKeyId=LTAIyMkGfEdogyL9'
 
 r = requests.put(url,data=open(didir,'rb'))
 print(r.status_code)