|
@@ -1,47 +1,13 @@
|
|
|
-#!/usr/bin/env python3
|
|
|
-# -*- coding: utf-8 -*-
|
|
|
-"""
|
|
|
-@Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
|
|
|
-@software: PyCharm
|
|
|
-@Version: python3.6
|
|
|
-"""
|
|
|
-import datetime
|
|
|
-import traceback
|
|
|
import time
|
|
|
-import logging
|
|
|
-import jwt
|
|
|
-import simplejson
|
|
|
-import simplejson as json
|
|
|
-import requests
|
|
|
-from django.contrib.auth.hashers import make_password, check_password # 对密码加密模块
|
|
|
-from django.db.models import Q
|
|
|
-from django.http import HttpResponseRedirect
|
|
|
+
|
|
|
from django.utils.decorators import method_decorator
|
|
|
-from django.utils.timezone import utc
|
|
|
+
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.views.generic import TemplateView
|
|
|
-from jwt.algorithms import RSAAlgorithm
|
|
|
-from ratelimit.decorators import ratelimit
|
|
|
-
|
|
|
-from Ansjer.config import AuthCode_Expire, SERVER_DOMAIN, APNS_CONFIG, JPUSH_CONFIG, FCM_CONFIG, TUTK_PUSH_DOMAIN
|
|
|
-from Controller.CheckUserData import DataValid, date_handler, RandomStr
|
|
|
-from Model.models import Device_User, Role, UidPushModel, UserOauth2Model, UserExModel, Device_Info, UidSetModel, \
|
|
|
- UserAppFrequencyModel, CountryIPModel, CountryModel, RegionModel, P2PIpModel, DeviceDomainModel
|
|
|
-from Object.AWS.SesClassObject import SesClassObject
|
|
|
-from Object.AliSmsObject import AliSmsObject
|
|
|
-from Object.RedisObject import RedisObject
|
|
|
+from Model.models import CountryModel, RegionModel, P2PIpModel, DeviceDomainModel
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
-from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
-from Service.ModelService import ModelService
|
|
|
-from Service.TemplateService import TemplateService
|
|
|
-from django.views.generic import View
|
|
|
-import base64
|
|
|
-import random
|
|
|
-from io import BytesIO
|
|
|
-from PIL import Image, ImageDraw, ImageFont
|
|
|
-from django.shortcuts import HttpResponse
|
|
|
-from Ansjer.config import BASE_DIR
|
|
|
+
|
|
|
|
|
|
#确认设备所在地区
|
|
|
class ConfirmRegion(TemplateView):
|
|
@@ -73,43 +39,49 @@ class ConfirmRegion(TemplateView):
|
|
|
return response.json(0,{"request_api_url": api[0]['api']})
|
|
|
|
|
|
|
|
|
-# 根据设备的ip返回域名
|
|
|
+# 根据设备的ip返回域名和地区id
|
|
|
class ConfirmRegionV2(TemplateView):
|
|
|
@method_decorator(csrf_exempt)
|
|
|
def dispatch(self, *args, **kwargs):
|
|
|
return super(ConfirmRegionV2, self).dispatch(*args, **kwargs)
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
+ response = ResponseObject()
|
|
|
+ uid = request.GET.get('uid', None)
|
|
|
+ serial_number = request.GET.get('serial_number', None)
|
|
|
+ if not uid and not serial_number:
|
|
|
+ return response.json(444)
|
|
|
try:
|
|
|
- response = ResponseObject()
|
|
|
- uid = request.GET.get('uid', None)
|
|
|
- serial_number = request.GET.get('serial_number', None)
|
|
|
- if not uid and not serial_number:
|
|
|
- return response.json(444)
|
|
|
if uid:
|
|
|
data_dict = {'uid': uid}
|
|
|
device_domain_qs = DeviceDomainModel.objects.filter(uid=uid)
|
|
|
else:
|
|
|
data_dict = {'serial_number': serial_number}
|
|
|
device_domain_qs = DeviceDomainModel.objects.filter(serial_number=serial_number)
|
|
|
+
|
|
|
+ # 根据请求ip确认地区
|
|
|
request.encoding = 'utf-8'
|
|
|
ip = CommonService.get_ip_address(request)
|
|
|
data_dict['ip'] = ip
|
|
|
ipInfo = CommonService.getIpIpInfo(ip, 'CN')
|
|
|
country_code = ipInfo['country_code']
|
|
|
+
|
|
|
if country_code:
|
|
|
data_dict['country_name'] = ipInfo['country_name']
|
|
|
- device_request_url = CountryModel.objects.filter(country_code=country_code).values('region__api')
|
|
|
- if device_request_url.exists():
|
|
|
- api = device_request_url[0]['region__api']
|
|
|
+ country_qs = CountryModel.objects.filter(country_code=country_code).\
|
|
|
+ values('region__api', 'region__id')
|
|
|
+ if country_qs.exists():
|
|
|
+ api = country_qs[0]['region__api']
|
|
|
+ region_id = country_qs[0]['region__id']
|
|
|
else: # 默认返回美洲地区api
|
|
|
- api = RegionModel.objects.filter(continent_code='NA').values('api')[0]['api']
|
|
|
+ api, region_id = self.get_default_api()
|
|
|
else:
|
|
|
# 默认返回美洲地区api
|
|
|
- api = RegionModel.objects.filter(continent_code='NA').values('api')[0]['api']
|
|
|
+ api, region_id = self.get_default_api()
|
|
|
|
|
|
# 更新或创建设备域名数据
|
|
|
data_dict['api'] = api
|
|
|
+ data_dict['region_id'] = region_id
|
|
|
if device_domain_qs.exists():
|
|
|
device_domain_qs.update(**data_dict)
|
|
|
else:
|
|
@@ -119,6 +91,13 @@ class ConfirmRegionV2(TemplateView):
|
|
|
print(e)
|
|
|
return response.json(500, repr(e))
|
|
|
|
|
|
+ # 获取区域表美洲的相关数据
|
|
|
+ @staticmethod
|
|
|
+ def get_default_api():
|
|
|
+ region_qs = RegionModel.objects.filter(continent_code='NA').values('api', 'id')
|
|
|
+ api = region_qs[0]['api']
|
|
|
+ region_id = region_qs[0]['id']
|
|
|
+ return api, region_id
|
|
|
|
|
|
#确认设备所在地区
|
|
|
class Device_Region(object):
|
|
@@ -206,8 +185,6 @@ def confirm_country_with_ip(request):
|
|
|
ip = ip[:-1]
|
|
|
ipInfo = CommonService.getIpIpInfo(ip, "CN")
|
|
|
country = ipInfo['country_name'] if ipInfo['country_name'] else 'N/A'
|
|
|
- if country == '中国':
|
|
|
- country = '美国'
|
|
|
wf.write(country+'\n')
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|