|
@@ -17,7 +17,7 @@ from django.utils import timezone
|
|
|
from pyipip import IPIPDatabase
|
|
|
|
|
|
from Ansjer.config import BASE_DIR, SERVER_DOMAIN_SSL, CONFIG_INFO, CONFIG_TEST, CONFIG_CN, SERVER_DOMAIN_TEST, \
|
|
|
- SERVER_DOMAIN_CN, SERVER_DOMAIN_US, CONFIG_US
|
|
|
+ SERVER_DOMAIN_CN, SERVER_DOMAIN_US, CONFIG_US, CONFIG_EUR
|
|
|
from Controller.CheckUserData import RandomStr
|
|
|
from Model.models import iotdeviceInfoModel, Device_Info, CountryModel, RegionModel, UIDModel
|
|
|
from Object.ResponseObject import ResponseObject
|
|
@@ -625,25 +625,33 @@ GCqvlyw5dfxNA+EtxNE2wCW/LW7ENJlACgcfgPlBZtpLheWoZB/maw4=
|
|
|
return thing_name_suffix
|
|
|
|
|
|
@staticmethod
|
|
|
- def confirm_region_id(request):
|
|
|
+ def confirm_region_id(request=None):
|
|
|
"""
|
|
|
根据配置信息确定region_id
|
|
|
@param request: 请求体
|
|
|
@return: region_id
|
|
|
"""
|
|
|
region_id = 3
|
|
|
- if CONFIG_INFO == CONFIG_TEST or CONFIG_INFO == CONFIG_CN:
|
|
|
- region_id = 1
|
|
|
- else: # 国外配置暂时通过ip确认
|
|
|
- ip = CommonService.get_ip_address(request)
|
|
|
- ipInfo = CommonService.getIpIpInfo(ip, 'CN')
|
|
|
- if ipInfo['country_code']:
|
|
|
- country_qs = CountryModel.objects.filter(country_code=ipInfo['country_code']).values('region__id')
|
|
|
- if country_qs.exists():
|
|
|
- region_id = country_qs[0]['region__id']
|
|
|
- else: # 不存在默认返回美洲地区api
|
|
|
- region_qs = RegionModel.objects.filter(continent_code='NA').values("id")
|
|
|
- region_id = region_qs[0]['id']
|
|
|
+ if request is None:
|
|
|
+ if CONFIG_INFO == CONFIG_TEST or CONFIG_INFO == CONFIG_CN:
|
|
|
+ region_id = 1
|
|
|
+ elif CONFIG_INFO == CONFIG_US:
|
|
|
+ region_id = 3
|
|
|
+ elif CONFIG_INFO == CONFIG_EUR:
|
|
|
+ region_id = 4
|
|
|
+ else:
|
|
|
+ if CONFIG_INFO == CONFIG_TEST or CONFIG_INFO == CONFIG_CN:
|
|
|
+ region_id = 1
|
|
|
+ else: # 国外配置暂时通过ip确认
|
|
|
+ ip = CommonService.get_ip_address(request)
|
|
|
+ ipInfo = CommonService.getIpIpInfo(ip, 'CN')
|
|
|
+ if ipInfo['country_code']:
|
|
|
+ country_qs = CountryModel.objects.filter(country_code=ipInfo['country_code']).values('region__id')
|
|
|
+ if country_qs.exists():
|
|
|
+ region_id = country_qs[0]['region__id']
|
|
|
+ else: # 不存在默认返回美洲地区api
|
|
|
+ region_qs = RegionModel.objects.filter(continent_code='NA').values("id")
|
|
|
+ region_id = region_qs[0]['id']
|
|
|
return region_id
|
|
|
|
|
|
@staticmethod
|