asa
parent
bc0929d571
commit
9ffad64773
|
@ -7,18 +7,27 @@
|
|||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="zhn-auth" />
|
||||
<module name="zhn-common" />
|
||||
<module name="zhn-gateway" />
|
||||
<module name="zhn-system" />
|
||||
<module name="xsnb-gateway" />
|
||||
<module name="xsnb-system" />
|
||||
<module name="xsnb-common" />
|
||||
<module name="xsnb-auth" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel target="17" />
|
||||
<bytecodeTargetLevel target="17">
|
||||
<module name="zhn-auth" target="1.8" />
|
||||
<module name="zhn-dev" target="1.8" />
|
||||
<module name="zhn-gateway" target="1.8" />
|
||||
<module name="zhn-modules" target="1.8" />
|
||||
<module name="zhn-system" target="1.8" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
<component name="JavacSettings">
|
||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||
<module name="xsnb-auth" options="-parameters" />
|
||||
<module name="xsnb-common" options="-parameters" />
|
||||
<module name="xsnb-gateway" options="-parameters" />
|
||||
<module name="xsnb-system" options="-parameters" />
|
||||
<module name="zhn-auth" options="-parameters" />
|
||||
<module name="zhn-common" options="-parameters" />
|
||||
<module name="zhn-gateway" options="-parameters" />
|
||||
<module name="zhn-system" options="-parameters" />
|
||||
</option>
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/zhn-auth/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/zhn-common/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/zhn-gateway/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/zhn-modules/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/zhn-modules/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/zhn-modules/zhn-system/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/xsnb-auth/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/xsnb-common/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/xsnb-gateway/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/xsnb-modules/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/xsnb-modules/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/xsnb-modules/xsnb-system/src/main/java" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
|
@ -8,6 +8,7 @@
|
|||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/xsnb-modules/zhn-system/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
#!/bin/bash
|
||||
echo "==============build begin 当前环境:【$ENV】=============="
|
||||
if [[ "$ENV" = "" ]]; then
|
||||
ENV=$env
|
||||
fi
|
||||
|
||||
if [[ $ENV == 'test' ]]; then
|
||||
HUB_USERNAME=wlf19941002
|
||||
HUB_PASSWORD=901002wei
|
||||
UCLOUD_HUB=registry.cn-hangzhou.aliyuncs.com/weilingfeng-dev
|
||||
elif [[ $ENV == 'prod' ]]; then
|
||||
HUB_USERNAME=wlf19941002
|
||||
HUB_PASSWORD=901002wei
|
||||
UCLOUD_HUB=registry.cn-hangzhou.aliyuncs.com/weilingfeng-prod
|
||||
else
|
||||
echo 'Please enter right environment! eg: test || prod(master or v/V*.*.* branch)'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#编译后将包拷贝至新建的publish目录下,gitlab上可以在对应节点下载包。
|
||||
mvn clean package -Dmaven.test.skip=true || exit 1 && \
|
||||
echo 'build successful!'
|
||||
|
||||
# 构建 TAG 变量
|
||||
TAG="${CI_COMMIT_SHA:0:4}${CI_PIPELINE_ID:0:4}"
|
||||
|
||||
# 打印 TAG 变量的值
|
||||
echo "TAG value: $TAG"
|
||||
|
||||
ZHN_AUTH=zhn-auth
|
||||
ZHN_GATEWAY=zhn-gateway
|
||||
ZHN_SYSTEM=zhn-system
|
||||
|
||||
#构建镜像
|
||||
docker build -f zhn-gateway/Dockerfile -t $UCLOUD_HUB/${ZHN_GATEWAY}:$TAG .
|
||||
docker build -f zhn-auth/Dockerfile -t $UCLOUD_HUB/${ZHN_AUTH}:$TAG .
|
||||
docker build -f zhn-modules/zhn-system/Dockerfile -t $UCLOUD_HUB/${ZHN_SYSTEM}:$TAG .
|
||||
#镜像仓库登录
|
||||
docker login registry.cn-hangzhou.aliyuncs.com --username $HUB_USERNAME --password $HUB_PASSWORD
|
||||
|
||||
#推送镜像
|
||||
docker push $UCLOUD_HUB/${ZHN_AUTH}:$TAG
|
||||
docker push $UCLOUD_HUB/${ZHN_GATEWAY}:$TAG
|
||||
docker push $UCLOUD_HUB/${ZHN_SYSTEM}:$TAG
|
||||
|
||||
#删除镜像
|
||||
docker rmi -f $UCLOUD_HUB/${ZHN_AUTH}:$TAG
|
||||
docker rmi -f $UCLOUD_HUB/${ZHN_GATEWAY}:$TAG
|
||||
docker push $UCLOUD_HUB/${ZHN_SYSTEM}:$TAG
|
||||
|
||||
#删除none 镜像
|
||||
docker image prune -f --filter "dangling=true"
|
||||
|
||||
echo "$UCLOUD_HUB/${ZHN_AUTH}:$TAG"
|
||||
echo "$UCLOUD_HUB/${ZHN_GATEWAY}:$TAG"
|
||||
echo "$UCLOUD_HUB/${ZHN_SYSTEM}:$TAG"
|
||||
echo "==============build end!!!================"
|
|
@ -1,47 +0,0 @@
|
|||
#!/bin/bash
|
||||
echo "==============deploy begin!!!================"
|
||||
|
||||
UCLOUD_HUB=registry.cn-hangzhou.aliyuncs.com/weilingfeng-dev
|
||||
UCLOUD_HUB=registry.cn-hangzhou.aliyuncs.com/weilingfeng-prod
|
||||
|
||||
TAG="${CI_COMMIT_SHA:0:4}${CI_PIPELINE_ID:0:4}"
|
||||
|
||||
ZHN_GATEWAY=zhn-gateway
|
||||
ZHN_AUTH=zhn-auth
|
||||
ZHN_SYSTEM=zhn-system
|
||||
|
||||
#停止
|
||||
if [ -n "$(docker ps -a -q -f name=$ZHN_GATEWAY)" ]; then
|
||||
docker rm -f $ZHN_GATEWAY
|
||||
echo "$ZHN_GATEWAY 已经停止"
|
||||
fi
|
||||
|
||||
if [ -n "$(docker ps -a -q -f name=$ZHN_AUTH)" ]; then
|
||||
docker rm -f $ZHN_AUTH
|
||||
echo "$ZHN_AUTH 已经停止"
|
||||
fi
|
||||
|
||||
if [ -n "$(docker ps -a -q -f name=$ZHN_SYSTEM)" ]; then
|
||||
docker rm -f $ZHN_SYSTEM
|
||||
echo "$ZHN_SYSTEM 已经停止"
|
||||
fi
|
||||
|
||||
#删除所有镜像
|
||||
docker images | grep "zhn-gateway" | awk '{print $3}' | while read image_id; do docker rmi -f "$image_id"; done
|
||||
docker images | grep "zhn-auth" | awk '{print $3}' | while read image_id; do docker rmi -f "$image_id"; done
|
||||
docker images | grep "zhn-system" | awk '{print $3}' | while read image_id; do docker rmi -f "$image_id"; done
|
||||
|
||||
|
||||
#拉取镜像
|
||||
docker pull $UCLOUD_HUB/${ZHN_AUTH}:$TAG || exit 1
|
||||
docker pull $UCLOUD_HUB/${ZHN_SYSTEM}:$TAG || exit 1
|
||||
docker pull $UCLOUD_HUB/${ZHN_GATEWAY}:$TAG || exit 1
|
||||
|
||||
#发布
|
||||
docker run -itd -p 8080:8080 --name=zhn-gateway --restart=always $UCLOUD_HUB/${ZHN_GATEWAY}:$TAG || exit 1
|
||||
docker run -itd -p 9200:9200 --name=zhn-auth --restart=always $UCLOUD_HUB/${ZHN_AUTH}:$TAG || exit 1
|
||||
docker run -itd -p 9201:9201 --name=zhn-system --restart=always $UCLOUD_HUB/${ZHN_SYSTEM}:$TAG || exit 1
|
||||
|
||||
echo "==============deploy success end!!!=================="
|
||||
|
||||
|
16
pom.xml
16
pom.xml
|
@ -4,15 +4,15 @@
|
|||
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>
|
||||
|
||||
<groupId>com.zhn</groupId>
|
||||
<artifactId>zhn-dev</artifactId>
|
||||
<groupId>com.xsnb</groupId>
|
||||
<artifactId>xsnb-dev</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0.0</version>
|
||||
<modules>
|
||||
<module>zhn-common</module>
|
||||
<module>zhn-gateway</module>
|
||||
<module>zhn-auth</module>
|
||||
<module>zhn-modules</module>
|
||||
<module>xsnb-common</module>
|
||||
<module>xsnb-gateway</module>
|
||||
<module>xsnb-auth</module>
|
||||
<module>xsnb-modules</module>
|
||||
</modules>
|
||||
|
||||
<!-- 规定SpringBoot版本 -->
|
||||
|
@ -50,8 +50,8 @@
|
|||
</dependency>
|
||||
<!-- common依赖(公共模块声明) -->
|
||||
<dependency>
|
||||
<groupId>com.zhn</groupId>
|
||||
<artifactId>zhn-common</artifactId>
|
||||
<groupId>com.xsnb</groupId>
|
||||
<artifactId>xsnb-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
|
|
|
@ -4,12 +4,12 @@ FROM openjdk:8-jre
|
|||
MAINTAINER ex_weilingfeng@163.com
|
||||
|
||||
# 挂载目录
|
||||
VOLUME /home/zhn
|
||||
VOLUME /home/xsnb
|
||||
# 创建目录
|
||||
RUN mkdir -p /home/zhn
|
||||
RUN mkdir -p /home/xsnb
|
||||
# 指定路径
|
||||
WORKDIR /home/zhn
|
||||
WORKDIR /home/xsnb
|
||||
# 复制jar文件到路径
|
||||
COPY zhn-auth/target/zhn-auth.jar /home/zhn/zhn-auth.jar
|
||||
COPY xsnb-auth/target/xsnb-auth.jar /home/xsnb/xsnb-auth.jar
|
||||
# 启动网关服务
|
||||
ENTRYPOINT ["java","-jar","zhn-auth.jar"]
|
||||
ENTRYPOINT ["java","-jar","xsnb-auth.jar"]
|
|
@ -3,19 +3,29 @@
|
|||
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>zhn-dev</artifactId>
|
||||
<groupId>com.zhn</groupId>
|
||||
<artifactId>xsnb-dev</artifactId>
|
||||
<groupId>com.xsnb</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>zhn-auth</artifactId>
|
||||
<artifactId>xsnb-auth</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 项目公共 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.zhn</groupId>
|
||||
<artifactId>zhn-common</artifactId>
|
||||
<groupId>com.xsnb</groupId>
|
||||
<artifactId>xsnb-common</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- SpringBoot Web-->
|
||||
<dependency>
|
|
@ -1,4 +1,5 @@
|
|||
package com.zhn.auth;
|
||||
package com.xsnb.auth;
|
||||
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
@ -7,8 +8,9 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
|||
/**
|
||||
* @author zhang
|
||||
*/
|
||||
@SpringBootApplication
|
||||
|
||||
@EnableFeignClients
|
||||
@SpringBootApplication
|
||||
public class AuthMian {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AuthMian.class, args);
|
|
@ -0,0 +1,53 @@
|
|||
package com.xsnb.auth.controller;
|
||||
|
||||
|
||||
import com.xsnb.auth.service.AuthService;
|
||||
import com.xsnb.common.domain.User;
|
||||
import com.xsnb.common.domain.request.RequestUser;
|
||||
import com.xsnb.common.domain.response.RespJwt;
|
||||
import com.xsnb.common.result.Result;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@RestController
|
||||
@Log4j2
|
||||
public class AuthController {
|
||||
@Autowired
|
||||
AuthService authService;
|
||||
|
||||
|
||||
|
||||
@PostMapping("/getPhoneCode")
|
||||
public Result getPhoneCode(@RequestBody User user ){
|
||||
log.info("获取的信息:{}",user.toString());
|
||||
return authService.getPhoneCode(user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 登录
|
||||
* @param requestUser
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
Result<RespJwt> login(@RequestBody RequestUser requestUser){
|
||||
|
||||
return authService.login(requestUser);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/user/info")
|
||||
Result<User> userinfo(HttpServletRequest request){
|
||||
return authService.userinfo(request);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,14 +1,15 @@
|
|||
package com.zhn.auth.feign;
|
||||
package com.xsnb.auth.feign;
|
||||
|
||||
|
||||
import com.zhn.common.domain.User;
|
||||
import com.zhn.common.result.Result;
|
||||
import com.xsnb.common.domain.User;
|
||||
import com.xsnb.common.result.Result;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
@FeignClient("zhn-system")
|
||||
@FeignClient("xsnb-system")
|
||||
public interface AuthFeignSystem {
|
||||
|
||||
@GetMapping("/user/byphone/{phone}")
|
||||
Result<User> byphone(@PathVariable String phone);
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.xsnb.auth.service;
|
||||
|
||||
import com.xsnb.common.domain.User;
|
||||
import com.xsnb.common.domain.request.RequestUser;
|
||||
import com.xsnb.common.domain.response.RespJwt;
|
||||
import com.xsnb.common.result.Result;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public interface AuthService {
|
||||
Result<RespJwt> login(RequestUser requestUser);
|
||||
|
||||
Result<User> userinfo(HttpServletRequest request);
|
||||
|
||||
Result getPhoneCode(User user);
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package com.xsnb.auth.service.impl;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xsnb.auth.feign.AuthFeignSystem;
|
||||
import com.xsnb.auth.service.AuthService;
|
||||
import com.xsnb.common.constants.JwtConstants;
|
||||
import com.xsnb.common.constants.RabbitMQConstants;
|
||||
import com.xsnb.common.constants.TokenConstants;
|
||||
import com.xsnb.common.domain.User;
|
||||
import com.xsnb.common.domain.request.RequestUser;
|
||||
import com.xsnb.common.domain.response.RespJwt;
|
||||
import com.xsnb.common.result.Result;
|
||||
import com.xsnb.common.utils.JwtUtils;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Service
|
||||
@Log4j2
|
||||
public class AuthServiceImpl implements AuthService {
|
||||
|
||||
@Autowired
|
||||
AuthFeignSystem authFeignSystem;
|
||||
|
||||
@Autowired
|
||||
RedisTemplate<String, String> redisTemplate;
|
||||
@Autowired
|
||||
RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
public Result<RespJwt> login(RequestUser requestUser) {
|
||||
String phone = requestUser.getPhone();
|
||||
String captcha = requestUser.getCaptcha();
|
||||
if (null == phone || null == captcha) {
|
||||
return Result.error("联系管理员");
|
||||
}
|
||||
if ("".equals(phone) || "".equals(captcha)) {
|
||||
|
||||
return Result.error("请输入手机号+密码");
|
||||
}
|
||||
Result<User> byphone = authFeignSystem.byphone(phone);
|
||||
User data = byphone.getData();
|
||||
if (null == data) {
|
||||
return Result.error("先注册手机号,在登录");
|
||||
}
|
||||
//从redsi拿验证码进行比对
|
||||
//判断名字为"PHONE_"+phone的key是否存在
|
||||
String s = redisTemplate.opsForValue().get(phone);
|
||||
log.info("拿到的:{}",s);
|
||||
if (null == s || !s.equals(captcha)) {
|
||||
return Result.error("验证码错误");
|
||||
}
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
String userkey = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
map.put(JwtConstants.USER_KEY, userkey);
|
||||
map.put(JwtConstants.DETAILS_USER_ID, data.getId());
|
||||
String token = JwtUtils.createToken(map);
|
||||
redisTemplate.opsForValue().set(
|
||||
TokenConstants.LOGIN_TOKEN_KEY + userkey,
|
||||
JSONObject.toJSONString(data),
|
||||
TokenConstants.EXPIRATION,
|
||||
TimeUnit.MINUTES
|
||||
);
|
||||
RespJwt respJwt = new RespJwt();
|
||||
respJwt.setToken(token);
|
||||
respJwt.setEidTime("720MIN");
|
||||
log.info("登录成功,token:{}", token);
|
||||
return Result.success(respJwt);
|
||||
}
|
||||
|
||||
/*
|
||||
* 前台每次请求都会来到这里进行解析user
|
||||
*
|
||||
* */
|
||||
@Override
|
||||
public Result<User> userinfo(HttpServletRequest request) {
|
||||
String token = request.getHeader(TokenConstants.TOKEN);
|
||||
String userKey = JwtUtils.getUserKey(token);
|
||||
String s = redisTemplate.opsForValue().get(TokenConstants.LOGIN_TOKEN_KEY + userKey);
|
||||
User user = JSONObject.parseObject(s, User.class);
|
||||
/*获取用户信息*/
|
||||
log.info("userInfo获取的用户信息是:{}", user);
|
||||
return Result.success(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param user
|
||||
* @return
|
||||
* @dis 短信发送
|
||||
*/
|
||||
@Override
|
||||
public Result getPhoneCode(User user) {
|
||||
String phone = user.getPhone() == null ? "18906604007" : user.getPhone();
|
||||
|
||||
log.info("短信发送的手机号 :{}", phone);
|
||||
Result<User> byphone = authFeignSystem.byphone(phone);
|
||||
User data = byphone.getData();
|
||||
if (null == data) {
|
||||
return Result.error("先注册手机号,在登录");
|
||||
}
|
||||
Pattern compile = Pattern.compile("^(?:(?:\\+|00)86)?1\\d{10}$");
|
||||
if (!compile.matcher(phone).matches()) {
|
||||
return Result.error("手机号格式错误");
|
||||
}
|
||||
rabbitTemplate.convertAndSend(RabbitMQConstants.SEND_SMS_QUEUs, phone, message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
log.info("rabbit异步发送完毕 :{}", phone);
|
||||
return message;
|
||||
});
|
||||
|
||||
return Result.success("开始发送短信");
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,7 @@ spring:
|
|||
time-zone: GMT+8
|
||||
application:
|
||||
# 应用名称
|
||||
name: zhn-auth
|
||||
name: xsnb-auth
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
|
@ -20,10 +20,10 @@ spring:
|
|||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 192.168.2.51:8848
|
||||
server-addr: 127.0.0.1:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 192.168.2.51:8848
|
||||
server-addr: 127.0.0.1:8848
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.zhn.auth.mapper.AuthMapper">
|
||||
<mapper namespace="com.xsnb.auth.mapper.AuthMapper">
|
||||
<!--namespace根据自己需要创建的的mapper的路径和名称填写-->
|
||||
|
||||
|
|
@ -3,13 +3,13 @@
|
|||
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>zhn-dev</artifactId>
|
||||
<groupId>com.zhn</groupId>
|
||||
<artifactId>xsnb-dev</artifactId>
|
||||
<groupId>com.xsnb</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>zhn-common</artifactId>
|
||||
<artifactId>xsnb-common</artifactId>
|
||||
<dependencies>
|
||||
<!-- bootstrap 启动器 -->
|
||||
<dependency>
|
||||
|
@ -58,6 +58,16 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<!--rabbitMQ-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
<!--邮箱-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>
|
||||
<!-- Hibernate Validator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -91,6 +101,19 @@
|
|||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.12.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- mybatis Plus 插件-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus</artifactId>
|
||||
<version>3.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.3.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -1,8 +1,8 @@
|
|||
package com.zhn.common.constants;
|
||||
package com.xsnb.common.constants;
|
||||
|
||||
/**
|
||||
* @description: 系统常量
|
||||
* @author zhn
|
||||
* @author xsnb
|
||||
*/
|
||||
public class Constants {
|
||||
/**
|
|
@ -1,7 +1,7 @@
|
|||
package com.zhn.common.constants;
|
||||
package com.xsnb.common.constants;
|
||||
|
||||
/**
|
||||
* @author zhn
|
||||
* @author xsnb
|
||||
* @description: Jwt常量
|
||||
*/
|
||||
public class JwtConstants {
|
|
@ -0,0 +1,11 @@
|
|||
package com.xsnb.common.constants;
|
||||
|
||||
/**
|
||||
* @BelongsProject: Bob_Up_Like_A_Cork
|
||||
* @BelongsPackage: com.zhn.common.constants
|
||||
* @Author: zhangquan
|
||||
* @CreateTime: 2023/8/1 20:11
|
||||
*/
|
||||
public class RabbitMQConstants {
|
||||
public static final String SEND_SMS_QUEUs = "send_sms_queun";
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package com.zhn.common.constants;
|
||||
package com.xsnb.common.constants;
|
||||
|
||||
/**
|
||||
* @author zhn
|
||||
* @author xsnb
|
||||
* @description: 令牌常量
|
||||
*/
|
||||
public class TokenConstants {
|
|
@ -0,0 +1,22 @@
|
|||
package com.xsnb.common.domain;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class User {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String phone;
|
||||
private String email;
|
||||
private String wx_uid;
|
||||
private String user_name;
|
||||
private String user_pass;
|
||||
private String avatar;
|
||||
private Date lastLoginTime;
|
||||
private String balance;
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.zhn.common.domain.request;
|
||||
package com.xsnb.common.domain.request;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
@ -14,6 +14,8 @@ public class RequestUser {
|
|||
private String emil;
|
||||
private String lastLoginTime;
|
||||
private String balance;
|
||||
private String captcha;
|
||||
private String loginRadio;
|
||||
|
||||
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
package com.zhn.common.domain.response;
|
||||
package com.xsnb.common.domain.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @ClassName:RespJwt
|
||||
* @author:zhn
|
||||
* @author:xsnb
|
||||
* @create: 2023-08-03 09:01
|
||||
* @Description: 用户登录token返回实体类
|
||||
*/
|
|
@ -1,4 +1,4 @@
|
|||
package com.zhn.common.domain.response;
|
||||
package com.xsnb.common.domain.response;
|
||||
|
||||
|
||||
import lombok.Data;
|
|
@ -1,4 +1,4 @@
|
|||
package com.zhn.common.result;
|
||||
package com.xsnb.common.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -6,7 +6,7 @@ import java.io.Serializable;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhn
|
||||
* @author xsnb
|
||||
* @description: 列表返回结果集
|
||||
*/
|
||||
@Data
|
|
@ -1,12 +1,12 @@
|
|||
package com.zhn.common.result;
|
||||
package com.xsnb.common.result;
|
||||
|
||||
import com.zhn.common.constants.Constants;
|
||||
import com.xsnb.common.constants.Constants;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author zhn
|
||||
* @author xsnb
|
||||
* @description: 响应信息主体
|
||||
*/
|
||||
@Data
|
|
@ -1,6 +1,6 @@
|
|||
package com.zhn.common.utils;
|
||||
package com.xsnb.common.utils;
|
||||
|
||||
import com.zhn.common.constants.JwtConstants;
|
||||
import com.xsnb.common.constants.JwtConstants;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
|
@ -9,7 +9,7 @@ import java.util.Map;
|
|||
|
||||
/**
|
||||
* @description: Jwt工具类
|
||||
* @author zhn
|
||||
* @author xsnb
|
||||
*/
|
||||
public class JwtUtils {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.zhn.common.utils.Msg;
|
||||
package com.xsnb.common.utils.Msg;
|
||||
|
||||
import com.zhn.common.utils.StringUtils;
|
||||
import com.xsnb.common.utils.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.HttpClient;
|
|
@ -1,4 +1,4 @@
|
|||
package com.zhn.common.utils.Msg;
|
||||
package com.xsnb.common.utils.Msg;
|
||||
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.zhn.common.utils;
|
||||
package com.xsnb.common.utils;
|
||||
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
|
@ -1,4 +1,4 @@
|
|||
package com.zhn.common.utils;
|
||||
package com.xsnb.common.utils;
|
||||
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
|
@ -6,7 +6,7 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhn
|
||||
* @author xsnb
|
||||
* @description: 字符串处理工具类
|
||||
*/
|
||||
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|
@ -1,4 +1,4 @@
|
|||
package com.zhn.common.utils;
|
||||
package com.xsnb.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.dysmsapi20170525.Client;
|
||||
|
@ -18,8 +18,9 @@ public class TelSmsUtils {
|
|||
/**
|
||||
* 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限
|
||||
*/
|
||||
private static String accessKeyId = "LTAIEVXszCmcd1T5";
|
||||
private static String accessKeySecret = "2zHwciQXln8wExSEnkIYtRTSwLeRNd";
|
||||
private static String accessKeyId = "LTAI5tHLTV3mgTwB4wzxvkLS";
|
||||
private static String accessKeySecret = "jjQt8WSFzSDTvp1TMhRFS8FSyueaQU";
|
||||
private static String templateCode = "SMS_154950909";
|
||||
|
||||
/**
|
||||
* 短信访问域名
|
||||
|
@ -28,7 +29,7 @@ public class TelSmsUtils {
|
|||
/**
|
||||
* 短信签名
|
||||
*/
|
||||
private static String signName = "登录验证";
|
||||
private static String signName = "阿里云短信测试";
|
||||
|
||||
/**
|
||||
* 实例化短信对象
|
||||
|
@ -40,22 +41,22 @@ public class TelSmsUtils {
|
|||
long startTime = System.currentTimeMillis();
|
||||
try {
|
||||
client = initClient();
|
||||
log.info("初始化短信成功:{}",signName);
|
||||
log.info("初始化短信成功:{}", signName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
log.info("初始化短信服务结束:耗时:{}MS",(System.currentTimeMillis()-startTime));
|
||||
log.info("初始化短信服务结束:耗时:{}MS", (System.currentTimeMillis() - startTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化短信对象
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static Client initClient() throws Exception{
|
||||
private static Client initClient() throws Exception {
|
||||
Config config = new Config()
|
||||
// 您的AccessKey ID
|
||||
.setAccessKeyId(accessKeyId)
|
||||
// 您的AccessKey Secret
|
||||
.setAccessKeySecret(accessKeySecret);
|
||||
// 访问的域名
|
||||
config.endpoint = endpoint;
|
||||
|
@ -64,11 +65,11 @@ public class TelSmsUtils {
|
|||
|
||||
/**
|
||||
* 发送单条短信
|
||||
*
|
||||
* @param tel
|
||||
* @param templateCode SMS_153991546
|
||||
* @param sendDataMap
|
||||
*/
|
||||
public static String sendSms(String tel , String templateCode , Map<String, String> sendDataMap){
|
||||
public static String sendSms(String tel, Map<String, String> sendDataMap) {
|
||||
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
||||
.setPhoneNumbers(tel)
|
||||
.setSignName(signName)
|
|
@ -0,0 +1,77 @@
|
|||
package com.xsnb.common.utils.mqUtile;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.DirectExchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class DLXQueue {
|
||||
// routingKey
|
||||
private static final String DEAD_ROUTING_KEY = "dead.routingkey";
|
||||
private static final String ROUTING_KEY = "routingkey";
|
||||
private static final String DEAD_EXCHANGE = "dead.exchange";
|
||||
private static final String EXCHANGE = "common.exchange";
|
||||
@Autowired
|
||||
RabbitTemplate rabbitTemplate;
|
||||
@Resource
|
||||
RabbitAdmin rabbitAdmin;
|
||||
|
||||
/**
|
||||
* 发送死信队列,过期后进入死信交换机,进入死信队列
|
||||
*
|
||||
* @param queueName 队列名称
|
||||
* @param deadQueueName 死信队列名称
|
||||
* @param params 消息内容
|
||||
* @param expiration 过期时间 毫秒
|
||||
*/
|
||||
public void sendDLXQueue(String queueName, String deadQueueName, Object params, Integer expiration) {
|
||||
/**
|
||||
* ----------------------------------先创建一个ttl队列和死信队列--------------------------------------------
|
||||
*/
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
// 队列设置存活时间,单位ms, 必须是整形数据。
|
||||
map.put("x-message-ttl", expiration);
|
||||
// 设置死信交换机
|
||||
map.put("x-dead-letter-exchange", DEAD_EXCHANGE);
|
||||
// 设置死信交换器路由
|
||||
map.put("x-dead-letter-routing-key", DEAD_ROUTING_KEY);
|
||||
/*参数1:队列名称 参数2:持久化 参数3:是否排他 参数4:自动删除队列 参数5:队列参数*/
|
||||
Queue queue = new Queue(queueName, true, false, false, map);
|
||||
rabbitAdmin.declareQueue(queue);
|
||||
/**
|
||||
* ---------------------------------创建交换机---------------------------------------------
|
||||
*/
|
||||
DirectExchange directExchange = new DirectExchange(EXCHANGE, true, false);
|
||||
rabbitAdmin.declareExchange(directExchange);
|
||||
/**
|
||||
* ---------------------------------队列绑定交换机---------------------------------------------
|
||||
*/
|
||||
Binding binding = BindingBuilder.bind(queue).to(directExchange).with(ROUTING_KEY);
|
||||
rabbitAdmin.declareBinding(binding);
|
||||
/**
|
||||
* ---------------------------------在创建一个死信交换机和队列,接收死信队列---------------------------------------------
|
||||
*/
|
||||
DirectExchange deadExchange = new DirectExchange(DEAD_EXCHANGE, true, false);
|
||||
rabbitAdmin.declareExchange(deadExchange);
|
||||
|
||||
Queue deadQueue = new Queue(deadQueueName, true, false, false);
|
||||
rabbitAdmin.declareQueue(deadQueue);
|
||||
/**
|
||||
* ---------------------------------队列绑定死信交换机---------------------------------------------
|
||||
*/
|
||||
// 将队列和交换机绑定
|
||||
Binding deadbinding = BindingBuilder.bind(deadQueue).to(deadExchange).with(DEAD_ROUTING_KEY);
|
||||
rabbitAdmin.declareBinding(deadbinding);
|
||||
// 发送消息
|
||||
rabbitTemplate.convertAndSend(EXCHANGE, ROUTING_KEY, params);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package com.xsnb.common.utils.mqUtile;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.CustomExchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 发送延迟队列的工具类
|
||||
*/
|
||||
@Component
|
||||
public class DelayedQueue {
|
||||
|
||||
// routingKey
|
||||
private static final String DELAYED_ROUTING_KEY = "delayed.routingkey";
|
||||
|
||||
// 延迟队列交换机
|
||||
private static final String DELAYED_EXCHANGE = "delayed.exchange";
|
||||
|
||||
@Autowired
|
||||
RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Resource
|
||||
RabbitAdmin rabbitAdmin;
|
||||
|
||||
/**
|
||||
* 发送延迟队列
|
||||
*
|
||||
* @param queueName 队列名称
|
||||
* @param params 消息内容
|
||||
* @param expiration 延迟时间 毫秒
|
||||
*/
|
||||
public void sendDelayedQueue(String queueName, Object params, Integer expiration) {
|
||||
// 先创建一个队列
|
||||
Queue queue = new Queue(queueName);
|
||||
rabbitAdmin.declareQueue(queue);
|
||||
|
||||
// 创建延迟队列交换机
|
||||
CustomExchange customExchange = createCustomExchange();
|
||||
rabbitAdmin.declareExchange(customExchange);
|
||||
|
||||
// 将队列和交换机绑定
|
||||
Binding binding = BindingBuilder.bind(queue).to(customExchange).with(DELAYED_ROUTING_KEY).noargs();
|
||||
rabbitAdmin.declareBinding(binding);
|
||||
|
||||
// 发送延迟消息
|
||||
rabbitTemplate.convertAndSend(DELAYED_EXCHANGE, DELAYED_ROUTING_KEY, params, msg -> {
|
||||
// 发送消息的时候 延迟时长
|
||||
msg.getMessageProperties().setMessageId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
msg.getMessageProperties().setDelay(expiration);
|
||||
return msg;
|
||||
});
|
||||
}
|
||||
|
||||
private CustomExchange createCustomExchange() {
|
||||
Map<String, Object> arguments = new HashMap<>();
|
||||
/**
|
||||
* 参数说明:
|
||||
* 1.交换机的名称
|
||||
* 2.交换机的类型
|
||||
* 3.是否需要持久化
|
||||
* 4.是否自动删除
|
||||
* 5.其它参数
|
||||
*/
|
||||
arguments.put("x-delayed-type", "direct");
|
||||
return new CustomExchange(DELAYED_EXCHANGE, "x-delayed-message", true, false, arguments);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.xsnb.common.utils.mqUtile;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RabbitMQ {
|
||||
public static final String SEND_CODE_QUEUE = "send_code_queue";
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.xsnb.common.utils.mqUtile;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.DirectExchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 发送TTL队列 设置 消息的存活时间 如果超过了存活时间
|
||||
* 该条消息还没有被消费 则自动从队列中消息 ,如果配置了死信队列则消息会进入死信队列
|
||||
*/
|
||||
@Component
|
||||
public class TtlQueue {
|
||||
// routingKey
|
||||
private static final String TTL_KEY = "ttl.routingkey";
|
||||
private static final String TTL_EXCHANGE = "ttl.exchange";
|
||||
|
||||
@Autowired
|
||||
RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Resource
|
||||
RabbitAdmin rabbitAdmin;
|
||||
|
||||
/**
|
||||
* 发送TTL队列
|
||||
*
|
||||
* @param queueName 队列名称
|
||||
* @param params 消息内容
|
||||
* @param expiration 过期时间 毫秒
|
||||
*/
|
||||
public void sendTtlQueue(String queueName, Object params, Integer expiration) {
|
||||
/**
|
||||
* ----------------------------------先创建一个ttl队列--------------------------------------------
|
||||
*/
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
// 队列设置存活时间,单位ms,必须是整形数据。
|
||||
map.put("x-message-ttl", expiration);
|
||||
/*参数1:队列名称 参数2:持久化 参数3:是否排他 参数4:自动删除队列 参数5:队列参数*/
|
||||
Queue queue = new Queue(queueName, true, false, false, map);
|
||||
rabbitAdmin.declareQueue(queue);
|
||||
|
||||
/**
|
||||
* ---------------------------------创建交换机---------------------------------------------
|
||||
*/
|
||||
DirectExchange directExchange = new DirectExchange(TTL_EXCHANGE, true, false);
|
||||
rabbitAdmin.declareExchange(directExchange);
|
||||
/**
|
||||
* ---------------------------------队列绑定交换机---------------------------------------------
|
||||
*/
|
||||
// 将队列和交换机绑定
|
||||
Binding binding = BindingBuilder.bind(queue).to(directExchange).with(TTL_KEY);
|
||||
rabbitAdmin.declareBinding(binding);
|
||||
|
||||
// 发送消息
|
||||
rabbitTemplate.convertAndSend(TTL_EXCHANGE, TTL_KEY, params);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
# 基础镜像
|
||||
FROM openjdk:8-jre
|
||||
# author
|
||||
MAINTAINER ex_weilingfeng@163.com
|
||||
|
||||
# 挂载目录
|
||||
VOLUME /home/xsnb
|
||||
# 创建目录
|
||||
RUN mkdir -p /home/xsnb
|
||||
# 指定路径
|
||||
WORKDIR /home/xsnb
|
||||
# 复制jar文件到路径
|
||||
COPY xsnb-gateway/target/xsnb-gateway.jar /home/xsnb/xsnb-gateway.jar
|
||||
# 启动网关服务
|
||||
ENTRYPOINT ["java","-jar","xsnb-gateway.jar"]
|
|
@ -3,19 +3,29 @@
|
|||
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>zhn-dev</artifactId>
|
||||
<groupId>com.zhn</groupId>
|
||||
<artifactId>xsnb-dev</artifactId>
|
||||
<groupId>com.xsnb</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>zhn-gateway</artifactId>
|
||||
<artifactId>xsnb-gateway</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 公共模块 -->
|
||||
<dependency>
|
||||
<groupId>com.zhn</groupId>
|
||||
<artifactId>zhn-common</artifactId>
|
||||
<groupId>com.xsnb</groupId>
|
||||
<artifactId>xsnb-common</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- 网关依赖 -->
|
||||
<!-- SpringCloud Gateway -->
|
|
@ -1,4 +1,5 @@
|
|||
package com.zhn.gateway;
|
||||
package com.xsnb.gateway;
|
||||
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
@ -6,6 +7,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
/**
|
||||
* @author zhang
|
||||
*/
|
||||
|
||||
@SpringBootApplication
|
||||
public class GatewayMian {
|
||||
public static void main(String[] args) {
|
|
@ -1,4 +1,4 @@
|
|||
package com.zhn.gateway.config;
|
||||
package com.xsnb.gateway.config;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* @description: 放行白名单配置
|
||||
* @author zhn
|
||||
* @author xsnb
|
||||
*/
|
||||
@Configuration
|
||||
@RefreshScope
|
|
@ -0,0 +1,4 @@
|
|||
package com.xsnb.gateway.constants;
|
||||
|
||||
public class Constants {
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
package com.zhn.gateway.filters;
|
||||
package com.xsnb.gateway.filters;
|
||||
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zhn.common.constants.TokenConstants;
|
||||
import com.zhn.common.domain.User;
|
||||
import com.zhn.common.utils.JwtUtils;
|
||||
import com.zhn.common.utils.StringUtils;
|
||||
import com.zhn.gateway.config.IgnoreWhiteConfig;
|
||||
import com.zhn.gateway.utils.GatewayUtils;
|
||||
import com.xsnb.common.constants.TokenConstants;
|
||||
import com.xsnb.common.domain.User;
|
||||
import com.xsnb.common.utils.JwtUtils;
|
||||
import com.xsnb.common.utils.StringUtils;
|
||||
import com.xsnb.gateway.config.IgnoreWhiteConfig;
|
||||
import com.xsnb.gateway.utils.GatewayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
|
@ -56,6 +56,7 @@ public class AuthFilters implements GlobalFilter, Ordered {
|
|||
}
|
||||
String jsonStr = redisTemplate.opsForValue().get(TokenConstants.LOGIN_TOKEN_KEY + userKey);
|
||||
User user = JSONObject.parseObject(jsonStr, User.class);
|
||||
user.setLastLoginTime(new Date());
|
||||
Date lastLoginTime = user.getLastLoginTime();
|
||||
long between = DateUtil.between(lastLoginTime, new Date(), DateUnit.MINUTE);
|
||||
if (between >= 10) {
|
|
@ -1,8 +1,8 @@
|
|||
package com.zhn.gateway.utils;
|
||||
package com.xsnb.gateway.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zhn.common.result.Result;
|
||||
import com.zhn.common.utils.StringUtils;
|
||||
import com.xsnb.common.result.Result;
|
||||
import com.xsnb.common.utils.StringUtils;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
@ -13,7 +13,7 @@ import org.springframework.web.server.ServerWebExchange;
|
|||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author zhn
|
||||
* @author xsnb
|
||||
* @description: 网关处理工具类
|
||||
*/
|
||||
@Log4j2
|
|
@ -5,7 +5,7 @@ server:
|
|||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: zhn-gateway
|
||||
name: xsnb-gateway
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
|
@ -18,10 +18,10 @@ spring:
|
|||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 192.168.2.51:8848
|
||||
server-addr: 127.0.0.1:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 192.168.2.51:8848
|
||||
server-addr: 127.0.0.1:8848
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
|
@ -3,16 +3,16 @@
|
|||
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>zhn-dev</artifactId>
|
||||
<groupId>com.zhn</groupId>
|
||||
<artifactId>xsnb-dev</artifactId>
|
||||
<groupId>com.xsnb</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>zhn-modules</artifactId>
|
||||
<artifactId>xsnb-modules</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>zhn-system</module>
|
||||
<module>xsnb-system</module>
|
||||
</modules>
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
# 基础镜像
|
||||
FROM openjdk:8-jre
|
||||
# author
|
||||
MAINTAINER ex_weilingfeng
|
||||
|
||||
# 挂载目录
|
||||
VOLUME /home/xsnb
|
||||
# 创建目录
|
||||
RUN mkdir -p /home/xsnb
|
||||
# 指定路径
|
||||
WORKDIR /home/xsnb
|
||||
# 复制jar文件到路径
|
||||
COPY xsnb-modules/xsnb-system/target/xsnb-modules-system.jar /home/xsnb/xsnb-modules-system.jar
|
||||
# 启动系统服务
|
||||
ENTRYPOINT ["java","-jar","xsnb-modules-system.jar"]
|
|
@ -3,19 +3,19 @@
|
|||
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>zhn-modules</artifactId>
|
||||
<groupId>com.zhn</groupId>
|
||||
<artifactId>xsnb-modules</artifactId>
|
||||
<groupId>com.xsnb</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>zhn-system</artifactId>
|
||||
<artifactId>xsnb-system</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 系统公共 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.zhn</groupId>
|
||||
<artifactId>zhn-common</artifactId>
|
||||
<groupId>com.xsnb</groupId>
|
||||
<artifactId>xsnb-common</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringBoot Web-->
|
||||
<dependency>
|
||||
|
@ -77,6 +77,18 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
<version>8.5.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.10.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
<build>
|
|
@ -1,5 +1,6 @@
|
|||
package com.zhn.system;
|
||||
package com.xsnb.system;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
@ -8,6 +9,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||
@SpringBootApplication
|
||||
@EnableFeignClients
|
||||
@EnableScheduling
|
||||
@MapperScan("com.xsnb.**.mapper")
|
||||
public class SystemMian {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SystemMian.class, args);
|
|
@ -0,0 +1,48 @@
|
|||
package com.xsnb.system.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* FileName: MailSender
|
||||
* Author: 张海宁
|
||||
* Date: 2024/3/4 14:41
|
||||
* Description:
|
||||
* History:
|
||||
* <author> <time> <version> <desc>
|
||||
* 作者姓名 修改时间 版本号 描述
|
||||
*/
|
||||
@Configuration
|
||||
public class MailSender {
|
||||
@Value("${spring.mail.username}")
|
||||
private String username;
|
||||
|
||||
@Value("${spring.mail.password}")
|
||||
private String password;
|
||||
|
||||
@Value("${spring.mail.host}")
|
||||
private String host;
|
||||
|
||||
@Value("${spring.mail.port}")
|
||||
private int port;
|
||||
|
||||
@Bean
|
||||
public JavaMailSender javaMailSender() {
|
||||
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
||||
mailSender.setHost(host);
|
||||
mailSender.setPort(port);
|
||||
mailSender.setUsername(username);
|
||||
mailSender.setPassword(password);
|
||||
|
||||
Properties props = mailSender.getJavaMailProperties();
|
||||
props.put("mail.smtp.auth", "true");
|
||||
props.put("mail.smtp.starttls.enable", "true");
|
||||
|
||||
return mailSender;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.xsnb.system.controller;
|
||||
|
||||
import com.xsnb.common.domain.User;
|
||||
import com.xsnb.common.result.Result;
|
||||
import com.xsnb.system.domain.Mail;
|
||||
import com.xsnb.system.service.MailService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* FileName: DomeController
|
||||
* Author: 张海宁
|
||||
* Date: 2024/3/4 14:07
|
||||
* Description:测试广场
|
||||
* History:
|
||||
* <author> <time> <version> <desc>
|
||||
* 作者姓名 修改时间 版本号 描述
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
public class DomeController {
|
||||
|
||||
|
||||
@Autowired
|
||||
MailService mailService;
|
||||
|
||||
|
||||
//获取邮件列表
|
||||
@PostMapping("/allListMail")
|
||||
public Result<List<Mail>> allListMail(User user){
|
||||
return mailService.allListMail(user);
|
||||
}
|
||||
//删除邮件,通过传来的邮箱id来删除邮件
|
||||
@PostMapping("/deleteMail")
|
||||
public Result<Mail> deleteMail(Mail mail){
|
||||
return mailService.deleteMail(mail);
|
||||
}
|
||||
//添加邮件,通过邮箱实体类来创建邮箱,也就是邮箱发送
|
||||
@PostMapping("/addMail")
|
||||
public Result<Mail> addMail(Mail mail){
|
||||
return mailService.addMail(mail);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.xsnb.system.controller;
|
||||
|
||||
|
||||
import com.xsnb.common.domain.User;
|
||||
import com.xsnb.common.result.Result;
|
||||
import com.xsnb.system.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
|
||||
|
||||
@GetMapping("/byphone/{phone}")
|
||||
Result<User> byphone(@PathVariable String phone){
|
||||
|
||||
return userService.byphone(phone);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.xsnb.system.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* FileName: Attachment
|
||||
* Author: 张海宁
|
||||
* Date: 2024/3/4 13:57
|
||||
* Description:邮箱抽象类
|
||||
* History:
|
||||
* <author> <time> <version> <desc>
|
||||
* 作者姓名 修改时间 版本号 描述
|
||||
*/
|
||||
@Data
|
||||
public class Attachment {
|
||||
/** 文件名称 */
|
||||
public String fileName;
|
||||
/** 文件路径 */
|
||||
public String filePath;
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.xsnb.system.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
@TableName("email")
|
||||
public class Mail {
|
||||
|
||||
private int id;
|
||||
private String title;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date sendTime;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date readTime;
|
||||
private String content;
|
||||
private int attachmentId;
|
||||
private String emailStatus;
|
||||
private int userId;
|
||||
private int recipientId;
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.xsnb.system.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* FileName: MinioReturn
|
||||
* Author: 张海宁
|
||||
* Date: 2024/3/1 10:30
|
||||
* Description:
|
||||
* History:
|
||||
* <author> <time> <version> <desc>
|
||||
* 作者姓名 修改时间 版本号 描述
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MinioReturn {
|
||||
|
||||
/**
|
||||
* 文件地址
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 原始文件名
|
||||
*/
|
||||
private String inputName;
|
||||
|
||||
/**
|
||||
* 最终文件名
|
||||
*/
|
||||
private String outPutName;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.xsnb.system.domain.req;
|
||||
|
||||
import com.xsnb.system.domain.Attachment;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* FileName: ReqMail
|
||||
* Author: 张海宁
|
||||
* Date: 2024/3/4 14:16
|
||||
* Description:
|
||||
* History:
|
||||
* <author> <time> <version> <desc>
|
||||
* 作者姓名 修改时间 版本号 描述
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ReqMail {
|
||||
private String from;
|
||||
private String to;
|
||||
private File mailFile;
|
||||
private String subject;
|
||||
private String content;
|
||||
private Attachment attachment;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.xsnb.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xsnb.system.domain.Mail;
|
||||
|
||||
public interface MailMapper extends BaseMapper<Mail> {
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.xsnb.system.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xsnb.common.domain.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.xsnb.system.rabbitMQ;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsResponseBody;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.xsnb.common.constants.RabbitMQConstants;
|
||||
import com.xsnb.common.utils.TelSmsUtils;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
public class MessageConsumerService {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String,String> redisTemplate;
|
||||
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue(RabbitMQConstants.SEND_SMS_QUEUs)})
|
||||
public void SmsController(String phone, Message message, Channel channel){
|
||||
long s = System.currentTimeMillis();
|
||||
String messageId = message.getMessageProperties().getMessageId();
|
||||
log.info("短信消费队列开始消费 消息内容:{},开始执行",phone);
|
||||
try {
|
||||
Long count = redisTemplate.opsForSet().add(RabbitMQConstants.SEND_SMS_QUEUs, messageId);
|
||||
if(count==1){
|
||||
String code = RandomUtil.randomNumbers(4);
|
||||
String jsons = TelSmsUtils.sendSms(phone, new HashMap<String, String>() {{
|
||||
put("code",code);
|
||||
}});
|
||||
SendSmsResponseBody sendSmsResponseBody = JSONObject.parseObject(jsons, SendSmsResponseBody.class);
|
||||
if(!"OK".equals(sendSmsResponseBody.getCode())){
|
||||
TelSmsUtils.sendSms(phone,new HashMap<String, String>(){{
|
||||
put("code",code);
|
||||
}});
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
|
||||
redisTemplate.opsForValue().set(phone,JSONObject.toJSONString(code));
|
||||
log.info("短信消费队列消费成功 用户:{},耗时:{}",phone,System.currentTimeMillis()-s);
|
||||
}
|
||||
}else {
|
||||
log.info("短信重复消费 内容:{}",phone);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("消息队列消费失败 异常信息 用户:{}, 内容:{}",phone,e.getMessage());
|
||||
try {
|
||||
channel.basicReject(message.getMessageProperties().getDeliveryTag(),true);
|
||||
} catch (Exception exception) {
|
||||
log.error("消息队列消费失败 回退信息 用户:{},内容:{}",phone,exception.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.xsnb.system.service;
|
||||
|
||||
import com.xsnb.common.domain.User;
|
||||
import com.xsnb.common.result.Result;
|
||||
import com.xsnb.system.domain.Mail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* FileName: MailService
|
||||
* Author: 张海宁
|
||||
* Date: 2024/3/4 14:18
|
||||
* Description:
|
||||
* History:
|
||||
* <author> <time> <version> <desc>
|
||||
* 作者姓名 修改时间 版本号 描述
|
||||
*/
|
||||
public interface MailService {
|
||||
|
||||
Result<List<Mail>> allListMail(User user);
|
||||
|
||||
Result<Mail> deleteMail(Mail mail);
|
||||
|
||||
Result<Mail> addMail(Mail mail);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.xsnb.system.service;
|
||||
|
||||
import com.xsnb.common.domain.User;
|
||||
import com.xsnb.common.result.Result;
|
||||
|
||||
public interface UserService {
|
||||
Result<User> byphone(String phone);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.xsnb.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.xsnb.common.domain.User;
|
||||
import com.xsnb.common.result.Result;
|
||||
import com.xsnb.system.domain.Mail;
|
||||
import com.xsnb.system.mapper.MailMapper;
|
||||
import com.xsnb.system.service.MailService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* FileName: MailServiceImpl
|
||||
* Author: 张海宁
|
||||
* Date: 2024/3/4 14:18
|
||||
* Description:
|
||||
* History:
|
||||
* <author> <time> <version> <desc>
|
||||
* 作者姓名 修改时间 版本号 描述
|
||||
*/
|
||||
@Service
|
||||
public class MailServiceImpl implements MailService {
|
||||
@Autowired
|
||||
MailMapper mapper;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result<List<Mail>> allListMail(User user) {
|
||||
QueryWrapper<Mail> qw = new QueryWrapper<>();
|
||||
qw.eq("user_id", user.getId());
|
||||
List<Mail> mailList = mapper.selectList(qw);
|
||||
return Result.success(mailList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mail
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result<Mail> deleteMail(Mail mail) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mail
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result<Mail> addMail(Mail mail) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.xsnb.system.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.xsnb.common.domain.User;
|
||||
import com.xsnb.common.result.Result;
|
||||
import com.xsnb.system.mapper.UserMapper;
|
||||
import com.xsnb.system.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
@Autowired
|
||||
UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public Result<User> byphone(String phone) {
|
||||
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("phone",phone);
|
||||
User user = userMapper.selectOne(queryWrapper);
|
||||
return Result.success(user);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package com.xsnb.system.utils;
|
||||
|
||||
import com.xsnb.system.domain.Attachment;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeUtility;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* FileName: EmailUtils
|
||||
* Author: 张海宁
|
||||
* Date: 2024/3/4 13:53
|
||||
* Description:邮箱工具类
|
||||
* History:
|
||||
* <author> <time> <version> <desc>
|
||||
* 作者姓名 修改时间 版本号 描述
|
||||
*/
|
||||
@Slf4j
|
||||
public class EmailUtils {
|
||||
|
||||
|
||||
public static Integer sendMailAttachment(JavaMailSender mailSender,
|
||||
String fromEmail,
|
||||
String toEmail,
|
||||
String subject,
|
||||
String content,
|
||||
Attachment attachment) {
|
||||
MimeMessage message = mailSender.createMimeMessage();
|
||||
Integer result = 1;
|
||||
try {
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
|
||||
helper.setFrom(fromEmail);
|
||||
helper.setTo(toEmail);
|
||||
helper.setSubject(subject);
|
||||
helper.setText(content, true);
|
||||
|
||||
if (attachment != null && attachment.getFileName() != null && attachment.getFilePath() != null) {
|
||||
File destinationFile = new File(attachment.getFilePath());
|
||||
FileSystemResource fileResource = new FileSystemResource(destinationFile);
|
||||
helper.addAttachment(destinationFile.getName(), fileResource);
|
||||
}
|
||||
|
||||
mailSender.send(message);
|
||||
log.info("邮件发送成功,收件人地址:" + toEmail);
|
||||
} catch (Exception e) {
|
||||
result = 0;
|
||||
log.error("邮件发送出现异常,收件人地址:" + toEmail, e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Integer sendMailAttachments(JavaMailSender mailSender, String fromEmail, String toEmail,
|
||||
String subject, String content, List<Attachment> attachments) {
|
||||
System.setProperty("mail.mime.splitlongparameters", "false");
|
||||
MimeMessage message = mailSender.createMimeMessage();
|
||||
try {
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
|
||||
helper.setFrom(fromEmail);
|
||||
helper.setTo(toEmail);
|
||||
helper.setSubject(subject);
|
||||
helper.setText(content, true);
|
||||
if (!ObjectUtils.isEmpty(attachments)) {
|
||||
attachments.forEach((attachment) -> {
|
||||
try {
|
||||
FileSystemResource file = new FileSystemResource(attachment.getFilePath());
|
||||
helper.addAttachment(MimeUtility.
|
||||
encodeWord(attachment.getFileName(),
|
||||
"UTF-8",
|
||||
"B"),
|
||||
file);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
mailSender.send(message);
|
||||
log.info("邮件发送成功,收件人地址:" + toEmail);
|
||||
return 1;
|
||||
} catch (Exception e) {
|
||||
log.error("邮件发送出现异常,收件人地址:" + toEmail, e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
server:
|
||||
port: 9002
|
||||
|
||||
spring:
|
||||
mail: # 邮件相关配置
|
||||
username: xingsnbadmin@xingsnb.cn # 你自己的QQ邮箱的用户名,需要填写你的QQ邮箱地址
|
||||
password: drjyrrmzqmjcbhdb # 你自己的QQ邮箱的密钥/密码,需要填写你的QQ邮箱登录密码
|
||||
host: smtp.qq.com # SMTP服务器主机名,这里设置为QQ邮箱的SMTP服务器
|
||||
port: 465 # SMTP服务器端口,通常情况下使用SSL的SMTP协议使用465端口
|
||||
protocol: smtp # 使用SMTP协议发送邮件
|
||||
properties: # 邮件相关的属性配置
|
||||
mail: # 邮件协议属性配置
|
||||
smtp: # SMTP协议属性配置
|
||||
ssl: # SSL/TLS属性配置
|
||||
enable: true # 启用SSL,表示使用加密传输邮件
|
||||
auth: true # 启用SMTP身份验证,需要提供用户名和密码
|
||||
starttls: # STARTTLS属性配置,用于在未加密连接上启用TLS
|
||||
enable: true # 启用STARTTLS
|
||||
required: true # 要求必须使用STARTTLS
|
||||
socketFactory: # Socket工厂属性配置,用于SSL连接
|
||||
port: 465 # SSL连接的端口,与SMTP服务器的端口一致
|
||||
class: javax.net.ssl.SSLSocketFactory # 使用的Socket工厂类,通常用于SSL连接
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
allow-circular-references: true
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
name: xsnb-system
|
||||
profiles:
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
config:
|
||||
server-addr: 127.0.0.1:8848
|
||||
file-extension: yml
|
||||
shared-configs:
|
||||
- "application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}"
|
||||
rabbitmq:
|
||||
host: 127.0.0.1
|
||||
port: 5672
|
||||
username: guest
|
||||
password: guest
|
||||
virtualHost: /
|
||||
listener:
|
||||
simple:
|
||||
prefetch: 1
|
|
@ -1,32 +0,0 @@
|
|||
package com.zhn.auth.controller;
|
||||
|
||||
|
||||
import com.zhn.auth.service.AuthService;
|
||||
import com.zhn.common.domain.User;
|
||||
import com.zhn.common.domain.request.RequestUser;
|
||||
import com.zhn.common.domain.response.RespJwt;
|
||||
import com.zhn.common.result.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@RestController
|
||||
public class AuthController {
|
||||
@Autowired
|
||||
AuthService authService;
|
||||
@PostMapping("/login")
|
||||
Result<RespJwt> login(@RequestBody RequestUser requestUser){
|
||||
|
||||
return authService.login(requestUser);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/user/info")
|
||||
Result<User> userinfo(HttpServletRequest request){
|
||||
return authService.userinfo(request);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package com.zhn.auth.service;
|
||||
|
||||
import com.zhn.common.domain.User;
|
||||
import com.zhn.common.domain.request.RequestUser;
|
||||
import com.zhn.common.domain.response.RespJwt;
|
||||
import com.zhn.common.result.Result;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public interface AuthService {
|
||||
Result<RespJwt> login(RequestUser requestUser);
|
||||
|
||||
Result<User> userinfo(HttpServletRequest request);
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
package com.zhn.auth.service.impl;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zhn.auth.feign.AuthFeignSystem;
|
||||
import com.zhn.auth.service.AuthService;
|
||||
import com.zhn.common.constants.JwtConstants;
|
||||
import com.zhn.common.constants.TokenConstants;
|
||||
import com.zhn.common.domain.User;
|
||||
import com.zhn.common.domain.request.RequestUser;
|
||||
import com.zhn.common.domain.response.RespJwt;
|
||||
import com.zhn.common.result.Result;
|
||||
import com.zhn.common.utils.JwtUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.TimeoutUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
import com.zhn.auth.service.AuthService;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class AuthServiceImpl implements AuthService {
|
||||
|
||||
@Autowired
|
||||
AuthFeignSystem authFeignSystem;
|
||||
|
||||
@Autowired
|
||||
RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
@Override
|
||||
public Result<RespJwt> login(RequestUser requestUser) {
|
||||
String phone = requestUser.getPhone();
|
||||
String password = requestUser.getPassword();
|
||||
if (null == phone || null == password) {
|
||||
return Result.error("联系管理员");
|
||||
}
|
||||
if ("".equals(phone) || "".equals(password)) {
|
||||
|
||||
return Result.error("请输入手机号+密码");
|
||||
}
|
||||
Result<User> byphone = authFeignSystem.byphone(phone);
|
||||
User data = byphone.getData();
|
||||
if (null == data) {
|
||||
return Result.error("先注册手机号,在登录");
|
||||
}
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
String userkey = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
map.put(JwtConstants.USER_KEY, userkey);
|
||||
map.put(JwtConstants.DETAILS_USER_ID, data.getId());
|
||||
String token = JwtUtils.createToken(map);
|
||||
redisTemplate.opsForValue().set(
|
||||
TokenConstants.LOGIN_TOKEN_KEY + userkey,
|
||||
JSONObject.toJSONString(data),
|
||||
TokenConstants.EXPIRATION,
|
||||
TimeUnit.MINUTES
|
||||
);
|
||||
RespJwt respJwt = new RespJwt();
|
||||
respJwt.setToken(token);
|
||||
respJwt.setEidTime("720MIN");
|
||||
|
||||
return Result.success(respJwt);
|
||||
}
|
||||
|
||||
/*
|
||||
* 前台每次请求都会来到这里进行解析user
|
||||
*
|
||||
* */
|
||||
@Override
|
||||
public Result<User> userinfo(HttpServletRequest request) {
|
||||
String token = request.getHeader(TokenConstants.TOKEN);
|
||||
String userKey = JwtUtils.getUserKey(token);
|
||||
String s = redisTemplate.opsForValue().get(
|
||||
TokenConstants.LOGIN_TOKEN_KEY + userKey
|
||||
);
|
||||
User user = JSONObject.parseObject(s, User.class);
|
||||
return Result.success(user);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9001
|
||||
# Spring
|
||||
spring:
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
allow-circular-references: true
|
||||
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
# 应用名称
|
||||
name: zhn-auth
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 192.168.2.51:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 192.168.2.51:8848
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.zhn.auth.mapper.AuthMapper">
|
||||
<!--namespace根据自己需要创建的的mapper的路径和名称填写-->
|
||||
|
||||
|
||||
</mapper>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,22 +0,0 @@
|
|||
package com.zhn.common.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class User {
|
||||
|
||||
private String id;
|
||||
private String username;
|
||||
private String password;
|
||||
private String tel;
|
||||
private String name;
|
||||
private String avatar;
|
||||
/**
|
||||
* 最后登录时间
|
||||
*/
|
||||
private Date lastLoginTime;
|
||||
private String balance;
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
数据源文件
|
|
@ -1,15 +0,0 @@
|
|||
# 基础镜像
|
||||
FROM openjdk:8-jre
|
||||
# author
|
||||
MAINTAINER ex_weilingfeng@163.com
|
||||
|
||||
# 挂载目录
|
||||
VOLUME /home/zhn
|
||||
# 创建目录
|
||||
RUN mkdir -p /home/zhn
|
||||
# 指定路径
|
||||
WORKDIR /home/zhn
|
||||
# 复制jar文件到路径
|
||||
COPY zhn-gateway/target/zhn-gateway.jar /home/zhn/zhn-gateway.jar
|
||||
# 启动网关服务
|
||||
ENTRYPOINT ["java","-jar","zhn-gateway.jar"]
|
|
@ -1,4 +0,0 @@
|
|||
package com.zhn.gateway.constants;
|
||||
|
||||
public class Constants {
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 18080
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: zhn-gateway
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
main:
|
||||
# 允许使用循环引用
|
||||
allow-circular-references: true
|
||||
# 允许定义相同的bean对象 去覆盖原有的
|
||||
allow-bean-definition-overriding: true
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 192.168.2.51:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 192.168.2.51:8848
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue