From 20f74288d44683fe30fe421ef4ec71caa0ee062c Mon Sep 17 00:00:00 2001 From: roger_mac Date: Thu, 28 Dec 2023 20:55:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=80=BC=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mock/utils/mock_service.py | 12 ------------ mock/views.py | 31 ++++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/mock/utils/mock_service.py b/mock/utils/mock_service.py index 53145e4..420ce73 100644 --- a/mock/utils/mock_service.py +++ b/mock/utils/mock_service.py @@ -32,9 +32,7 @@ def mock(_ip, _api, **kwargs): mock_data = get_overtime_ticket_status_tmp.get_json(cinema_obj, kwargs.get('request')) else: mock_data = get_overtime_ticket_status_tmp.get(cinema_obj, kwargs.get('request')) - print('mock_data', mock_data) if mock_data is not None: - print("this is none") return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False}) else: return bypass(kwargs.get('request')) @@ -45,24 +43,14 @@ def mock(_ip, _api, **kwargs): def bypass(_r): print('bypass') - print(_r.method, _r.path) - print(_r.GET) - print(_r.POST) if _r.method == 'GET': req_url = ZZ_URL + _r.path req_params = dict(_r.GET) - print(req_url) - print(req_params) response_dara = requests.get(req_url, params=req_params) - print(response_dara.json()) return JsonResponse(response_dara.json(), json_dumps_params={'ensure_ascii': False}) if _r.method == 'POST': req_url = ZZ_URL + _r.path req_params = dict(_r.GET) req_data = dict(_r.POST) - print(req_url) - print(req_params) - print(req_data) response_dara = requests.post(req_url, params=req_params, data=req_data) - print(response_dara.json()) return JsonResponse(response_dara.json(), json_dumps_params={'ensure_ascii': False}) diff --git a/mock/views.py b/mock/views.py index 49ab844..f72fb09 100644 --- a/mock/views.py +++ b/mock/views.py @@ -16,6 +16,8 @@ from mock.mock_templates import * from mock.cinema_sql import * ZZ_URL = 'https://zzcs.yinghezhong.com' +mock_config = dict() +json_data = dict() # 用于将前端的接口名转换成后端的 api_dict = { @@ -38,7 +40,8 @@ def report_ticket(request): ip = request.META.get('REMOTE_ADDR') mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() if mock_service_switch.reportTicket is True: - mock_service.bypass(request) + if customer_json := json_data.get('reportTicket'): + return customer_json return mock_service.mock(ip, 'reportTicket') else: return mock_service.bypass(request) @@ -50,7 +53,8 @@ def report_film_schedule(request): ip = request.META.get('REMOTE_ADDR') mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() if mock_service_switch.reportFilmSchedule is True: - mock_service.bypass(request) + if customer_json := json_data.get('reportFilmSchedule'): + return customer_json return mock_service.mock(ip, 'reportFilmSchedule') else: return mock_service.bypass(request) @@ -62,7 +66,8 @@ def upload_screen_seat_info(request): ip = request.META.get('REMOTE_ADDR') mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() if mock_service_switch.uploadScreenSeatInfo is True: - mock_service.bypass(request) + if customer_json := json_data.get('uploadScreenSeatInfo'): + return customer_json return mock_service.mock(ip, 'uploadScreenSeatInfo') else: return mock_service.bypass(request) @@ -74,6 +79,8 @@ def download_film_info(request): ip = request.META.get('REMOTE_ADDR') mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() if mock_service_switch.downloadFilmInfo is True: + if customer_json := json_data.get('downloadFilmInfo'): + return customer_json return mock_service.mock(ip, 'downloadFilmInfo') else: return mock_service.bypass(request) @@ -84,6 +91,8 @@ def get_cinema_info(request): ip = request.META.get('REMOTE_ADDR') mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() if mock_service_switch.getCinemaInfo is True: + if customer_json := json_data.get('getCinemaInfo'): + return customer_json return mock_service.mock(ip, 'getCinemaInfo') else: return mock_service.bypass(request) @@ -94,6 +103,8 @@ def get_screen_info(request): ip = request.META.get('REMOTE_ADDR') mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() if mock_service_switch.getScreenInfo is True: + if customer_json := json_data.get('getScreenInfo'): + return customer_json return mock_service.mock(ip, 'getScreenInfo') else: return mock_service.bypass(request) @@ -106,8 +117,8 @@ def get_overtime_ticket_status(request): ip = request.META.get('REMOTE_ADDR') mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() if mock_service_switch.getOvertimeTicketStatus is True: - r = mock_service.mock(ip, 'getOvertimeTicketStatus', request=request) - print('r', r) + if customer_json := json_data.get('getOvertimeTicketStatus'): + return customer_json return mock_service.mock(ip, 'getOvertimeTicketStatus', request=request) else: return mock_service.bypass(request) @@ -119,6 +130,8 @@ def valid_error(request): ip = request.META.get('REMOTE_ADDR') mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() if mock_service_switch.validError is True: + if customer_json := json_data.get('validError'): + return customer_json return mock_service.mock(ip, 'validError') else: return mock_service.bypass(request) @@ -228,11 +241,15 @@ def set_overtime_config(request): @csrf_exempt def enable_mock(request): ip = request.GET.get('ip') - req_mock_config = json.loads(request.body)['mock_config'] - mock_config = dict() + req = json.loads(request.body) + req_mock_config = req['mock_config'] + req_json_data = req['json_data'] for k, v in req_mock_config.items(): mock_config[api_dict[k]] = v + for k, v in req_json_data.items(): + json_data[api_dict[k]] = v print(mock_config) + print(json_data) server_ip = get_local_ip() current_host = db(ip, GET_ZZ_PLATFORM_HOST_SQL)['data'][0]['cinema_common_info_val'] if current_host == 'https://zzcs.yinghezhong.com' or current_host == 'https://dy.yinghezhong.com':