f4da767b by 周伟奇

add Go

1 parent d204dc5f
1 from django.urls import path
2 from . import views
3
4
5 urlpatterns = [
6 path(r'v1', views.GoView.as_view()),
7 ]
...@@ -6,6 +6,7 @@ import random ...@@ -6,6 +6,7 @@ import random
6 import datetime 6 import datetime
7 import fitz 7 import fitz
8 import shutil 8 import shutil
9 import requests
9 from openpyxl import Workbook 10 from openpyxl import Workbook
10 from django.utils import timezone 11 from django.utils import timezone
11 # from django.http import HttpResponse 12 # from django.http import HttpResponse
...@@ -67,6 +68,10 @@ def load_data(request, schema): ...@@ -67,6 +68,10 @@ def load_data(request, schema):
67 return request.data 68 return request.data
68 69
69 70
71 go_args = {
72 'image': fields.Raw(required=True),
73 }
74
70 usedcar_args = { 75 usedcar_args = {
71 'vinNo': fields.Str(required=True, validate=validate.Length(max=128)), 76 'vinNo': fields.Str(required=True, validate=validate.Length(max=128)),
72 "manufactureDate": CustomDate(required=True), 77 "manufactureDate": CustomDate(required=True),
...@@ -1496,3 +1501,22 @@ class MPOSView(GenericView, MPOSHandler): ...@@ -1496,3 +1501,22 @@ class MPOSView(GenericView, MPOSHandler):
1496 result_list.extend(result) 1501 result_list.extend(result)
1497 1502
1498 return response.ok(data=result_list) 1503 return response.ok(data=result_list)
1504
1505
1506 class GoView(GenericView):
1507 permission_classes = [IsAuthenticated]
1508 authentication_classes = [OAuth2AuthenticationWithUser]
1509
1510 @use_args(go_args, location='files')
1511 def post(self, request, args):
1512 files = [
1513 ('img', ('file', args.get('image'), 'application/octet-stream'))
1514 ]
1515
1516 go_result = requests.post(url=conf.GO_OCR_URL, files=files)
1517
1518 if go_result.status_code == 200:
1519 result = go_result.json().get('data', '')
1520 return response.ok(data=result)
1521 else:
1522 return response.res_content(3, '识别错误', data=None)
......
...@@ -26,5 +26,6 @@ urlpatterns = [ ...@@ -26,5 +26,6 @@ urlpatterns = [
26 path(r'api/compare/', include('apps.doc.compare_urls')), 26 path(r'api/compare/', include('apps.doc.compare_urls')),
27 path(r'api/doc/', include('apps.doc.internal_urls')), 27 path(r'api/doc/', include('apps.doc.internal_urls')),
28 path(r'api/mpos/', include('apps.doc.mpos_urls')), 28 path(r'api/mpos/', include('apps.doc.mpos_urls')),
29 path(r'api/go/', include('apps.doc.go_urls')),
29 path('api/oauth/', include('oauth2_provider.urls', namespace='oauth2_provider')), 30 path('api/oauth/', include('oauth2_provider.urls', namespace='oauth2_provider')),
30 ] 31 ]
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!