From 39b99b25ba65d5dfc91a22e31560aee61afbed7c Mon Sep 17 00:00:00 2001 From: kezhen0805 Date: Sat, 24 Dec 2022 23:09:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E6=9D=A1=E5=8F=91=E9=80=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E5=8F=82=E6=95=B0=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beancon-api/pom.xml | 5 +++ .../api/controller/SmsController.java | 40 +++++++++++++++++++ .../com/mashibing/api/enums/SmsCodeEnum.java | 20 ++++++++++ .../api/filter/CheckFilterContext.java | 2 +- .../mashibing/api/from/SingleSendForm.java | 33 +++++++++++++++ .../main/java/com/mashibing/api/util/R.java | 24 +++++++++++ .../java/com/mashibing/api/vo/ResultVO.java | 18 +++++++++ 7 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 beancon-api/src/main/java/com/mashibing/api/controller/SmsController.java create mode 100644 beancon-api/src/main/java/com/mashibing/api/enums/SmsCodeEnum.java create mode 100644 beancon-api/src/main/java/com/mashibing/api/from/SingleSendForm.java create mode 100644 beancon-api/src/main/java/com/mashibing/api/util/R.java create mode 100644 beancon-api/src/main/java/com/mashibing/api/vo/ResultVO.java diff --git a/beancon-api/pom.xml b/beancon-api/pom.xml index a5bc818..6480e16 100644 --- a/beancon-api/pom.xml +++ b/beancon-api/pom.xml @@ -47,6 +47,11 @@ org.springframework.boot spring-boot-starter-test + + + org.springframework.boot + spring-boot-starter-validation + diff --git a/beancon-api/src/main/java/com/mashibing/api/controller/SmsController.java b/beancon-api/src/main/java/com/mashibing/api/controller/SmsController.java new file mode 100644 index 0000000..343c76c --- /dev/null +++ b/beancon-api/src/main/java/com/mashibing/api/controller/SmsController.java @@ -0,0 +1,40 @@ +package com.mashibing.api.controller; + +import com.mashibing.api.enums.SmsCodeEnum; +import com.mashibing.api.from.SingleSendForm; +import com.mashibing.api.util.R; +import com.mashibing.api.vo.ResultVO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.BindingResult; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author kezhen + * @date 2022/12/23 + * @description + */ +@RestController +@RequestMapping("/sms") +@Slf4j +public class SmsController { + + /** + * @param singleSendForm + * @return + */ + @PostMapping(value = "/single_send", produces = "application/json;charset=utf-8") + public ResultVO signleSend(@RequestBody @Validated SingleSendForm singleSendForm, BindingResult bindingResult) { + System.out.println(singleSendForm); + System.out.println("SmsController.signleSend"); + if (bindingResult.hasErrors()) { + String message = bindingResult.getFieldError().getDefaultMessage(); + log.info("【接口模块-单条短信Contorller】 参数不合法,msg = {}", message); + return R.error(SmsCodeEnum.PARAMETER_ERROR.getCode(),message); + } + return R.ok(); + } +} diff --git a/beancon-api/src/main/java/com/mashibing/api/enums/SmsCodeEnum.java b/beancon-api/src/main/java/com/mashibing/api/enums/SmsCodeEnum.java new file mode 100644 index 0000000..43411a1 --- /dev/null +++ b/beancon-api/src/main/java/com/mashibing/api/enums/SmsCodeEnum.java @@ -0,0 +1,20 @@ +package com.mashibing.api.enums; + +import lombok.Getter; + +/** + * @author kezhen + * @date 2022/12/24 + * @description 一些相应信息中code和message的对应 + */ +@Getter +public enum SmsCodeEnum { + PARAMETER_ERROR(-10,"参数不合法"); + private Integer code; + private String meg; + + SmsCodeEnum(Integer code, String meg) { + this.code = code; + this.meg = meg; + } +} diff --git a/beancon-api/src/main/java/com/mashibing/api/filter/CheckFilterContext.java b/beancon-api/src/main/java/com/mashibing/api/filter/CheckFilterContext.java index 5e4468f..53f269c 100644 --- a/beancon-api/src/main/java/com/mashibing/api/filter/CheckFilterContext.java +++ b/beancon-api/src/main/java/com/mashibing/api/filter/CheckFilterContext.java @@ -9,7 +9,7 @@ import java.util.Map; /** * @author kezhen - * @description + * @description 策略模式的上下文对象 */ @Component @RefreshScope diff --git a/beancon-api/src/main/java/com/mashibing/api/from/SingleSendForm.java b/beancon-api/src/main/java/com/mashibing/api/from/SingleSendForm.java new file mode 100644 index 0000000..51abf52 --- /dev/null +++ b/beancon-api/src/main/java/com/mashibing/api/from/SingleSendForm.java @@ -0,0 +1,33 @@ +package com.mashibing.api.from; + +import lombok.Data; +import lombok.ToString; +import org.hibernate.validator.constraints.Range; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * @author kezhen + * @date 2022/12/23 + * @description 封装 + */ +@Data +@ToString +public class SingleSendForm { + // 客户的apikey + @NotBlank(message = "apikey不允许为空!") + private String apikey; + // 手机号 + @NotBlank(message = "手机号不允许为空!") + private String mobile; + // 短信内容 + @NotBlank(message = "短信内容不允许为空!") + private String text; + // 客户业务内的uid + private String uid; + // 短信类型 0-验证码短信 1-通知类短信 2-营销类短信 + @Range(min = 0,max = 2,message = "短信类型只能是0~2的整数!") + @NotNull(message = "短信类型不允许为空") + private Integer state; +} diff --git a/beancon-api/src/main/java/com/mashibing/api/util/R.java b/beancon-api/src/main/java/com/mashibing/api/util/R.java new file mode 100644 index 0000000..e9db904 --- /dev/null +++ b/beancon-api/src/main/java/com/mashibing/api/util/R.java @@ -0,0 +1,24 @@ +package com.mashibing.api.util; + +import com.mashibing.api.vo.ResultVO; + +/** + * @author kezhen + * @date 2022/12/23 + * @description + */ +public class R { + public static ResultVO ok() { + ResultVO r = new ResultVO(); + r.setCode(0); + r.setMsg("接收成功"); + return r; + } + + public static ResultVO error(Integer code, String message) { + ResultVO r = new ResultVO(); + r.setCode(code); + r.setMsg(message); + return r; + } +} diff --git a/beancon-api/src/main/java/com/mashibing/api/vo/ResultVO.java b/beancon-api/src/main/java/com/mashibing/api/vo/ResultVO.java new file mode 100644 index 0000000..ba5b748 --- /dev/null +++ b/beancon-api/src/main/java/com/mashibing/api/vo/ResultVO.java @@ -0,0 +1,18 @@ +package com.mashibing.api.vo; + +import lombok.Data; + +/** + * @author kezhen + * @date 2022/12/23 + * @description + */ +@Data +public class ResultVO { + private Integer code; + private String msg; + private Integer count; + private Long fee; + private String uid; + private String sid; +}