def post(request, *args, **kwargs): keys = list(request.GET.keys()) data = dict(keys=keys) try: result = json.loads(request.body) except json.JSONDecodeError as exc: msg = f'JSON解析失败:{str(exc)}' data['_trace'] = trace_request(request) api_resp = apr.APIFailResp(_msg=msg, data=data) resp = JsonResponse( data=api_resp.to_dict(), status=status.HTTP_400_BAD_REQUEST, ) return resp if 'Call' in keys: CallRecord.objects.callback_call_ytx(result['cdr'][0]) elif 'CallState' in keys: CallRecord.objects.callback_status_ytx(result) else: msg = f'未识别的业务类型:{keys}' data['_trace'] = trace_request(request) api_resp = apr.APIFailResp(_msg=msg, data=data) resp = JsonResponse( data=api_resp.to_dict(), status=status.HTTP_400_BAD_REQUEST, ) return resp data['_trace'] = trace_request(request) api_resp = apr.APIOKResp(data=data) resp = JsonResponse(data=api_resp.to_dict()) return resp
def post(self, request, *args, **kwargs): symbol = self.get_symbol(kwargs) phone = Phone.objects.user_phone_main(request.user.pk) if not phone: api_resp = apr.APIFailResp(_msg='暂未绑定手机号', data=dict(symbol=symbol.symbol)) return Response(data=api_resp.to_dict()) is_send, resp = phone.captcha_send_for_symbol_strike() logger.info( f'captcha_send_for_symbol_strike__done {symbol.symbol} {phone.summary} {is_send} {resp}' ) data = dict(phone=phone.show, symbol=symbol.symbol) if is_send: api_resp = apr.APIOKResp(data=data) else: api_resp = apr.APIFailResp(_msg=resp, data=data) return Response(data=api_resp.to_dict())
def post(self, request, *args, **kwargs): usrid = request.user.pk q_serializer = self.serializer_class(data=request.data, ) q_serializer.is_valid(raise_exception=True) qr_parse = q_serializer.validated_data['parse'] assert isinstance(qr_parse, QRParse) if not qr_parse.is_ok: api_resp = apr.APIFailResp(_msg=qr_parse.reason, data={}) return Response(data=api_resp.to_dict()) q_dic = asdict(qr_parse) is_ok, resp = qrcode_bind(usrid, q_dic) if is_ok: data = dict(fmt=resp.fmt, symbol=resp.symbol) api_resp = apr.APIOKResp(data=data) else: api_resp = apr.APIFailResp(_msg=resp, data={}) return Response(data=api_resp.to_dict())
def get(request, *args, **kwargs): trace = trace_request(request) data = dict(_trace=trace, keys=list(request.GET.keys())) api_resp = apr.APIFailResp(_msg='GET方法不允许', data=data) resp = JsonResponse( data=api_resp.to_dict(), status=status.HTTP_405_METHOD_NOT_ALLOWED, ) return resp
def post(self, request, *args, **kwargs): add_serializer = self.serializer_class( data=request.data, context={'user': request.user}, ) add_serializer.is_valid(raise_exception=True) data = add_serializer.validated_data phone = data['phone'] is_send, resp = phone.captcha_send_for_bind() logger.info(f'captcha_send_for_bind__done {phone.summary} {is_send} {resp}') request.session['bind_pnvid'] = resp request.session['bind_phoneid'] = phone.pk request.session['bind_usrid'] = phone.usrid data = dict(phone=phone.show) if is_send: api_resp = apr.APIOKResp(data=data) else: api_resp = apr.APIFailResp(_msg=resp, data=data) return Response(data=api_resp.to_dict())
def post(self, request, *args, **kwargs): img_serializer = self.serializer_class( data=request.data, context={'user': request.user}, ) img_serializer.is_valid(raise_exception=True) oss_key = img_serializer.validated_data['img'] inst = VehicleLicense.objects.vehicle_license_add( oss_key, request.user.pk) if inst.is_verified: is_ok, resp = Vehicle.objects.bind_vehicle_symbol(inst) else: is_ok, resp = False, inst.reason if is_ok: assert isinstance(resp, Symbol) data = serializer.SymbolSerializer(resp).data api_resp = apr.APIOKResp(data=data) else: api_resp = apr.APIFailResp(_msg=resp, data={}) return Response(data=api_resp.to_dict())
def get(self, request, *args, **kwargs): usrid = request.user.pk try: year, month = kwargs['year'], kwargs['month'] month_dt = datetime.date(year, month, 1) month_str = month_dt.isoformat()[:7] except (KeyError, ValueError): errors = ['月份输入有误'] drf_status = status.HTTP_400_BAD_REQUEST api_resp = apr.APIFailResp(data=dict(errors=errors)) return Response(data=api_resp.to_dict(), status=drf_status) try: inst = BillMonth.objects.get(month=month_dt, usrid=usrid) except BillMonth.DoesNotExist: reason = [f'{month_str} 无记录'] data = dict(details=[], fmt=month_str, reason=reason, count=0, amount=0) else: data = self.serializer_class(inst).data api_resp = apr.APIOKResp(data=data) return Response(data=api_resp.to_dict())