# -*- encoding: utf-8 -*- """ @File : UnicomComboController.py @Time : 2022/6/23 9:18 @Author : stephen @Email : zhangdongming@asj6.wecom.work @Software: PyCharm """ import json from django.http import HttpResponse from django.views.generic.base import View class UnicomComboView(View): def get(self, request, *args, **kwargs): request.encoding = 'utf-8' operation = kwargs.get('operation') return self.validation(request.GET, request, operation) def post(self, request, *args, **kwargs): request.encoding = 'utf-8' operation = kwargs.get('operation') return self.validation(request.POST, request, operation) def validation(self, request_dict, request, operation): if operation == 'test': return self.test(request_dict, request) else: r_data = {'success': False, 'msg': '失败'} return HttpResponse(json.dumps(r_data, ensure_ascii=False), content_type="application/json,charset=utf-8") @staticmethod def test(request_dict, request): body = request.body.decode("utf-8") if body: dict_data = json.loads(body) print(dict_data) print(request_dict) r_data = {'success': True, 'msg': '成功'} return HttpResponse(json.dumps(r_data, ensure_ascii=False), content_type="application/json,charset=utf-8")