|
@@ -26,22 +26,30 @@ class ConfirmRegion(View):
|
|
|
device_domain_qs = DeviceDomainModel.objects.filter(ip=ip)
|
|
|
|
|
|
# 获取国家编码
|
|
|
- ip_addr_qs = IPAddr.objects.filter(ip=ip, is_geoip2=False).values('country_code')
|
|
|
+ ip_addr_qs = IPAddr.objects.filter(ip=ip, is_geoip2=False).values('country_code', 'region')
|
|
|
if ip_addr_qs.exists():
|
|
|
country_code = ip_addr_qs[0]['country_code']
|
|
|
+ region = ip_addr_qs[0]['region']
|
|
|
else:
|
|
|
ip_qs = IPQuery(ip)
|
|
|
country_code = ip_qs.country_id
|
|
|
+ region = ip_qs.region
|
|
|
|
|
|
if country_code:
|
|
|
- country_qs = CountryModel.objects.filter(country_code=country_code).\
|
|
|
- values('region__api', 'region__push_api')
|
|
|
- if country_qs.exists():
|
|
|
- api = country_qs[0]['region__api']
|
|
|
- push_api = country_qs[0]['region__push_api']
|
|
|
-
|
|
|
- if not device_domain_qs.exists():
|
|
|
- DeviceDomainModel.objects.create(ip=ip, country_name=country_code, api=api)
|
|
|
+ # 港澳台返回美洲域名
|
|
|
+ if country_code == 'CN' and region in ['香港', '澳门', '台湾']:
|
|
|
+ api, push_api, region_id, push_region = get_default_api()
|
|
|
+ else:
|
|
|
+ country_qs = CountryModel.objects.filter(country_code=country_code).\
|
|
|
+ values('region__api', 'region__push_api')
|
|
|
+ if country_qs.exists():
|
|
|
+ api = country_qs[0]['region__api']
|
|
|
+ push_api = country_qs[0]['region__push_api']
|
|
|
+
|
|
|
+ if not device_domain_qs.exists():
|
|
|
+ DeviceDomainModel.objects.create(ip=ip, country_name=country_code, api=api)
|
|
|
+ else:
|
|
|
+ api, push_api, region_id, push_region = get_default_api()
|
|
|
|
|
|
push_region = get_push_region(api)
|
|
|
res = {
|
|
@@ -90,26 +98,32 @@ class ConfirmRegionV2(View):
|
|
|
data_dict['ip'] = ip
|
|
|
|
|
|
# 获取国家编码
|
|
|
- ip_addr_qs = IPAddr.objects.filter(ip=ip, is_geoip2=False).values('country_code')
|
|
|
+ ip_addr_qs = IPAddr.objects.filter(ip=ip, is_geoip2=False).values('country_code', 'region')
|
|
|
if ip_addr_qs.exists():
|
|
|
country_code = ip_addr_qs[0]['country_code']
|
|
|
+ region = ip_addr_qs[0]['region']
|
|
|
else:
|
|
|
ip_qs = IPQuery(ip)
|
|
|
country_code = ip_qs.country_id
|
|
|
+ region = ip_qs.region
|
|
|
|
|
|
if country_code:
|
|
|
data_dict['country_code'] = country_code
|
|
|
- country_qs = CountryModel.objects.filter(country_code=country_code).\
|
|
|
- values('region__api', 'region__push_api', 'region__id')
|
|
|
- if country_qs.exists():
|
|
|
- api = country_qs[0]['region__api']
|
|
|
- push_api = country_qs[0]['region__push_api']
|
|
|
- region_id = country_qs[0]['region__id']
|
|
|
- push_region = get_push_region(api)
|
|
|
- else:
|
|
|
- # 返回美洲域名
|
|
|
- data_dict['country_code'] = 'NA'
|
|
|
+ # 港澳台返回美洲域名
|
|
|
+ if country_code == 'CN' and region in ['香港', '澳门', '台湾']:
|
|
|
api, push_api, region_id, push_region = get_default_api()
|
|
|
+ else:
|
|
|
+ country_qs = CountryModel.objects.filter(country_code=country_code).\
|
|
|
+ values('region__api', 'region__push_api', 'region__id')
|
|
|
+ if country_qs.exists():
|
|
|
+ api = country_qs[0]['region__api']
|
|
|
+ push_api = country_qs[0]['region__push_api']
|
|
|
+ region_id = country_qs[0]['region__id']
|
|
|
+ push_region = get_push_region(api)
|
|
|
+ else:
|
|
|
+ # 返回美洲域名
|
|
|
+ data_dict['country_code'] = 'NA'
|
|
|
+ api, push_api, region_id, push_region = get_default_api()
|
|
|
else:
|
|
|
# 返回美洲域名
|
|
|
data_dict['country_code'] = 'NA'
|