三方接口增加短标识

This commit is contained in:
caoqianming 2022-04-11 13:41:51 +08:00
parent 57adbea2f0
commit b379dadf34
1 changed files with 19 additions and 3 deletions

View File

@ -1,5 +1,5 @@
from rest_framework.exceptions import ParseError, APIException 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.third.erros import TAPI_CODE_WRONG
from apps.utils.dahua import dhClient from apps.utils.dahua import dhClient
from apps.utils.errors import XX_REQUEST_ERROR 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 rest_framework.permissions import IsAuthenticated
from apps.utils.viewsets import CustomGenericViewSet from apps.utils.viewsets import CustomGenericViewSet
from rest_framework.mixins import CreateModelMixin from rest_framework.mixins import CreateModelMixin
from rest_framework.decorators import action
from apps.third.serializers import RequestCommonSerializer from apps.third.serializers import RequestCommonSerializer
# Create your views here. # Create your views here.
@ -85,7 +86,7 @@ class XxCommonViewSet(CreateModelMixin, CustomGenericViewSet):
vdata = serializer.validated_data vdata = serializer.validated_data
if vdata.get('code', ''): if vdata.get('code', ''):
try: try:
dhapi = tapis.dhapis[vdata['code']] dhapi = dhapis[vdata['code']]
except: except:
raise ParseError(**TAPI_CODE_WRONG) raise ParseError(**TAPI_CODE_WRONG)
vdata['url'] = dhapi['url'] vdata['url'] = dhapi['url']
@ -97,6 +98,13 @@ class XxCommonViewSet(CreateModelMixin, CustomGenericViewSet):
json=vdata.get('data', {})) json=vdata.get('data', {}))
return Response(res) return Response(res)
@action(methods=['get'], detail=False, permission_classes=[IsAuthenticated])
def codes(self, request, pk=None):
"""获取请求短标识
获取请求短标识
"""
return Response(xxapis)
class DhCommonViewSet(CreateModelMixin, CustomGenericViewSet): class DhCommonViewSet(CreateModelMixin, CustomGenericViewSet):
""" """
@ -111,7 +119,7 @@ class DhCommonViewSet(CreateModelMixin, CustomGenericViewSet):
vdata = serializer.validated_data vdata = serializer.validated_data
if vdata.get('code', ''): if vdata.get('code', ''):
try: try:
xxapi = tapis.xxapis[vdata['code']] xxapi = xxapis[vdata['code']]
except: except:
raise ParseError(**TAPI_CODE_WRONG) raise ParseError(**TAPI_CODE_WRONG)
vdata['url'] = xxapi['url'] vdata['url'] = xxapi['url']
@ -122,3 +130,11 @@ class DhCommonViewSet(CreateModelMixin, CustomGenericViewSet):
params=vdata.get('params', {}), params=vdata.get('params', {}),
json=vdata.get('data', {})) json=vdata.get('data', {}))
return Response(res) return Response(res)
@action(methods=['get'], detail=False, permission_classes=[IsAuthenticated])
def codes(self, request, pk=None):
"""获取请求短标识
获取请求短标识
"""
return Response(dhapis)