|
@@ -41,7 +41,8 @@ import java.util.Set;
|
|
|
*/
|
|
|
|
|
|
@RestController
|
|
|
-public class SysLoginController {
|
|
|
+public class SysLoginController
|
|
|
+{
|
|
|
|
|
|
@Autowired
|
|
|
private SysLoginService loginService;
|
|
@@ -62,9 +63,8 @@ public class SysLoginController {
|
|
|
private WxAppConfig wxAppConfig;
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SysLoginController.class);
|
|
|
-
|
|
|
@PostMapping("/wxLogin")
|
|
|
- public AjaxResult wxLogin(@RequestBody WxLoginBody wxLoginBody) {
|
|
|
+ public AjaxResult wxLogin(@RequestBody WxLoginBody wxLoginBody){
|
|
|
logger.info("登录参数: " + JSON.toJSONString(wxLoginBody));
|
|
|
// 获取登录凭证, 只能用一次
|
|
|
String code = wxLoginBody.getCode();
|
|
@@ -90,20 +90,19 @@ public class SysLoginController {
|
|
|
return AjaxResult.error("微信登录失败");
|
|
|
}
|
|
|
|
|
|
- if (StringUtils.hasText(decryptResult)) {
|
|
|
+ if(StringUtils.hasText(decryptResult)){
|
|
|
// 如果解析成功, 获取token
|
|
|
String token = loginService.wxLogin(decryptResult);
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
ajax.put(Constants.TOKEN, token);
|
|
|
return ajax;
|
|
|
- } else {
|
|
|
+ }else{
|
|
|
return AjaxResult.error("微信登录失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* AES解密
|
|
|
- *
|
|
|
* @param sessionKey
|
|
|
* @param encryptedIv
|
|
|
* @param encryptedData
|
|
@@ -117,7 +116,8 @@ public class SysLoginController {
|
|
|
byte[] encData = Base64.decode(encryptedData);
|
|
|
// 如果密钥不足16位, 那么久补足
|
|
|
int base = 16;
|
|
|
- if (key.length % base != 0) {
|
|
|
+ if (key.length % base != 0)
|
|
|
+ {
|
|
|
int groups = key.length / base + (key.length % base != 0 ? 1 : 0);
|
|
|
byte[] temp = new byte[groups * base];
|
|
|
Arrays.fill(temp, (byte) 0);
|
|
@@ -126,7 +126,7 @@ public class SysLoginController {
|
|
|
}
|
|
|
|
|
|
// 如果初始向量不足16位, 也补足
|
|
|
- if (iv.length % base != 0) {
|
|
|
+ if(iv.length % base != 0){
|
|
|
int groups = iv.length / base + (iv.length % base != 0 ? 1 : 0);
|
|
|
byte[] temp = new byte[groups * base];
|
|
|
Arrays.fill(temp, (byte) 0);
|
|
@@ -158,7 +158,8 @@ public class SysLoginController {
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@PostMapping("/login")
|
|
|
- public AjaxResult login(@RequestBody LoginBody loginBody) {
|
|
|
+ public AjaxResult login(@RequestBody LoginBody loginBody)
|
|
|
+ {
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
// 生成令牌
|
|
|
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
|
|
@@ -173,7 +174,8 @@ public class SysLoginController {
|
|
|
* @return 用户信息
|
|
|
*/
|
|
|
@GetMapping("getInfo")
|
|
|
- public AjaxResult getInfo() {
|
|
|
+ public AjaxResult getInfo()
|
|
|
+ {
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
if (loginUser == null) {
|
|
|
return AjaxResult.error("未获取到登录用户信息");
|
|
@@ -183,7 +185,8 @@ public class SysLoginController {
|
|
|
Set<String> roles = permissionService.getRolePermission(user);
|
|
|
// 权限集合
|
|
|
Set<String> permissions = permissionService.getMenuPermission(user);
|
|
|
- if (loginUser.getPermissions() != null && !loginUser.getPermissions().equals(permissions)) {
|
|
|
+ if (loginUser.getPermissions() != null && !loginUser.getPermissions().equals(permissions))
|
|
|
+ {
|
|
|
loginUser.setPermissions(permissions);
|
|
|
tokenService.refreshToken(loginUser);
|
|
|
}
|
|
@@ -200,7 +203,8 @@ public class SysLoginController {
|
|
|
* @return 路由信息
|
|
|
*/
|
|
|
@GetMapping("getRouters")
|
|
|
- public AjaxResult getRouters() {
|
|
|
+ public AjaxResult getRouters()
|
|
|
+ {
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
|
|
|
return AjaxResult.success(menuService.buildMenus(menus));
|