|
@@ -1,11 +1,14 @@
|
|
|
#!/usr/bin/env python3
|
|
|
# -*- coding: utf-8 -*-
|
|
|
+import time
|
|
|
+
|
|
|
import boto3
|
|
|
from django.views import View
|
|
|
|
|
|
from Model.models import Device_User, UserRegionModel
|
|
|
from Object.IOTCore.IotObject import ChinaIOTClient, AsiaIOTClient, EuropeIOTClient, AmericaIOTClient
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
+from Service.CommonService import CommonService
|
|
|
|
|
|
|
|
|
class IotCoreView(View):
|
|
@@ -33,15 +36,25 @@ class IotCoreView(View):
|
|
|
|
|
|
def create_provisioning_claim(self, request_dict, response):
|
|
|
uid = request_dict.get('uid', None)
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ time_stamp = request_dict.get('time_stamp', None)
|
|
|
+
|
|
|
+ if uid and token and time_stamp:
|
|
|
+ token = CommonService.decode_data(token)
|
|
|
+ time_stamp = int(time_stamp)
|
|
|
|
|
|
- if uid:
|
|
|
+ now_time = int(time.time())
|
|
|
+ distance = now_time - time_stamp
|
|
|
+
|
|
|
+ if token != time_stamp and distance > 600:
|
|
|
+ return response.json(404)
|
|
|
|
|
|
user_region_qs = UserRegionModel.objects.filter(user__device_info__UID=uid)
|
|
|
if user_region_qs.exists():
|
|
|
user_region = user_region_qs[0]
|
|
|
|
|
|
if user_region.region_id == 1:
|
|
|
- iotClient = AmericaIOTClient()
|
|
|
+ iotClient = ChinaIOTClient()
|
|
|
return response.json(0, {'res': iotClient.create_provisioning_claim('Ansjer_Iot_Queue')})
|
|
|
elif user_region.region_id == 2:
|
|
|
iotClient = AsiaIOTClient()
|