|
@@ -19,27 +19,29 @@ class ConfirmRegion(TemplateView):
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
response = ResponseObject()
|
|
|
request.encoding = 'utf-8'
|
|
|
- # number = request.POST.get('number', None)
|
|
|
- # selectRegion = CountryModel.objects.filter(number=number).values('region__api_url')
|
|
|
- # if not selectRegion.exists():
|
|
|
- # return response.json(0,{"api_url":"https://test.dvema.com"})
|
|
|
- # else:
|
|
|
- # return response.json(0,{"api_url":selectRegion[0]['region__api_url']})
|
|
|
-
|
|
|
- # serial_number = request.POST.get('serial_number', None)
|
|
|
- ip = CommonService.get_ip_address(request)
|
|
|
- # ip = '14.102.176.0'
|
|
|
- ipInfo = CommonService.getIpIpInfo(ip, "CN")
|
|
|
- logger = logging.getLogger('info')
|
|
|
- logger.info('设备获取域名---ip:{},country_code:{}'.format(ip, ipInfo['country_code']))
|
|
|
- if ipInfo['country_code']:
|
|
|
- device_request_url = CountryModel.objects.filter(country_code=ipInfo['country_code']).values("region__api")
|
|
|
- if device_request_url.exists():
|
|
|
- return response.json(0, {"request_api_url": device_request_url[0]['region__api']})
|
|
|
-
|
|
|
- # 不存在默认返回美洲地区api。
|
|
|
- api = RegionModel.objects.filter(continent_code='NA').values("api")
|
|
|
- return response.json(0,{"request_api_url": api[0]['api']})
|
|
|
+ try:
|
|
|
+ ip = CommonService.get_ip_address(request)
|
|
|
+ device_domain_data = {'ip': ip}
|
|
|
+ ipInfo = CommonService.getIpIpInfo(ip, 'CN')
|
|
|
+ logger = logging.getLogger('info')
|
|
|
+ logger.info('设备获取域名---ip:{},country_code:{}'.format(ip, ipInfo['country_code']))
|
|
|
+ if ipInfo['country_code']:
|
|
|
+ device_domain_data['country_name'] = ipInfo['country_code']
|
|
|
+ device_request_url = CountryModel.objects.filter(country_code=ipInfo['country_code']).values("region__api")
|
|
|
+ if device_request_url.exists():
|
|
|
+ device_domain_data['api'] = device_request_url[0]['region__api']
|
|
|
+ DeviceDomainModel.objects.create(**device_domain_data)
|
|
|
+ return response.json(0, {'request_api_url': device_request_url[0]['region__api']})
|
|
|
+
|
|
|
+ # 不存在默认返回美洲地区api。
|
|
|
+ api = RegionModel.objects.filter(continent_code='NA').values("api")
|
|
|
+ device_domain_data['country_name'] = 'NA'
|
|
|
+ device_domain_data['api'] = api[0]['api']
|
|
|
+ DeviceDomainModel.objects.create(**device_domain_data)
|
|
|
+ return response.json(0, {'request_api_url': api[0]['api']})
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(0, {'request_api_url': 'https://www.dvema.com'})
|
|
|
|
|
|
|
|
|
# 根据设备的ip返回域名和地区id
|