فهرست منبع

app下载链接确认地区接口

locky 1 سال پیش
والد
کامیت
8056006f30
2فایلهای تغییر یافته به همراه34 افزوده شده و 0 حذف شده
  1. 1 0
      Ansjer/urls.py
  2. 33 0
      Controller/DeviceConfirmRegion.py

+ 1 - 0
Ansjer/urls.py

@@ -246,6 +246,7 @@ urlpatterns = [
     re_path(r'^device/confirmRegion$', DeviceConfirmRegion.ConfirmRegion.as_view()),
     re_path(r'^device/confirmRegionV2$', DeviceConfirmRegion.ConfirmRegionV2.as_view()),
     re_path(r'^device/confirmCountry$', DeviceConfirmRegion.confirm_country_with_ip),
+    re_path(r'^appDownload/confirmRegion$', DeviceConfirmRegion.confirm_region_with_ip),
     re_path(r'^pcInfo/(?P<operation>.*)$', PcInfo.PcInfo.as_view()),
     re_path(r'^pcTest/(?P<operation>.*)$', PctestController.PcTest.as_view()),
     re_path('deviceDebug/(?P<operation>.*)', DeviceDebug.DeviceDebug.as_view()),

+ 33 - 0
Controller/DeviceConfirmRegion.py

@@ -251,3 +251,36 @@ def confirm_country_with_ip(request):
     except Exception as e:
         print(e)
         return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+
+
+def confirm_region_with_ip(request):
+    """
+    app下载链接确认地区
+    @param request:
+    @return:
+    """
+    response = ResponseObject()
+    try:
+        request.encoding = 'utf-8'
+        ip = CommonService.get_ip_address(request)
+        device_domain_qs = DeviceDomainModel.objects.filter(ip=ip)
+
+        # 获取地区和国家信息
+        ip_addr_qs = IPAddr.objects.filter(ip=ip, is_geoip2=False).values('region', 'country_code')
+        if ip_addr_qs.exists():
+            region = ip_addr_qs[0]['region']
+            country_code = ip_addr_qs[0]['country_code']
+        else:
+            ip_qs = IPQuery(ip)
+            region = ip_qs.region
+            country_code = ip_qs.country_id
+
+        area = 'mainland'
+        if country_code != 'CN':
+            area = 'overseas'
+        elif region in ['香港', '澳门', '台湾']:
+            area = 'overseas'
+        res = {region: area}
+        return response.json(0, res)
+    except Exception as e:
+        return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))