feat:网关整合sentinel

This commit is contained in:
haoxr 2021-04-08 22:58:14 +08:00
parent 78ca7c7ab6
commit b9ef5c5155
4 changed files with 15 additions and 11 deletions

View File

@ -118,7 +118,8 @@ youlai-mall
1. **启动`Nacos`服务** 1. **启动`Nacos`服务**
IDEA下方工具栏点击Terminal终端命令行执行`cd youlai-registry/nacos/bin`命令切换到Nacos的启动脚本文件夹下然后执行`startup -m standalone`命令启动Nacos服务 IDEA下方工具栏点击Terminal终端命令行执行`cd youlai-middleware/nacos/bin`命令切换到Nacos的启动脚本文件夹下然后执行`startup -m
standalone`命令启动Nacos服务
2. **启动平台基础服务** 2. **启动平台基础服务**

View File

@ -18,6 +18,7 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Strings;
@ -43,7 +44,7 @@ public class AuthController {
private TokenEndpoint tokenEndpoint; private TokenEndpoint tokenEndpoint;
@ApiOperation(value = "OAuth2认证",notes = "login") @ApiOperation(value = "OAuth2认证", notes = "login")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "grant_type", defaultValue = "password", value = "授权模式", required = true), @ApiImplicitParam(name = "grant_type", defaultValue = "password", value = "授权模式", required = true),
@ApiImplicitParam(name = "client_id", defaultValue = "client", value = "Oauth2客户端ID", required = true), @ApiImplicitParam(name = "client_id", defaultValue = "client", value = "Oauth2客户端ID", required = true),
@ -88,6 +89,7 @@ public class AuthController {
private UmsMemberFeignService memberFeignService; private UmsMemberFeignService memberFeignService;
private PasswordEncoder passwordEncoder; private PasswordEncoder passwordEncoder;
@SneakyThrows
public OAuth2AccessToken handleForWxAuth(Principal principal, Map<String, String> parameters) throws HttpRequestMethodNotSupportedException { public OAuth2AccessToken handleForWxAuth(Principal principal, Map<String, String> parameters) throws HttpRequestMethodNotSupportedException {
String code = parameters.get("code"); String code = parameters.get("code");
@ -97,12 +99,8 @@ public class AuthController {
} }
WxMaJscode2SessionResult session = null; WxMaJscode2SessionResult session = null;
try { // 根据授权code获取微信用户信息
// 根据授权code获取微信用户信息 session = wxService.getUserService().getSessionInfo(code);
session = wxService.getUserService().getSessionInfo(code);
} catch (WxErrorException e) {
e.printStackTrace();
}
String openid = session.getOpenid(); String openid = session.getOpenid();
String sessionKey = session.getSessionKey(); String sessionKey = session.getSessionKey();

View File

@ -54,11 +54,15 @@
<keepAliveDuration>5 minutes</keepAliveDuration> <keepAliveDuration>5 minutes</keepAliveDuration>
</appender> </appender>
<!-- additivity="true" 默认是true 会向上传递至root --> <!-- additivity 默认是true标识该logger的日志会在root的appender再打印一次 -->
<logger name="com.youlai.common.web.aspect.LoginLogAspect" level="INFO" additivity="true"> <logger name="com.youlai.common.web.aspect.LoginLogAspect" level="INFO" additivity="false">
<appender-ref ref="LOGIN_LOGSTASH"/> <appender-ref ref="LOGIN_LOGSTASH"/>
</logger> </logger>
<logger name="com.alibaba.nacos.client.naming" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<!-- 根logger --> <!-- 根logger -->
<root level="INFO"> <root level="INFO">
<appender-ref ref="CONSOLE"/> <appender-ref ref="CONSOLE"/>

View File

@ -14,6 +14,7 @@ spring:
server-addr: ${spring.cloud.nacos.discovery.server-addr} server-addr: ${spring.cloud.nacos.discovery.server-addr}
file-extension: yaml file-extension: yaml
sentinel: sentinel:
enabled: false
eager: true eager: true
transport: transport:
dashboard: localhost:8080 dashboard: localhost:8080
@ -34,6 +35,6 @@ spring:
groupId: SENTINEL_GROUP groupId: SENTINEL_GROUP
data-type: json data-type: json
rule-type: gw-api-group rule-type: gw-api-group
enabled: false