|
@@ -26,7 +26,7 @@ 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
|
|
|
+ UserAppFrequencyModel, CountryIPModel, CountryModel, RegionModel, P2PIpModel
|
|
|
from Object.AWS.SesClassObject import SesClassObject
|
|
|
from Object.AliSmsObject import AliSmsObject
|
|
|
from Object.RedisObject import RedisObject
|
|
@@ -89,3 +89,44 @@ class Device_Region(object):
|
|
|
return api[0]['id']
|
|
|
|
|
|
|
|
|
+# 根据p2p的ip统计设备所在地区
|
|
|
+class StatisticsIpRegion(TemplateView):
|
|
|
+ @method_decorator(csrf_exempt)
|
|
|
+ def dispatch(self, *args, **kwargs):
|
|
|
+ return super(StatisticsIpRegion, self).dispatch(*args, **kwargs)
|
|
|
+
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ return self.ipRegion(request.GET)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ return self.ipRegion(request.POST)
|
|
|
+
|
|
|
+ def ipRegion(self, request_dict):
|
|
|
+ response = ResponseObject()
|
|
|
+ ip = request_dict.get('ip', None)
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+
|
|
|
+ if not all([ip, uid]):
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ try:
|
|
|
+ # 判断uid是否已记录过ip信息
|
|
|
+ p2p_ip_qs = P2PIpModel.objects.filter(uid=uid)
|
|
|
+ if p2p_ip_qs.exists():
|
|
|
+ return response.json(174)
|
|
|
+
|
|
|
+ # 根据ip确定位置信息
|
|
|
+ ip_info = CommonService.getIpIpInfo(ip, 'CN')
|
|
|
+ # 获取国家,地区,城市
|
|
|
+ country_name = ip_info['country_name']
|
|
|
+ region_name = ip_info['region_name']
|
|
|
+ city_name = ip_info['city_name']
|
|
|
+ P2PIpModel.objects.create(uid=uid, ip=ip, country_name=country_name, region_name=region_name,
|
|
|
+ city_name=city_name, add_time=int(time.time()))
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|
|
|
+
|