From b379dadf34a0453673775900eba612396d6289bf Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 11 Apr 2022 13:41:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=89=E6=96=B9=E6=8E=A5=E5=8F=A3=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=9F=AD=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/third/views.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/apps/third/views.py b/apps/third/views.py index e7f5ca48..71071ce2 100644 --- a/apps/third/views.py +++ b/apps/third/views.py @@ -1,5 +1,5 @@ from rest_framework.exceptions import ParseError, APIException -from apps.third import tapis +from apps.third.tapis import dhapis, xxapis from apps.third.erros import TAPI_CODE_WRONG from apps.utils.dahua import dhClient from apps.utils.errors import XX_REQUEST_ERROR @@ -9,6 +9,7 @@ from rest_framework.views import APIView from rest_framework.permissions import IsAuthenticated from apps.utils.viewsets import CustomGenericViewSet from rest_framework.mixins import CreateModelMixin +from rest_framework.decorators import action from apps.third.serializers import RequestCommonSerializer # Create your views here. @@ -85,7 +86,7 @@ class XxCommonViewSet(CreateModelMixin, CustomGenericViewSet): vdata = serializer.validated_data if vdata.get('code', ''): try: - dhapi = tapis.dhapis[vdata['code']] + dhapi = dhapis[vdata['code']] except: raise ParseError(**TAPI_CODE_WRONG) vdata['url'] = dhapi['url'] @@ -97,6 +98,13 @@ class XxCommonViewSet(CreateModelMixin, CustomGenericViewSet): json=vdata.get('data', {})) return Response(res) + @action(methods=['get'], detail=False, permission_classes=[IsAuthenticated]) + def codes(self, request, pk=None): + """获取请求短标识 + + 获取请求短标识 + """ + return Response(xxapis) class DhCommonViewSet(CreateModelMixin, CustomGenericViewSet): """ @@ -111,7 +119,7 @@ class DhCommonViewSet(CreateModelMixin, CustomGenericViewSet): vdata = serializer.validated_data if vdata.get('code', ''): try: - xxapi = tapis.xxapis[vdata['code']] + xxapi = xxapis[vdata['code']] except: raise ParseError(**TAPI_CODE_WRONG) vdata['url'] = xxapi['url'] @@ -122,3 +130,11 @@ class DhCommonViewSet(CreateModelMixin, CustomGenericViewSet): params=vdata.get('params', {}), json=vdata.get('data', {})) return Response(res) + + @action(methods=['get'], detail=False, permission_classes=[IsAuthenticated]) + def codes(self, request, pk=None): + """获取请求短标识 + + 获取请求短标识 + """ + return Response(dhapis)