소스 검색

feature:支持uid通过ip地址获取该地址信息

chenjunkai 6 년 전
부모
커밋
2f5fadc9ad
3개의 변경된 파일57개의 추가작업 그리고 23개의 파일을 삭제
  1. 19 15
      Ansjer/test/test.py
  2. 1 0
      Ansjer/urls.py
  3. 37 8
      Controller/EquipmentStatus.py

+ 19 - 15
Ansjer/test/test.py

@@ -1,16 +1,20 @@
-def removeDuplicates(self, nums):
-    """
-    :type nums: List[int]
-    :rtype: int
-    """
-    diff_length = 0
-    index = -1
-    for index, item in enumerate(nums):
-        if nums[diff_length] != item:
-            diff_length += 1
-            nums[diff_length] = item
+import ipdb
 
-    if index >= diff_length:
-        return diff_length + 1
-    else:
-        return diff_length
+db = ipdb.City("D:/13.56.215.252/git/AnsjerFormal/DB/mydata4vipday2.ipdb")
+db.reload("/path/to/city.ipv4.ipdb") # update ipdb database file reload data
+# print(db.is_ipv4(), db.is_ipv6())
+# print(db.languages())  # support language
+# print(db.fields())  # support fields
+# print(db.build_time())  # build database time
+# print(db.languages())
+# xx = db.find_info("13.56.215.252", "EN")
+xx = db.find_map("13.56.215.252", "EN")
+
+from var_dump import var_dump
+
+var_dump(xx)
+exit()
+print()  # query ip return array
+# print(db.find(u"1.1.1.1", "CN")) #  Python 2.7
+print(db.find_map("8.8.8.8", "CN"))  # query ip return dict
+print(db.find_info("118.28.1.1", "CN").country_name) 

+ 1 - 0
Ansjer/urls.py

@@ -125,6 +125,7 @@ urlpatterns = [
     url(r'^appVer/views$', AppInfo.AppVersionView.as_view()),
 
     url(r'^user/init$', UserController.InitInfoView.as_view()),
+    url(r'^getTZ$', EquipmentStatus.getTZ),
 
     # 新的设备接口
     path('Test', Test.Test.as_view()),

+ 37 - 8
Controller/EquipmentStatus.py

@@ -11,16 +11,16 @@
 @file: EquipmentStat.py
 @Contact: chanjunkai@163.com
 """
+import base64
+import urllib.parse
+from Ansjer.config import BASE_DIR
+from django.http import JsonResponse
 from django.views.decorators.csrf import csrf_exempt
+
 from Model.models import Device_Info
-from django.utils import timezone
-from Service.CommonService import CommonService
-from django.views.generic.base import View
 from Object.ResponseObject import ResponseObject
-from Ansjer.config import UID_TOKEN_KEY
-import jwt
-from django.utils.decorators import method_decorator
-from Object.TokenObject import TokenObject
+from Service.CommonService import CommonService
+
 '''
 http://192.168.136.45:8077/device/online?UID=C2887N9EBS87ZAT1111A
 http://192.168.136.45:8077/device/offline?UID=C2887N9EBS87ZAT1111A
@@ -42,7 +42,6 @@ def EquipmentOnline(request):
         return response.json(173)
 
 
-
 @csrf_exempt
 def EquipmentOffline(request):
     response = ResponseObject()
@@ -84,3 +83,33 @@ def updateIP(request):
         print(repr(e))
     return response.json(0, {'area': area})
 
+import ipdb
+def getTZ(request):
+    request.encoding = 'utf-8'
+    if request.method == 'GET':
+        request_dict = request.GET
+    elif request.method == 'POST':
+        request_dict = request.POST
+    else:
+        return JsonResponse(status=200, data={'code': 403, 'msg': '接口请求方法错误'})
+    c = request_dict.get('etk', None)
+    ip = request_dict.get('ip',None)
+    lang = request_dict.get('lang',None)
+    if c:
+        c = base64.b64decode(c)
+        c = c[2:-2]
+        c = urllib.parse.unquote(c.decode('utf-8'))
+        c = base64.b64decode(c)
+        uid = c.decode('utf-8')
+        if len(uid) == 20:
+            db = ipdb.City(BASE_DIR + "/DB/mydata4vipday2.ipdb")
+            info = db.find_map(ip, lang)
+            # tz = info.timezone
+            # of = info.utc_offset
+            from var_dump import var_dump
+            var_dump(info)
+            return JsonResponse(status=200, data={'code': 0, 'msg': 'success', 'data': info})
+        else:
+            return JsonResponse(status=200,data={'code':404,'msg':'令牌错误'})
+    else:
+        return JsonResponse(status=200, data={'code': 444, 'msg': '接口参数错误 etk'})