Эх сурвалжийг харах

获取域名返回推送region参数

locky 2 жил өмнө
parent
commit
4cf97ddb96

+ 32 - 7
Controller/DeviceConfirmRegion.py

@@ -42,13 +42,25 @@ 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)
 
             # 不存在则返回美洲域名
-            api, push_api, region_id = get_default_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:
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
@@ -90,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 = get_default_api()
+                    api, push_api, region_id, region = get_default_api()
             else:
                 # 返回美洲域名
                 data_dict['country_code'] = 'NA'
-                api, push_api, region_id = get_default_api()
+                api, push_api, region_id, region = get_default_api()
 
             # 更新或创建设备域名数据
             data_dict['region_id'] = region_id
@@ -110,7 +123,8 @@ 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:
@@ -123,7 +137,18 @@ def get_default_api():
     api = region_qs[0]['api']
     push_api = region_qs[0]['push_api']
     region_id = region_qs[0]['id']
-    return api, push_api, region_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):