Эх сурвалжийг харах

ota下载包多语言增加

chenjunkai 6 жил өмнө
parent
commit
4fc6fa03bc

+ 6 - 1
Ansjer/urls.py

@@ -7,6 +7,7 @@ from Controller import FeedBackInfo, EquipmentOTA, EquipmentInfo, EquipmentSenso
     EquipmentManager, LogManager, PermissionManager, OTAEquipment, shareUserPermission, UserManger, CheckUserData, \
     UserController
 
+
 urlpatterns = [
     url(r'^account/authcode$', UserController.authCodeView.as_view()),
     url(r'^account/register$', UserController.registerView.as_view()),
@@ -49,7 +50,7 @@ urlpatterns = [
     url(r'^OTA/getEquipmentVersion$', OTAEquipment.getEquipmentVersionInterface),
     url(r'^OTA/getUpdataFileUrl$', OTAEquipment.getUpdataFileUrlInterface),
     url(r'^OTA/addNewEquipmentVersion$', OTAEquipment.addNewEquipmentVersionInterface),
-    url(r'^OTA/showAllEquipmentVersion$', OTAEquipment.showAllEquipmentVersionInterface),
+    # url(r'^OTA/showAllEquipmentVersion$', OTAEquipment.showAllEquipmentVersionInterface),
 
     url(r'^roles/addNewRole$', PermissionManager.addNewRoleView.as_view()),
     url(r'^roles/queryRole$', PermissionManager.queryRoleView.as_view()),
@@ -114,6 +115,10 @@ urlpatterns = [
     path('access/deleteSn/', AccessLog.deleteSn),
     # 多条件搜索用户信息admin
     path('accounts', AdminManage.search_user_by_content),
+
+    # 新需求v1接口
+    url(r'^OTA/getNewVer', OTAEquipment.getNewVerInterface),
+
     # 测试专用api
     path('Test', Test.Test.as_view()),
     # 路由加参数参考

+ 8 - 0
Controller/EquipmentOTA.py

@@ -9,6 +9,9 @@ import os,simplejson as json
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Ansjer.settings import BASE_DIR
+from Ansjer.config import SERVER_DOMAIN
+import time
+
 
 '''
 http://192.168.136.45:8077/equipment/OTA?token=test&operation=query&page=1&line=10
@@ -146,3 +149,8 @@ class EquipmentOTA(View):
                 return response.json(404)
         return response.json(444)
 
+
+
+
+
+

+ 37 - 24
Controller/OTAEquipment.py

@@ -66,8 +66,6 @@ def addNewEquipmentVersion(deviceContent, token,response):
     else:
         return response.json(311)
 
-
-
 def downloadUrl(fileType, fileCode, fileVersion, fileName):
     fullPath = os.path.join(BASE_DIR, "static/Upgrade").replace('\\', '/')
     if fileType == 'IPC':
@@ -148,7 +146,6 @@ def getMD5orSHA265(fileName, encryptionType='MD5'):
         f.close()
         return encryption.hexdigest()
 
-
 @csrf_exempt
 def downloadUpdataFileUrl(request):
     response = ResponseObject()
@@ -175,12 +172,10 @@ def downloadUpdataFileUrl(request):
         response['Content-Error'] = errorJSON
         return response
 
-
 '''
 http://192.168.136.40:8077/OTA/getEquipmentVersion?31AX162001A
 '''
 
-
 @csrf_exempt
 def getEquipmentVersionInterface(request):
     response = ResponseObject()
@@ -194,7 +189,7 @@ def getEquipmentVersionInterface(request):
         return response.json(801)
     if code is not None:
         try:
-            equipmentValid = Equipment_Version.objects.filter(code=code, status=1).order_by('-data_joined')
+            equipmentValid = Equipment_Version.objects.filter(code=code, status=1,lang='').order_by('-data_joined')
         except Exception as e:
             errorInfo = traceback.format_exc()
             print('查询数据库错误: %s' % errorInfo)
@@ -208,7 +203,6 @@ def getEquipmentVersionInterface(request):
     else:
         return response.json(800)
 
-
 @csrf_exempt
 def getUpdataFileUrlInterface(request):
     response = ResponseObject()
@@ -248,8 +242,6 @@ def getUpdataFileUrlInterface(request):
     else:
         return response.json(800)
 
-
-
 @csrf_exempt
 def downloadUpdataFileUrlInterface(request, fileType, fileName,
                                    *callback_args, **callback_kwargs):
@@ -312,7 +304,6 @@ def downloadUpdataFileUrlInterface(request, fileType, fileName,
         response['Content-Error'] = errorJSON
         return response
 
-
 class getUploadFiletoDirView(TemplateView):
     @method_decorator(csrf_exempt)
     def dispatch(self, *args, **kwargs):
@@ -439,7 +430,6 @@ class getUploadFiletoDirView(TemplateView):
             filePath = file_name[index:]
             return response.json(0, {'filePath': filePath})
 
-
 @csrf_exempt
 def addNewEquipmentVersionInterface(request):
 
@@ -461,7 +451,6 @@ def addNewEquipmentVersionInterface(request):
     else:
         return response.json(800)
 
-
 def showAllEquipmentVersion(userID,response):
     try:
         userValid = Device_User.objects.filter(userID=userID).order_by('-data_joined')
@@ -483,27 +472,51 @@ def showAllEquipmentVersion(userID,response):
         else:
             return response.json(113)
 
-
+# 检测ota更新包
 @csrf_exempt
-def showAllEquipmentVersionInterface(request):
+def getNewVerInterface(request):
     response = ResponseObject()
-    if request.method == 'POST':
+    if request.method == "POST":
+        request.encoding = 'utf-8'
+        code = request.POST.get('code', None)
         token = request.POST.get('token', None)
-    elif request.method == 'GET':
+        lang = request.POST.get('lang', None)
+    elif request.method == "GET":
+        request.encoding = 'gb2312'
+        code = request.GET.get('code', None)
         token = request.GET.get('token', None)
-    if token is not None:
+        # 利用语言包判断传递
+        lang = request.GET.get('lang', None)
+    else:
+        return response.json(801)
+    if code is not None and token is not None:
         tko = TokenObject(token)
         tko.valid()
         response.lang = tko.lang
         if tko.code == 0:
-            userID = tko.userID
-            if userID:
-                return showAllEquipmentVersion(userID,response)
+            try:
+                if lang:
+                    equipmentValid = Equipment_Version.objects.filter(code=code, status=1, lang=lang).order_by('-data_joined')
+                else:
+                    equipmentValid = Equipment_Version.objects.filter(code=code, status=1).order_by('-data_joined')
+            except Exception as e:
+                return response.json(500, {'details': repr(e)})
             else:
-                return response.json(310)
+                if equipmentValid.exists():
+                    ver = equipmentValid[0].softwareVersion
+                    equipment = equipmentValid[0]
+                    file_path = equipment.filePath
+                    path = file_path.replace('static/Upgrade/', '').replace('\\', '/')
+                    url = SERVER_DOMAIN + '/OTA/downloads/' + path + '?time=' + str(time.time())
+                    return response.json(0, {
+                        'ver': ver,
+                        'url': url,
+                        # "fileSize": equipment.fileSize,
+                        "Description": equipment.Description,
+                    })
+                else:
+                    return response.json(902)
         else:
             return response.json(tko.code)
     else:
-        return response.json(800)
-
-
+        return response.json(444,'token,code')

+ 65 - 5
Controller/Test.py

@@ -29,6 +29,9 @@ from ratelimit.decorators import ratelimit
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.RedisObject import RedisObject
+from django.shortcuts import render_to_response,render,redirect
+import paypalrestsdk
+from django.http import HttpResponseRedirect
 
 
 class Test(View):
@@ -44,14 +47,71 @@ class Test(View):
     def dispatch(self, *args, **kwargs):
         return super(Test, self).dispatch(*args, **kwargs)
 
-    @ratelimit(key='ip', rate='1/m')
     # 查询
+    '''
+    /Test?paymentId=PAY-4VL25365CA733482BLPMAHBI&token=EC-1SU951197H0006730&PayerID=A29TCMY2J8G9C
+    '''
+    @ratelimit(key='ip', rate='1/m')
     def get(self, request, *args, **kwargs):
         response = ResponseObject()
-        redisObj = RedisObject()
-        key=request.GET.get('key')
-        return response.json(0,redisObj.get_data(key=key)
-)
+        # return response.json(0)
+        paymentId = request.GET.get('paymentId',None)
+        PayerID = request.GET.get('PayerID',None)
+        if paymentId and PayerID:
+            paypalrestsdk.configure({
+                "mode": "sandbox",  # sandbox or live
+                "client_id": "AfnfDqezODOoWGS-W2Itu-Zl1ay1R95IsGlMqPghPA3KGhkPndNMnQT0bdEewvSv92XAFIfLiinmyhBL",
+                "client_secret": "EErLskwYA1xXY3890mHx5OhzgK83B2rNc57zIozGNyKc8i6RJuhPTF9WyhhdZgyDEih0heo1MH9Jk1lj"
+            })
+            # ID of the payment. This ID is provided when creating payment.
+            payment = paypalrestsdk.Payment.find(paymentId)
+            payres = payment.execute({"payer_id": PayerID})
+            print(payres)
+            if payres:
+                print("Payment execute successfully")
+            else:
+                print(payment.error)  # Error Hash
+            return response.json(0)
+        else:
+            pass
+        paypalrestsdk.configure({
+            "mode": "sandbox",  # sandbox or live
+            "client_id": "AfnfDqezODOoWGS-W2Itu-Zl1ay1R95IsGlMqPghPA3KGhkPndNMnQT0bdEewvSv92XAFIfLiinmyhBL",
+            "client_secret": "EErLskwYA1xXY3890mHx5OhzgK83B2rNc57zIozGNyKc8i6RJuhPTF9WyhhdZgyDEih0heo1MH9Jk1lj"})
+
+        payment = paypalrestsdk.Payment({
+            "intent": "sale",
+            "payer": {
+                "payment_method": "paypal"},
+            "redirect_urls": {
+                # "return_url": "http://192.168.136.45:3000/payment/execute",
+                "return_url": "http://192.168.136.40:8077/Test",
+                "cancel_url": "http://localhost:3000/"},
+            "transactions": [{
+                "item_list": {
+                    "items": [{
+                        "name": "item",
+                        "sku": "item",
+                        "price": "5.00",
+                        "currency": "USD",
+                        "quantity": 1}]},
+                "amount": {
+                    "total": "5.00",
+                    "currency": "USD"},
+                "description": "This is the payment transaction description."}]})
+
+        if payment.create():
+            print("Payment created successfully")
+        else:
+            print(payment.error)
+        print(payment)
+        for link in payment.links:
+            if link.rel == "approval_url":
+                # Convert to str to avoid Google App Engine Unicode issue
+                # https://github.com/paypal/rest-api-sdk-python/pull/58
+                approval_url = str(link.href)
+                print("Redirect for approval: %s" % (approval_url))
+                return HttpResponseRedirect(approval_url)
 
     # 增加
     def post(self, request, *args, **kwargs):

+ 3 - 0
Controller/UserController.py

@@ -296,6 +296,8 @@ class LoginView(TemplateView):
     def validates(self, request_dict, response):
         username = request_dict.get('userName', None)
         password = request_dict.get('userPwd', None)
+        print(username)
+        print(password)
         mcode = request_dict.get('mobileMechanicalCode', '')
         if username and password:
             username = username.strip()
@@ -563,6 +565,7 @@ class EmailResetPwdView(TemplateView):
         else:
             return response.json(444, 'token')
 
+
 class refreshTokenView(TemplateView):
     @method_decorator(csrf_exempt)
     def dispatch(self, *args, **kwargs):

+ 6 - 7
Service/TemplateService.py

@@ -30,16 +30,16 @@ class TemplateService:
             'account/getAvatar',
             'account/delUser',
             'account/setUserValid',
-            'account/showAllUser',
+            # 'account/showAllUser',
             'account/help',
             'account/searchUser',
             'account/unsharedUserEquipment',
-            'account/success',
+            # 'account/success',
             'equipment/queryUserEquipment',
             'equipment/addNewUserEquipment',
             'equipment/delUserEquipment',
             'equipment/modifyUserEquipment',
-            'equipment/showAllUserEquipment',
+            # 'equipment/showAllUserEquipment',
             'accessLog/findEquipmentInfo',
             'OTA/uploads',
             'OTA/download',
@@ -47,9 +47,8 @@ class TemplateService:
             'OTA/getEquipmentVersion',
             'OTA/getUpdataFileUrl',
             'OTA/addNewEquipmentVersion',
-            'OTA/showAllEquipmentVersion',
+            # 'OTA/showAllEquipmentVersion',
             'OTA/getUpdataFileUrl',
-            'mobile/uploadlogFile',
             'roles/addNewRole',
             'roles/queryRole',
             'roles/delRole',
@@ -60,10 +59,10 @@ class TemplateService:
             'perms/modifyPerms',
             'permsManager/queryRolePerms',
             'uploads/upgrade',
-            'upgrade/download',
+            # 'upgrade/download',
             'downloads/upgrade',
             'getOTAurl/getUpdataFileUrl',
-            'equipment/sensor',
+            # 'equipment/sensor',
             'equipment/info',
             'adminManage/manage',
             'equipment/OTA',