|
@@ -10,12 +10,15 @@ from django.views import View
|
|
|
|
|
|
from Ansjer.config import CRCKey, CONFIG_INFO, CONFIG_US, CONFIG_EUR, \
|
|
|
CONFIG_CN, USED_SERIAL_REDIS_LIST, UNUSED_SERIAL_REDIS_LIST, SERVER_DOMAIN_US, REGION_ID_LIST, SERVER_DOMAIN_TEST, \
|
|
|
- SERVER_DOMAIN_LIST, SERVER_DOMAIN_CN, SERVER_DOMAIN_EUR, RESET_REGION_ID_SERIAL_REDIS_LIST, LOGGER, CONFIG_TEST
|
|
|
+ SERVER_DOMAIN_LIST, SERVER_DOMAIN_CN, SERVER_DOMAIN_EUR, RESET_REGION_ID_SERIAL_REDIS_LIST, LOGGER, CONFIG_TEST, \
|
|
|
+ SERVER_DOMAIN
|
|
|
+from Controller.CheckUserData import DataValid
|
|
|
from Controller.UnicomCombo.UnicomComboController import UnicomComboView
|
|
|
from Model.models import SerialNumberModel, CompanySerialModel, UIDCompanySerialModel, UIDModel, Device_Info, \
|
|
|
iotdeviceInfoModel, LogModel, UidSetModel, UID_Bucket, \
|
|
|
Unused_Uid_Meal, Order_Model, StsCrdModel, VodHlsModel, ExperienceContextModel, UidUserModel, ExperienceAiModel, \
|
|
|
- AiService, DeviceDomainRegionModel, RegionModel, UidPushModel, AppScannedSerial, Device_User, SerialUnbindUID
|
|
|
+ AiService, DeviceDomainRegionModel, RegionModel, UidPushModel, AppScannedSerial, Device_User, SerialUnbindUID, \
|
|
|
+ DeviceNetInfo
|
|
|
from Object.AWS.S3Email import S3Email
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.TokenObject import TokenObject
|
|
@@ -72,6 +75,8 @@ class SerialNumberView(View):
|
|
|
return self.get_global_uid_region(request_dict, response)
|
|
|
elif operation == 'getIoTCoreBySerialNumber': # 根据序列号获取iot core
|
|
|
return self.get_iot_core_by_serial_number(request_dict, response)
|
|
|
+ elif operation == 'saveUserNetInfo':
|
|
|
+ return self.save_user_net_info(request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -976,3 +981,84 @@ class SerialNumberView(View):
|
|
|
except Exception as e:
|
|
|
LOGGER.info('{}同步iot异常,errLine:{}, errMsg:{}'.format(serial_number, e.__traceback__.tb_lineno, repr(e)))
|
|
|
return False
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def save_user_net_info(request_dict, response):
|
|
|
+ """
|
|
|
+ 保存用户网络信息
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ serial = request_dict.get('serial', None)
|
|
|
+ username = request_dict.get('username', None)
|
|
|
+ wifi_name = request_dict.get('wifi_name', None)
|
|
|
+ wifi_password = request_dict.get('wifi_password', None)
|
|
|
+
|
|
|
+ if not all([serial, username, wifi_name, wifi_password]):
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ # 根据序列号获取p2p类型,设备类型信息
|
|
|
+ serial_number = serial[:9]
|
|
|
+ p2p_type = serial[9:10]
|
|
|
+ device_type = int(serial[10:14], 16)
|
|
|
+
|
|
|
+ # 请求绑定uid或查询uid
|
|
|
+ time_stamp = int(time.time())
|
|
|
+ token = CommonService.encode_data(time_stamp)
|
|
|
+ is_verify = '1'
|
|
|
+ data = {
|
|
|
+ 'serial_number': serial_number,
|
|
|
+ 'p2ptype': p2p_type,
|
|
|
+ 'time_stamp': time_stamp,
|
|
|
+ 'token': token,
|
|
|
+ 'is_verify': is_verify
|
|
|
+ }
|
|
|
+ url = SERVER_DOMAIN + 'serialNumber/attachUID'
|
|
|
+ try:
|
|
|
+ r = requests.post(url=url, data=data, timeout=30)
|
|
|
+ assert r.status_code == 200
|
|
|
+ r = r.json()
|
|
|
+ assert r['result_code'] == 0
|
|
|
+ uid = CommonService.decode_data(r['result']['uid'])
|
|
|
+
|
|
|
+ # 查询用户是否存在,不存在则创建
|
|
|
+ device_user_qs = Device_User.objects.filter(username=username).values('userID')
|
|
|
+ if device_user_qs.exists():
|
|
|
+ user_id = device_user_qs[0]['userID']
|
|
|
+ # 已保存过,更新网络信息
|
|
|
+ device_info_qs = Device_Info.objects.filter(userID_id=user_id, UID=uid).values('id')
|
|
|
+ if device_info_qs.exists():
|
|
|
+ device_id = device_info_qs[0]['id']
|
|
|
+ device_net_info_qs = DeviceNetInfo.objects.filter(device_id=device_id)
|
|
|
+ if device_net_info_qs.exists():
|
|
|
+ device_net_info_qs.update(wifi_name=wifi_name, wifi_password=wifi_password)
|
|
|
+ else:
|
|
|
+ password = ''
|
|
|
+ user_id = CommonService.getUserID(μs=False, setOTAID=True)
|
|
|
+ user_data = {
|
|
|
+ 'userID': user_id,
|
|
|
+ 'username': username,
|
|
|
+ 'NickName': username,
|
|
|
+ 'password': password
|
|
|
+ }
|
|
|
+ # 判断用户名是手机号还是邮箱
|
|
|
+ if DataValid().mobile_validate(username):
|
|
|
+ user_data['phone'] = username
|
|
|
+ elif DataValid().email_validate(username):
|
|
|
+ user_data['userEmail'] = username
|
|
|
+ else:
|
|
|
+ return response.json(444)
|
|
|
+ Device_User.objects.create(**user_data)
|
|
|
+
|
|
|
+ # 创建用户设备数据
|
|
|
+ device_id = CommonService.getUserID(getUser=False)
|
|
|
+ Device_Info.objects.create(
|
|
|
+ id=device_id, userID_id=user_id, serial_number=serial_number, UID=uid, NickName=serial[:6],
|
|
|
+ Type=device_type, View_Account='admin', View_Password='admin', vodPrimaryMaster=username,
|
|
|
+ vodPrimaryUserID=user_id
|
|
|
+ )
|
|
|
+ DeviceNetInfo.objects.create(
|
|
|
+ device_id=device_id, wifi_name=wifi_name, wifi_password=wifi_password
|
|
|
+ )
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|