|
@@ -17,10 +17,13 @@ from Ansjer.config import BASE_DIR
|
|
|
from django.http import JsonResponse
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
import ipdb
|
|
|
-
|
|
|
-from Model.models import Device_Info
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
+from Model.models import Device_Info, UID_Preview
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Service.CommonService import CommonService
|
|
|
+import time
|
|
|
+import oss2
|
|
|
+from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY
|
|
|
|
|
|
'''
|
|
|
http://192.168.136.45:8077/device/online?UID=C2887N9EBS87ZAT1111A
|
|
@@ -106,8 +109,7 @@ def getTZ(request):
|
|
|
uid = c.decode('utf-8')
|
|
|
if len(uid) == 20:
|
|
|
print(uid)
|
|
|
- db = ipdb.City(BASE_DIR + "/DB/mydata4vipday2.ipdb")
|
|
|
- info = db.find_map(ip, lang)
|
|
|
+ info = CommonService.getIpIpInfo(ip=ip, lang=lang)
|
|
|
# tz = info.timezone
|
|
|
# of = info.utc_offset
|
|
|
# from var_dump import var_dump
|
|
@@ -117,3 +119,62 @@ def getTZ(request):
|
|
|
return JsonResponse(status=200, data={'code': 404, 'msg': '令牌错误'})
|
|
|
else:
|
|
|
return JsonResponse(status=200, data={'code': 444, 'msg': '接口参数错误 etk'})
|
|
|
+
|
|
|
+
|
|
|
+# 设备预览图
|
|
|
+def addUIDPreview(request):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ response = ResponseObject()
|
|
|
+ if request.method == 'GET':
|
|
|
+ request_dict = request.GET
|
|
|
+ elif request.method == 'POST':
|
|
|
+ request_dict = request.POST
|
|
|
+ else:
|
|
|
+ return response.json(414)
|
|
|
+ channel = request_dict.get('channel')
|
|
|
+ uid = request_dict.get('channel')
|
|
|
+ token = request_dict.get('token')
|
|
|
+ if all([token, uid, channel]):
|
|
|
+ tko = TokenObject(token)
|
|
|
+ if tko.code == 0:
|
|
|
+ nowTime = int(time.time())
|
|
|
+ upqs = UID_Preview.objects.filter(uid=uid, channel=channel)
|
|
|
+ if upqs.exists():
|
|
|
+ try:
|
|
|
+ is_update = upqs.update(updTime=nowTime)
|
|
|
+ except Exception as e:
|
|
|
+ print(repr(e))
|
|
|
+ return response.json(177)
|
|
|
+ else:
|
|
|
+ if is_update:
|
|
|
+ auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
+ bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
+ obj = 'uid_preview/{uid}/{channel}.jpeg'.format(uid=uid, channel=channel)
|
|
|
+ # 设置此签名URL在60秒内有效。
|
|
|
+ url = bucket.sign_url('PUT', obj, 7200)
|
|
|
+ return response.json(0, url)
|
|
|
+ else:
|
|
|
+ return response.json(177)
|
|
|
+ else:
|
|
|
+ create_data = {
|
|
|
+ 'addTime': nowTime,
|
|
|
+ 'updTime': nowTime,
|
|
|
+ 'uid': uid,
|
|
|
+ 'channel': channel
|
|
|
+ }
|
|
|
+ try:
|
|
|
+ UID_Preview.objects.create(**create_data)
|
|
|
+ except Exception as e:
|
|
|
+ print(repr(e))
|
|
|
+ return response.json(178)
|
|
|
+ else:
|
|
|
+ auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
+ bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
+ obj = 'uid_preview/{uid}/{channel}.jpeg'.format(uid=uid, channel=channel)
|
|
|
+ # 设置此签名URL在60秒内有效。
|
|
|
+ url = bucket.sign_url('PUT', obj, 7200)
|
|
|
+ return response.json(0, url)
|
|
|
+ else:
|
|
|
+ return response.json(tko.code)
|
|
|
+ else:
|
|
|
+ return response.json(444)
|