From 2e04fa4dca504f55859dcde9cbc937abb42cce73 Mon Sep 17 00:00:00 2001 From: kurami Date: Mon, 25 Sep 2023 21:18:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=89=8D=E6=A3=80=E6=9F=A5=E8=BE=93?= =?UTF-8?q?=E5=85=A5JSON=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/ChannelAccountController.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/ChannelAccountController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/ChannelAccountController.java index 900bd46..c699797 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/controller/ChannelAccountController.java +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/ChannelAccountController.java @@ -2,7 +2,9 @@ package com.java3y.austin.web.controller; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.common.enums.AccountFormat; import com.java3y.austin.common.enums.RespStatusEnum; import com.java3y.austin.support.domain.ChannelAccount; import com.java3y.austin.web.annotation.AustinAspect; @@ -48,6 +50,7 @@ public class ChannelAccountController { @PostMapping("/save") @ApiOperation("/保存数据") public ChannelAccount saveOrUpdate(@RequestBody ChannelAccount channelAccount) { + accountConfigPreCheck(channelAccount); if (loginUtils.needLogin() && StrUtil.isBlank(channelAccount.getCreator())) { throw new CommonException(RespStatusEnum.NO_LOGIN.getCode(), RespStatusEnum.NO_LOGIN.getMsg()); } @@ -99,4 +102,14 @@ public class ChannelAccountController { } } + /** + * 检查JSON格式是否正确 + */ + public void accountConfigPreCheck(ChannelAccount channelAccount) throws CommonException{ + try{ + JSON.parseObject(channelAccount.getAccountConfig(), Object.class); + }catch (Exception e){ + throw new CommonException(RespStatusEnum.CLIENT_BAD_PARAMETERS.getCode(), RespStatusEnum.CLIENT_BAD_PARAMETERS.getMsg()); + } + } }