feat: 修改配置信息
This commit is contained in:
parent
7bd921a746
commit
69f322f236
|
@ -0,0 +1,13 @@
|
|||
package com.atguigu.daijia.common.login;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
//登录判断
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface GuiguLogin {
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.atguigu.daijia.common.login;
|
||||
|
||||
import com.atguigu.daijia.common.constant.RedisConstant;
|
||||
import com.atguigu.daijia.common.execption.GuiguException;
|
||||
import com.atguigu.daijia.common.result.ResultCodeEnum;
|
||||
import com.atguigu.daijia.common.util.AuthContextHolder;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
@Component
|
||||
@Aspect //切面类
|
||||
public class GuiguLoginAspect {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<Object,Object> redisTemplate;
|
||||
|
||||
//环绕通知,登录判断
|
||||
//切入点表达式:指定对哪些规则的方法进行增强
|
||||
@Around("execution(* com.atguigu.daijia.*.controller.*.*(..)) && @annotation(guiguLogin)")
|
||||
public Object login(ProceedingJoinPoint proceedingJoinPoint,GuiguLogin guiguLogin) throws Throwable {
|
||||
|
||||
//1 获取request对象
|
||||
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
||||
ServletRequestAttributes sra = (ServletRequestAttributes)attributes;
|
||||
HttpServletRequest request = sra.getRequest();
|
||||
|
||||
//2 从请求头获取token
|
||||
String token = request.getHeader("token");
|
||||
|
||||
//3 判断token是否为空,如果为空,返回登录提示
|
||||
if(!StringUtils.hasText(token)) {
|
||||
throw new GuiguException(ResultCodeEnum.LOGIN_AUTH);
|
||||
}
|
||||
|
||||
//4 token不为空,查询redis
|
||||
String customerId = (String)redisTemplate.opsForValue()
|
||||
.get(RedisConstant.USER_LOGIN_KEY_PREFIX+token);
|
||||
|
||||
//5 查询redis对应用户id,把用户id放到ThreadLocal里面
|
||||
if(StringUtils.hasText(customerId)) {
|
||||
AuthContextHolder.setUserId(Long.parseLong(customerId));
|
||||
}
|
||||
|
||||
//6 执行业务方法
|
||||
return proceedingJoinPoint.proceed();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
spring:
|
||||
application:
|
||||
name: service-coupon
|
||||
profiles:
|
||||
active: dev
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 192.168.3.129:8848
|
||||
config:
|
||||
server-addr: 192.168.3.129:8848
|
||||
prefix: ${spring.application.name}
|
||||
file-extension: yaml
|
||||
shared-configs:
|
||||
- data-id: common-account.yaml
|
|
@ -0,0 +1,28 @@
|
|||
package com.atguigu.daijia.customer.config;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class WxConfigOperator {
|
||||
|
||||
@Autowired
|
||||
private WxConfigProperties wxConfigProperties;
|
||||
|
||||
@Bean
|
||||
public WxMaService wxMaService() {
|
||||
|
||||
//微信小程序id和秘钥
|
||||
WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
|
||||
wxMaConfig.setAppid(wxConfigProperties.getAppId());
|
||||
wxMaConfig.setSecret(wxConfigProperties.getSecret());
|
||||
|
||||
WxMaService service = new WxMaServiceImpl();
|
||||
service.setWxMaConfig(wxMaConfig);
|
||||
return service;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.atguigu.daijia.customer.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "wx.miniapp")
|
||||
public class WxConfigProperties {
|
||||
private String appId;
|
||||
private String secret;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
spring:
|
||||
application:
|
||||
name: service-customer
|
||||
profiles:
|
||||
active: dev
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 192.168.3.129:8848
|
||||
config:
|
||||
server-addr: 192.168.3.129:8848
|
||||
prefix: ${spring.application.name}
|
||||
file-extension: yaml
|
||||
shared-configs:
|
||||
- data-id: common-account.yaml
|
|
@ -0,0 +1,18 @@
|
|||
spring:
|
||||
application:
|
||||
name: web-customer
|
||||
profiles:
|
||||
active: dev
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 192.168.3.129:8848
|
||||
config:
|
||||
server-addr: 192.168.3.129:8848
|
||||
prefix: ${spring.application.name}
|
||||
file-extension: yaml
|
||||
shared-configs:
|
||||
- data-id: common-account.yaml
|
Loading…
Reference in New Issue