|
@@ -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)))
|