commit
fd5938cae3
@ -0,0 +1,21 @@
|
||||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### Example user template template
|
||||
### Example user template
|
||||
|
||||
# IntelliJ project files
|
||||
.idea
|
||||
*.iml
|
||||
out
|
||||
gen
|
||||
### Maven template
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
|
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>beacon-cloud</artifactId>
|
||||
<groupId>com.mashibing</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>beacon-api</artifactId>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<!-- web项目-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- 注册到nacos-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<!-- nacos拉取配置-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
<!-- openFeign-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<!-- RabbitMQ-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
<!-- 记录日志等工具-->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<!-- 测试的依赖-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
<!-- 参数校验-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,18 @@
|
||||
package com.mashibing.api;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
public class ApiStarterApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ApiStarterApp.class,args);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.mashibing.api.controller;
|
||||
|
||||
import com.mashibing.api.enums.SmsCodeEnum;
|
||||
import com.mashibing.api.form.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 zjw
|
||||
* @description
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sms")
|
||||
@Slf4j
|
||||
public class SmsController {
|
||||
|
||||
|
||||
@PostMapping(value = "/single_send",produces = "application/json;charset=utf-8")
|
||||
public ResultVO singleSend(@RequestBody @Validated SingleSendForm singleSendForm, BindingResult bindingResult){
|
||||
//1. 校验参数
|
||||
if (bindingResult.hasErrors()){
|
||||
String msg = bindingResult.getFieldError().getDefaultMessage();
|
||||
log.info("【接口模块-单条短信Controller】 参数不合法 msg = {}",msg);
|
||||
return R.error(SmsCodeEnum.PARAMETER_ERROR.getCode(),msg);
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.mashibing.api.controller;
|
||||
|
||||
import com.mashibing.api.filter.CheckFilterContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description 测试校验链的效果
|
||||
*/
|
||||
@Controller
|
||||
public class TestController {
|
||||
|
||||
@Autowired
|
||||
private CheckFilterContext checkFilterContext;
|
||||
|
||||
@GetMapping("/api/test")
|
||||
public void test(){
|
||||
System.out.println("====================================");
|
||||
checkFilterContext.check(new Object());
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.mashibing.api.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 一些响应信息中code和msg的对应
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@Getter
|
||||
public enum SmsCodeEnum {
|
||||
PARAMETER_ERROR(-10,"参数不合法!");
|
||||
|
||||
private Integer code;
|
||||
private String msg;
|
||||
|
||||
SmsCodeEnum(Integer code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.mashibing.api.filter.impl;
|
||||
|
||||
import com.mashibing.api.filter.CheckFilter;
|
||||
import com.mashibing.api.form.SmsForm;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description 校验客户的apikey是否合法
|
||||
*/
|
||||
@Service(value = "apikey")
|
||||
@Slf4j
|
||||
public class ApiKeyCheckFilter implements CheckFilter {
|
||||
|
||||
|
||||
@Override
|
||||
public void check(SmsForm smsForm) {
|
||||
log.info("【接口模块-校验apikey】 校验ing…………");
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.mashibing.api.filter.impl;
|
||||
|
||||
import com.mashibing.api.filter.CheckFilter;
|
||||
import com.mashibing.api.form.SmsForm;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description 校验客户剩余的金额是否充足
|
||||
*/
|
||||
@Service(value = "fee")
|
||||
@Slf4j
|
||||
public class FeeCheckFilter implements CheckFilter {
|
||||
|
||||
|
||||
@Override
|
||||
public void check(SmsForm smsForm) {
|
||||
log.info("【接口模块-校验客户余额】 校验ing…………");
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.mashibing.api.filter.impl;
|
||||
|
||||
import com.mashibing.api.filter.CheckFilter;
|
||||
import com.mashibing.api.form.SmsForm;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description 校验请求的ip地址是否是白名单
|
||||
*/
|
||||
@Service(value = "ip")
|
||||
@Slf4j
|
||||
public class IPCheckFilter implements CheckFilter {
|
||||
|
||||
|
||||
@Override
|
||||
public void check(SmsForm smsForm) {
|
||||
log.info("【接口模块-校验ip】 校验ing…………");
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.mashibing.api.filter.impl;
|
||||
|
||||
import com.mashibing.api.filter.CheckFilter;
|
||||
import com.mashibing.api.form.SmsForm;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description 校验手机号的格式合法性
|
||||
*/
|
||||
@Service(value = "mobile")
|
||||
@Slf4j
|
||||
public class MobileCheckFilter implements CheckFilter {
|
||||
|
||||
|
||||
@Override
|
||||
public void check(SmsForm smsForm) {
|
||||
log.info("【接口模块-校验手机号】 校验ing…………");
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.mashibing.api.filter.impl;
|
||||
|
||||
import com.mashibing.api.filter.CheckFilter;
|
||||
import com.mashibing.api.form.SmsForm;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description 校验短信的签名
|
||||
*/
|
||||
@Service(value = "sign")
|
||||
@Slf4j
|
||||
public class SignCheckFilter implements CheckFilter {
|
||||
|
||||
|
||||
@Override
|
||||
public void check(SmsForm smsForm) {
|
||||
log.info("【接口模块-校验签名】 校验ing…………");
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.mashibing.api.filter.impl;
|
||||
|
||||
import com.mashibing.api.filter.CheckFilter;
|
||||
import com.mashibing.api.form.SmsForm;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description 校验短信的模板
|
||||
*/
|
||||
@Service(value = "template")
|
||||
@Slf4j
|
||||
public class TemplateCheckFilter implements CheckFilter {
|
||||
|
||||
|
||||
@Override
|
||||
public void check(SmsForm smsForm) {
|
||||
log.info("【接口模块-校验模板】 校验ing…………");
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.mashibing.api.util;
|
||||
|
||||
import com.mashibing.api.vo.ResultVO;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @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 msg) {
|
||||
ResultVO r = new ResultVO();
|
||||
r.setCode(code);
|
||||
r.setMsg(msg);
|
||||
return r;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.mashibing.api.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@Data
|
||||
public class ResultVO {
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String msg;
|
||||
|
||||
private Integer count;
|
||||
|
||||
private Long fee;
|
||||
|
||||
private String uid;
|
||||
|
||||
private String sid;
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
# 服务名称
|
||||
spring:
|
||||
application:
|
||||
name: beacon-api
|
||||
# 多环境
|
||||
profiles:
|
||||
active: dev
|
||||
# nacos注册中心地址
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 114.116.226.76:8848
|
||||
# nacos配置中心地址:
|
||||
config:
|
||||
server-addr: 114.116.226.76:8848
|
||||
file-extension: yml
|
||||
# beacon-api-dev.yml
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.mashibing.api.filter;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@SpringBootTest
|
||||
@RunWith(SpringRunner.class)
|
||||
public class CheckFilterContextTest {
|
||||
|
||||
@Autowired
|
||||
private CheckFilterContext checkFilterContext;
|
||||
|
||||
@org.junit.Test
|
||||
public void check() {
|
||||
Object obj = new Object();
|
||||
checkFilterContext.check(obj);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<modules>
|
||||
<module>beacon-api</module>
|
||||
</modules>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.12.RELEASE</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
<groupId>com.mashibing</groupId>
|
||||
<artifactId>beacon-cloud</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<spring.cloud-version>Hoxton.SR12</spring.cloud-version>
|
||||
<spring.cloud.alibaba-version>2.2.6.RELEASE</spring.cloud.alibaba-version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring.cloud-version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>${spring.cloud.alibaba-version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
Loading…
Reference in new issue