|
@@ -42,21 +42,27 @@ class ConfirmRegion(View):
|
|
|
if not device_domain_qs.exists():
|
|
|
DeviceDomainModel.objects.create(ip=ip, country_name=country_code, api=api)
|
|
|
|
|
|
- return response.json(0, {'request_api_url': api, 'push_api_url': push_api})
|
|
|
+ region = get_push_region(api)
|
|
|
+ res = {
|
|
|
+ 'request_api_url': api,
|
|
|
+ 'push_api_url': push_api,
|
|
|
+ 'region': region
|
|
|
+ }
|
|
|
+ return response.json(0, res)
|
|
|
|
|
|
# 不存在则返回美洲域名
|
|
|
- region_qs = RegionModel.objects.filter(continent_code='NA').values('api', 'push_api')
|
|
|
- api = region_qs[0]['api']
|
|
|
- push_api = region_qs[0]['push_api']
|
|
|
-
|
|
|
+ api, push_api, region_id, region = get_default_api()
|
|
|
if not device_domain_qs.exists():
|
|
|
DeviceDomainModel.objects.create(ip=ip, country_name='NA', api=api)
|
|
|
|
|
|
- return response.json(0, {'request_api_url': api, 'push_api_url': push_api})
|
|
|
+ res = {
|
|
|
+ 'request_api_url': api,
|
|
|
+ 'push_api_url': push_api,
|
|
|
+ 'region': region
|
|
|
+ }
|
|
|
+ return response.json(0, res)
|
|
|
except Exception as e:
|
|
|
- print(e)
|
|
|
- return response.json(0, {'request_api_url': 'https://www.dvema.com',
|
|
|
- 'push_api_url': 'https://push.dvema.com'})
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
|
|
|
class ConfirmRegionV2(View):
|
|
@@ -65,7 +71,8 @@ class ConfirmRegionV2(View):
|
|
|
def dispatch(self, *args, **kwargs):
|
|
|
return super(ConfirmRegionV2, self).dispatch(*args, **kwargs)
|
|
|
|
|
|
- def get(self, request, *args, **kwargs):
|
|
|
+ @staticmethod
|
|
|
+ def get(request, *args, **kwargs):
|
|
|
response = ResponseObject()
|
|
|
serial_number = request.GET.get('serial_number', None)
|
|
|
if not serial_number:
|
|
@@ -95,14 +102,15 @@ class ConfirmRegionV2(View):
|
|
|
api = country_qs[0]['region__api']
|
|
|
push_api = country_qs[0]['region__push_api']
|
|
|
region_id = country_qs[0]['region__id']
|
|
|
+ region = get_push_region(api)
|
|
|
else:
|
|
|
# 返回美洲域名
|
|
|
data_dict['country_code'] = 'NA'
|
|
|
- api, push_api, region_id = self.get_default_api()
|
|
|
+ api, push_api, region_id, region = get_default_api()
|
|
|
else:
|
|
|
# 返回美洲域名
|
|
|
data_dict['country_code'] = 'NA'
|
|
|
- api, push_api, region_id = self.get_default_api()
|
|
|
+ api, push_api, region_id, region = get_default_api()
|
|
|
|
|
|
# 更新或创建设备域名数据
|
|
|
data_dict['region_id'] = region_id
|
|
@@ -115,27 +123,32 @@ class ConfirmRegionV2(View):
|
|
|
res = {
|
|
|
'request_api_url': api,
|
|
|
'push_api_url': push_api,
|
|
|
- 'region_id': region_id
|
|
|
+ 'region_id': region_id,
|
|
|
+ 'region': region
|
|
|
}
|
|
|
return response.json(0, res)
|
|
|
except Exception as e:
|
|
|
- print(repr(e))
|
|
|
- api, push_api, region_id = self.get_default_api()
|
|
|
- res = {
|
|
|
- 'request_api_url': api,
|
|
|
- 'push_api_url': push_api,
|
|
|
- 'region_id': region_id
|
|
|
- }
|
|
|
- return response.json(0, res)
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
- # 获取区域表美洲的相关数据
|
|
|
- @staticmethod
|
|
|
- def get_default_api():
|
|
|
- region_qs = RegionModel.objects.filter(continent_code='NA').values('api', 'push_api', 'id')
|
|
|
- api = region_qs[0]['api']
|
|
|
- push_api = region_qs[0]['push_api']
|
|
|
- region_id = region_qs[0]['id']
|
|
|
- return api, push_api, region_id
|
|
|
+
|
|
|
+def get_default_api():
|
|
|
+ # 获取默认域名(美洲服域名)
|
|
|
+ region_qs = RegionModel.objects.filter(continent_code='NA').values('api', 'push_api', 'id')
|
|
|
+ api = region_qs[0]['api']
|
|
|
+ push_api = region_qs[0]['push_api']
|
|
|
+ region_id = region_qs[0]['id']
|
|
|
+ region = 1 # 推送图片S3存储地区,1:国外, 2:国内
|
|
|
+ return api, push_api, region_id, region
|
|
|
+
|
|
|
+
|
|
|
+def get_push_region(api):
|
|
|
+ """
|
|
|
+ 根据域名获取推送图片S3存储地区
|
|
|
+ @param api:
|
|
|
+ @return: region
|
|
|
+ """
|
|
|
+ region = 2 if '.cn' in api else 1
|
|
|
+ return region
|
|
|
|
|
|
|
|
|
class Device_Region(object):
|