userName hai 2 semanas
pai
achega
472a5b4445

+ 16 - 44
src/main/java/com/zhentao/controller/LoginController.java

@@ -1,5 +1,8 @@
 package com.zhentao.controller;
 
+import com.zhentao.domain.GooseUser;
+import com.zhentao.service.GooseUserService;
+import com.zhentao.util.ResultVo;
 import org.apache.shiro.SecurityUtils;
 import org.apache.shiro.authc.IncorrectCredentialsException;
 import org.apache.shiro.authc.UnknownAccountException;
@@ -7,52 +10,21 @@ import org.apache.shiro.authc.UsernamePasswordToken;
 import org.apache.shiro.subject.Subject;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.*;
 
-@Controller
-public class LoginController {
-
-    // ---------------------- 登录页面 ----------------------
-    @GetMapping("/login")
-    public String loginPage() {
-        return "login"; // 对应 resources/templates/login.html
-    }
-
-    // ---------------------- 登录处理 ----------------------
-    @PostMapping("/login")
-    public String login(String username, String password, Model model) {
-        Subject subject = SecurityUtils.getSubject();
-        UsernamePasswordToken token = new UsernamePasswordToken(username, password);
-        try {
-            subject.login(token); // 执行认证
-            return "redirect:/home"; // 认证成功跳转主页
-        } catch (UnknownAccountException e) {
-            model.addAttribute("error", "用户名不存在");
-        } catch (IncorrectCredentialsException e) {
-            model.addAttribute("error", "密码错误");
-        }
-        return "login"; // 认证失败返回登录页
-    }
+import javax.annotation.Resource;
 
-    // ---------------------- 主页(需认证) ----------------------
-    @GetMapping("/home")
-    public String homePage(Model model) {
-        Subject subject = SecurityUtils.getSubject();
-        model.addAttribute("username", subject.getPrincipal());
-        return "home"; // 对应 resources/templates/home.html
-    }
-
-    // ---------------------- 未授权页面 ----------------------
-    @GetMapping("/unauthorized")
-    public String unauthorizedPage() {
-        return "unauthorized"; // 对应 resources/templates/unauthorized.html
+@RestController
+@RequestMapping("/user")
+public class LoginController {
+    @Resource
+    private GooseUserService gooseUserService;
+    @RequestMapping("/login")
+    public ResultVo login(@RequestBody GooseUser gooseUser){
+        return gooseUserService.login(gooseUser);
     }
-
-    // ---------------------- 退出登录 ----------------------
-    @GetMapping("/logout")
-    public String logout() {
-        SecurityUtils.getSubject().logout();
-        return "redirect:/login";
+    @RequestMapping("/register")
+    public ResultVo register(@RequestBody GooseUser gooseUser){
+        return gooseUserService.register(gooseUser);
     }
 }

+ 77 - 0
src/main/java/com/zhentao/controller/WechatLoginApplication.java

@@ -0,0 +1,77 @@
+package com.zhentao.controller;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.client.HttpClientErrorException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@RestController
+public class WechatLoginApplication {
+
+    private static final String APPID = "wxc8a6a80ca6808238";
+    private static final String SECRET = "96f6ef6782c1080b1c33016c0d0555b5";
+    private static final ObjectMapper objectMapper = new ObjectMapper(); // JSON 解析器
+
+    @PostMapping("/api/wx-login")
+    public Map<String, Object> wxLogin(@RequestBody Map<String, String> requestData) {
+        String code = requestData.get("code");
+        System.out.println(code);
+        if (code == null) {
+            return buildErrorResponse("Missing code");
+        }
+
+        String url = "https://api.weixin.qq.com/sns/jscode2session?" +
+                "appid=" + APPID +
+                "&secret=" + SECRET +
+                "&js_code=" + code +
+                "&grant_type=authorization_code";
+
+        RestTemplate restTemplate = new RestTemplate();
+        HttpHeaders headers = new HttpHeaders();
+        HttpEntity<String> entity = new HttpEntity<>(headers);
+
+        try {
+            // 改用 String 接收响应,兼容所有 Content-Type
+            ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
+            String responseBody = response.getBody();
+
+            // 手动解析 JSON
+            Map<String, Object> result = objectMapper.readValue(responseBody, Map.class);
+            System.out.println(result);
+            if (result.containsKey("errcode")) { // 微信错误响应
+                return buildErrorResponse("微信接口返回错误: " + result.get("errmsg"));
+            }
+            // 成功响应
+            return buildSuccessResponse((String) result.get("openid"), (String) result.get("session_key"));
+
+        } catch (HttpClientErrorException e) { // 处理 HTTP 错误(如 400、500)
+            return buildErrorResponse("请求微信接口失败: " + e.getResponseBodyAsString());
+        } catch (Exception e) { // 处理 JSON 解析错误
+            return buildErrorResponse("响应解析失败: " + e.getMessage());
+        }
+    }
+
+    // 构建成功响应
+    private Map<String, Object> buildSuccessResponse(String openid, String sessionKey) {
+        Map<String, Object> response = new HashMap<>();
+        response.put("openid", openid);
+        response.put("session_key", sessionKey);
+        return response;
+    }
+
+    // 构建错误响应
+    private Map<String, Object> buildErrorResponse(String message) {
+        Map<String, Object> response = new HashMap<>();
+        response.put("error", message);
+        return response;
+    }
+}

+ 295 - 295
src/main/java/com/zhentao/shiro/config/ShiroConfig.java

@@ -1,295 +1,295 @@
-
-
-package com.zhentao.shiro.config;
-
-import com.alibaba.fastjson.JSON;
-
-import com.zhentao.properties.JwtProperties;
-import com.zhentao.properties.ShiroPermissionProperties;
-import com.zhentao.properties.ShiroProperties;
-import com.zhentao.util.IniUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.authc.Authenticator;
-import org.apache.shiro.authc.credential.CredentialsMatcher;
-import org.apache.shiro.authc.pam.FirstSuccessfulStrategy;
-import org.apache.shiro.authc.pam.ModularRealmAuthenticator;
-import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
-import org.apache.shiro.mgt.DefaultSubjectDAO;
-import org.apache.shiro.mgt.SecurityManager;
-import org.apache.shiro.mgt.SessionStorageEvaluator;
-import org.apache.shiro.spring.LifecycleBeanPostProcessor;
-import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
-import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
-import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
-import org.apache.shiro.web.mgt.DefaultWebSessionStorageEvaluator;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.boot.web.servlet.FilterRegistrationBean;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.filter.DelegatingFilterProxy;
-
-import javax.servlet.DispatcherType;
-import javax.servlet.Filter;
-import java.util.*;
-
-/**
- * Shiro配置
- * https://shiro.apache.org/spring.html
- * https://shiro.apache.org/spring-boot.html
- **/
-@Slf4j
-@Configuration
-@EnableConfigurationProperties({ShiroProperties.class})
-@ConditionalOnProperty(value = {"spring-boot-jjj.shiro.enable"}, matchIfMissing = true)
-public class ShiroConfig {
-
-    /**
-     * JWT过滤器名称
-     */
-    private static final String JWT_FILTER_NAME = "jwtFilter";
-
-    /**
-     * Shiro过滤器名称
-     */
-    private static final String SHIRO_FILTER_NAME = "shiroFilter";
-
-    /**
-     * anon
-     */
-    private static final String ANON = "anon";
-
-
-    @Bean
-    public CredentialsMatcher credentialsMatcher() {
-        return new JwtCredentialsMatcher();
-    }
-
-    /**
-     * JWT数据源验证
-     *
-     * @return
-     */
-    @Bean
-    public JwtRealm jwtRealm() {
-        JwtRealm jwtRealm = new JwtRealm();
-//        jwtRealm.setCachingEnabled(false);
-        jwtRealm.setCredentialsMatcher(credentialsMatcher());
-        return jwtRealm;
-    }
-
-
-    @Bean
-    public SessionStorageEvaluator sessionStorageEvaluator() {
-        DefaultSessionStorageEvaluator sessionStorageEvaluator = new DefaultWebSessionStorageEvaluator();
-        sessionStorageEvaluator.setSessionStorageEnabled(false);
-        return sessionStorageEvaluator;
-    }
-
-    @Bean
-    public DefaultSubjectDAO subjectDAO() {
-        DefaultSubjectDAO defaultSubjectDAO = new DefaultSubjectDAO();
-        defaultSubjectDAO.setSessionStorageEvaluator(sessionStorageEvaluator());
-        return defaultSubjectDAO;
-    }
-
-    /**
-     * 安全管理器配置
-     *
-     * @return
-     */
-    @Bean
-    public SecurityManager securityManager() {
-        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
-        securityManager.setRealm(jwtRealm());
-        securityManager.setSubjectDAO(subjectDAO());
-        SecurityUtils.setSecurityManager(securityManager);
-        return securityManager;
-    }
-
-    /**
-     * ShiroFilterFactoryBean配置
-     *
-     * @param securityManager
-     * @param shiroProperties
-     * @param jwtProperties
-     * @return
-     */
-    @Bean(SHIRO_FILTER_NAME)
-    public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager,
-
-                                                         ShiroProperties shiroProperties,
-                                                         JwtProperties jwtProperties) {
-        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
-        shiroFilterFactoryBean.setSecurityManager(securityManager);
-        Map<String, Filter> filterMap = getFilterMap( jwtProperties);
-        shiroFilterFactoryBean.setFilters(filterMap);
-        Map<String, String> filterChainMap = null;
-        try {
-            filterChainMap = getFilterChainDefinitionMap(shiroProperties);
-
-        shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainMap);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return shiroFilterFactoryBean;
-    }
-
-
-    /**
-     * 获取filter map
-     *
-     * @return
-     */
-    private Map<String, Filter> getFilterMap(
-                                             JwtProperties jwtProperties) {
-        Map<String, Filter> filterMap = new LinkedHashMap<>();
-        filterMap.put(JWT_FILTER_NAME, new JwtFilter(jwtProperties));
-        return filterMap;
-    }
-
-
-    /**
-     * Shiro路径权限配置
-     *
-     * @return
-     */
-    private Map<String, String> getFilterChainDefinitionMap(ShiroProperties shiroProperties) throws Exception {
-        Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
-        // 获取排除的路径
-        List<String[]> anonList = shiroProperties.getAnon();
-        log.debug("anonList:{}", JSON.toJSONString(anonList));
-        if (CollectionUtils.isNotEmpty(anonList)) {
-            anonList.forEach(anonArray -> {
-                if (ArrayUtils.isNotEmpty(anonArray)) {
-                    for (String anonPath : anonArray) {
-                        filterChainDefinitionMap.put(anonPath, ANON);
-                    }
-                }
-            });
-        }
-
-        // 获取ini格式配置
-        String definitions = shiroProperties.getFilterChainDefinitions();
-        if (StringUtils.isNotBlank(definitions)) {
-            Map<String, String> section = IniUtil.parseIni(definitions);
-            log.debug("definitions:{}", JSON.toJSONString(section));
-            for (Map.Entry<String, String> entry : section.entrySet()) {
-                filterChainDefinitionMap.put(entry.getKey(), entry.getValue());
-            }
-        }
-
-        // 获取自定义权限路径配置集合
-        List<ShiroPermissionProperties> permissionConfigs = shiroProperties.getPermission();
-        log.debug("permissionConfigs:{}", JSON.toJSONString(permissionConfigs));
-        if (CollectionUtils.isNotEmpty(permissionConfigs)) {
-            for (ShiroPermissionProperties permissionConfig : permissionConfigs) {
-                String url = permissionConfig.getUrl();
-                String[] urls = permissionConfig.getUrls();
-                String permission = permissionConfig.getPermission();
-                if (StringUtils.isBlank(url) && ArrayUtils.isEmpty(urls)) {
-                    throw new Exception("shiro permission config 路径配置不能为空");
-                }
-                if (StringUtils.isBlank(permission)) {
-                    throw new Exception("shiro permission config permission不能为空");
-                }
-
-                if (StringUtils.isNotBlank(url)) {
-                    filterChainDefinitionMap.put(url, permission);
-                }
-                if (ArrayUtils.isNotEmpty(urls)) {
-                    for (String string : urls) {
-                        filterChainDefinitionMap.put(string, permission);
-                    }
-                }
-            }
-        }
-
-        // 如果启用shiro,则设置最后一个设置为JWTFilter,否则全部路径放行
-        if (shiroProperties.isEnable()) {
-            filterChainDefinitionMap.put("/**", JWT_FILTER_NAME);
-        } else {
-            filterChainDefinitionMap.put("/**", ANON);
-        }
-
-        log.debug("filterChainMap:{}", JSON.toJSONString(filterChainDefinitionMap));
-
-        // 添加默认的filter
-        Map<String, String> newFilterChainDefinitionMap = addDefaultFilterDefinition(filterChainDefinitionMap);
-        return newFilterChainDefinitionMap;
-    }
-
-    /**
-     * 添加默认的filter权限过滤
-     *
-     * @param filterChainDefinitionMap
-     * @return
-     */
-    private Map<String, String> addDefaultFilterDefinition(Map<String, String> filterChainDefinitionMap) {
-        if (MapUtils.isEmpty(filterChainDefinitionMap)) {
-            return filterChainDefinitionMap;
-        }
-        final Map<String, String> map = new LinkedHashMap<>();
-        for (Map.Entry<String, String> entry : filterChainDefinitionMap.entrySet()) {
-            String key = entry.getKey();
-            String value = entry.getValue();
-            String definition;
-            String[] strings = value.split(",");
-            List<String> list = new ArrayList<>();
-            list.addAll(Arrays.asList(strings));
-            definition = String.join(",", list);
-            map.put(key, definition);
-        }
-        return map;
-    }
-
-    /**
-     * ShiroFilter配置
-     *
-     * @return
-     */
-    @Bean
-    public FilterRegistrationBean delegatingFilterProxy() {
-        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
-        DelegatingFilterProxy proxy = new DelegatingFilterProxy();
-        proxy.setTargetFilterLifecycle(true);
-        proxy.setTargetBeanName(SHIRO_FILTER_NAME);
-        filterRegistrationBean.setFilter(proxy);
-        filterRegistrationBean.setAsyncSupported(true);
-        filterRegistrationBean.setEnabled(true);
-        filterRegistrationBean.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
-        return filterRegistrationBean;
-    }
-
-    @Bean
-    public Authenticator authenticator() {
-        ModularRealmAuthenticator authenticator = new ModularRealmAuthenticator();
-        authenticator.setRealms(Arrays.asList(jwtRealm()));
-        authenticator.setAuthenticationStrategy(new FirstSuccessfulStrategy());
-        return authenticator;
-    }
-
-
-    /**
-     * Enabling Shiro Annotations
-     *
-     * @return
-     */
-    @Bean
-    public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
-        return new LifecycleBeanPostProcessor();
-    }
-
-    @Bean
-    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
-        AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
-        authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
-        return authorizationAttributeSourceAdvisor;
-    }
-
-}
+//
+//
+//package com.zhentao.shiro.config;
+//
+//import com.alibaba.fastjson.JSON;
+//
+//import com.zhentao.properties.JwtProperties;
+//import com.zhentao.properties.ShiroPermissionProperties;
+//import com.zhentao.properties.ShiroProperties;
+//import com.zhentao.util.IniUtil;
+//import lombok.extern.slf4j.Slf4j;
+//import org.apache.commons.collections.CollectionUtils;
+//import org.apache.commons.collections.MapUtils;
+//import org.apache.commons.lang3.ArrayUtils;
+//import org.apache.commons.lang3.StringUtils;
+//import org.apache.shiro.SecurityUtils;
+//import org.apache.shiro.authc.Authenticator;
+//import org.apache.shiro.authc.credential.CredentialsMatcher;
+//import org.apache.shiro.authc.pam.FirstSuccessfulStrategy;
+//import org.apache.shiro.authc.pam.ModularRealmAuthenticator;
+//import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
+//import org.apache.shiro.mgt.DefaultSubjectDAO;
+//import org.apache.shiro.mgt.SecurityManager;
+//import org.apache.shiro.mgt.SessionStorageEvaluator;
+//import org.apache.shiro.spring.LifecycleBeanPostProcessor;
+//import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
+//import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
+//import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
+//import org.apache.shiro.web.mgt.DefaultWebSessionStorageEvaluator;
+//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+//import org.springframework.boot.context.properties.EnableConfigurationProperties;
+//import org.springframework.boot.web.servlet.FilterRegistrationBean;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.web.filter.DelegatingFilterProxy;
+//
+//import javax.servlet.DispatcherType;
+//import javax.servlet.Filter;
+//import java.util.*;
+//
+///**
+// * Shiro配置
+// * https://shiro.apache.org/spring.html
+// * https://shiro.apache.org/spring-boot.html
+// **/
+//@Slf4j
+//@Configuration
+//@EnableConfigurationProperties({ShiroProperties.class})
+//@ConditionalOnProperty(value = {"spring-boot-jjj.shiro.enable"}, matchIfMissing = true)
+//public class ShiroConfig {
+//
+//    /**
+//     * JWT过滤器名称
+//     */
+//    private static final String JWT_FILTER_NAME = "jwtFilter";
+//
+//    /**
+//     * Shiro过滤器名称
+//     */
+//    private static final String SHIRO_FILTER_NAME = "shiroFilter";
+//
+//    /**
+//     * anon
+//     */
+//    private static final String ANON = "anon";
+//
+//
+//    @Bean
+//    public CredentialsMatcher credentialsMatcher() {
+//        return new JwtCredentialsMatcher();
+//    }
+//
+//    /**
+//     * JWT数据源验证
+//     *
+//     * @return
+//     */
+//    @Bean
+//    public JwtRealm jwtRealm() {
+//        JwtRealm jwtRealm = new JwtRealm();
+////        jwtRealm.setCachingEnabled(false);
+//        jwtRealm.setCredentialsMatcher(credentialsMatcher());
+//        return jwtRealm;
+//    }
+//
+//
+//    @Bean
+//    public SessionStorageEvaluator sessionStorageEvaluator() {
+//        DefaultSessionStorageEvaluator sessionStorageEvaluator = new DefaultWebSessionStorageEvaluator();
+//        sessionStorageEvaluator.setSessionStorageEnabled(false);
+//        return sessionStorageEvaluator;
+//    }
+//
+//    @Bean
+//    public DefaultSubjectDAO subjectDAO() {
+//        DefaultSubjectDAO defaultSubjectDAO = new DefaultSubjectDAO();
+//        defaultSubjectDAO.setSessionStorageEvaluator(sessionStorageEvaluator());
+//        return defaultSubjectDAO;
+//    }
+//
+//    /**
+//     * 安全管理器配置
+//     *
+//     * @return
+//     */
+//    @Bean
+//    public SecurityManager securityManager() {
+//        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
+//        securityManager.setRealm(jwtRealm());
+//        securityManager.setSubjectDAO(subjectDAO());
+//        SecurityUtils.setSecurityManager(securityManager);
+//        return securityManager;
+//    }
+//
+//    /**
+//     * ShiroFilterFactoryBean配置
+//     *
+//     * @param securityManager
+//     * @param shiroProperties
+//     * @param jwtProperties
+//     * @return
+//     */
+//    @Bean(SHIRO_FILTER_NAME)
+//    public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager,
+//
+//                                                         ShiroProperties shiroProperties,
+//                                                         JwtProperties jwtProperties) {
+//        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
+//        shiroFilterFactoryBean.setSecurityManager(securityManager);
+//        Map<String, Filter> filterMap = getFilterMap( jwtProperties);
+//        shiroFilterFactoryBean.setFilters(filterMap);
+//        Map<String, String> filterChainMap = null;
+//        try {
+//            filterChainMap = getFilterChainDefinitionMap(shiroProperties);
+//
+//        shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainMap);
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//        return shiroFilterFactoryBean;
+//    }
+//
+//
+//    /**
+//     * 获取filter map
+//     *
+//     * @return
+//     */
+//    private Map<String, Filter> getFilterMap(
+//                                             JwtProperties jwtProperties) {
+//        Map<String, Filter> filterMap = new LinkedHashMap<>();
+//        filterMap.put(JWT_FILTER_NAME, new JwtFilter(jwtProperties));
+//        return filterMap;
+//    }
+//
+//
+//    /**
+//     * Shiro路径权限配置
+//     *
+//     * @return
+//     */
+//    private Map<String, String> getFilterChainDefinitionMap(ShiroProperties shiroProperties) throws Exception {
+//        Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
+//        // 获取排除的路径
+//        List<String[]> anonList = shiroProperties.getAnon();
+//        log.debug("anonList:{}", JSON.toJSONString(anonList));
+//        if (CollectionUtils.isNotEmpty(anonList)) {
+//            anonList.forEach(anonArray -> {
+//                if (ArrayUtils.isNotEmpty(anonArray)) {
+//                    for (String anonPath : anonArray) {
+//                        filterChainDefinitionMap.put(anonPath, ANON);
+//                    }
+//                }
+//            });
+//        }
+//
+//        // 获取ini格式配置
+//        String definitions = shiroProperties.getFilterChainDefinitions();
+//        if (StringUtils.isNotBlank(definitions)) {
+//            Map<String, String> section = IniUtil.parseIni(definitions);
+//            log.debug("definitions:{}", JSON.toJSONString(section));
+//            for (Map.Entry<String, String> entry : section.entrySet()) {
+//                filterChainDefinitionMap.put(entry.getKey(), entry.getValue());
+//            }
+//        }
+//
+//        // 获取自定义权限路径配置集合
+//        List<ShiroPermissionProperties> permissionConfigs = shiroProperties.getPermission();
+//        log.debug("permissionConfigs:{}", JSON.toJSONString(permissionConfigs));
+//        if (CollectionUtils.isNotEmpty(permissionConfigs)) {
+//            for (ShiroPermissionProperties permissionConfig : permissionConfigs) {
+//                String url = permissionConfig.getUrl();
+//                String[] urls = permissionConfig.getUrls();
+//                String permission = permissionConfig.getPermission();
+//                if (StringUtils.isBlank(url) && ArrayUtils.isEmpty(urls)) {
+//                    throw new Exception("shiro permission config 路径配置不能为空");
+//                }
+//                if (StringUtils.isBlank(permission)) {
+//                    throw new Exception("shiro permission config permission不能为空");
+//                }
+//
+//                if (StringUtils.isNotBlank(url)) {
+//                    filterChainDefinitionMap.put(url, permission);
+//                }
+//                if (ArrayUtils.isNotEmpty(urls)) {
+//                    for (String string : urls) {
+//                        filterChainDefinitionMap.put(string, permission);
+//                    }
+//                }
+//            }
+//        }
+//
+//        // 如果启用shiro,则设置最后一个设置为JWTFilter,否则全部路径放行
+//        if (shiroProperties.isEnable()) {
+//            filterChainDefinitionMap.put("/**", JWT_FILTER_NAME);
+//        } else {
+//            filterChainDefinitionMap.put("/**", ANON);
+//        }
+//
+//        log.debug("filterChainMap:{}", JSON.toJSONString(filterChainDefinitionMap));
+//
+//        // 添加默认的filter
+//        Map<String, String> newFilterChainDefinitionMap = addDefaultFilterDefinition(filterChainDefinitionMap);
+//        return newFilterChainDefinitionMap;
+//    }
+//
+//    /**
+//     * 添加默认的filter权限过滤
+//     *
+//     * @param filterChainDefinitionMap
+//     * @return
+//     */
+//    private Map<String, String> addDefaultFilterDefinition(Map<String, String> filterChainDefinitionMap) {
+//        if (MapUtils.isEmpty(filterChainDefinitionMap)) {
+//            return filterChainDefinitionMap;
+//        }
+//        final Map<String, String> map = new LinkedHashMap<>();
+//        for (Map.Entry<String, String> entry : filterChainDefinitionMap.entrySet()) {
+//            String key = entry.getKey();
+//            String value = entry.getValue();
+//            String definition;
+//            String[] strings = value.split(",");
+//            List<String> list = new ArrayList<>();
+//            list.addAll(Arrays.asList(strings));
+//            definition = String.join(",", list);
+//            map.put(key, definition);
+//        }
+//        return map;
+//    }
+//
+//    /**
+//     * ShiroFilter配置
+//     *
+//     * @return
+//     */
+//    @Bean
+//    public FilterRegistrationBean delegatingFilterProxy() {
+//        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
+//        DelegatingFilterProxy proxy = new DelegatingFilterProxy();
+//        proxy.setTargetFilterLifecycle(true);
+//        proxy.setTargetBeanName(SHIRO_FILTER_NAME);
+//        filterRegistrationBean.setFilter(proxy);
+//        filterRegistrationBean.setAsyncSupported(true);
+//        filterRegistrationBean.setEnabled(true);
+//        filterRegistrationBean.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
+//        return filterRegistrationBean;
+//    }
+//
+//    @Bean
+//    public Authenticator authenticator() {
+//        ModularRealmAuthenticator authenticator = new ModularRealmAuthenticator();
+//        authenticator.setRealms(Arrays.asList(jwtRealm()));
+//        authenticator.setAuthenticationStrategy(new FirstSuccessfulStrategy());
+//        return authenticator;
+//    }
+//
+//
+//    /**
+//     * Enabling Shiro Annotations
+//     *
+//     * @return
+//     */
+//    @Bean
+//    public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
+//        return new LifecycleBeanPostProcessor();
+//    }
+//
+//    @Bean
+//    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
+//        AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
+//        authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
+//        return authorizationAttributeSourceAdvisor;
+//    }
+//
+//}

+ 27 - 0
src/main/java/com/zhentao/util/ResultVo.java

@@ -0,0 +1,27 @@
+package com.zhentao.util;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class ResultVo {
+    private Integer code;
+    private String message;
+    private Object data;
+
+    public static ResultVo OK(){
+        return new ResultVo(200,"操作成功",null);
+    }
+    public static ResultVo ERROR(){
+        return new ResultVo(400,"操作失败",null);
+    }
+    public static ResultVo OK(Object data){
+        return new ResultVo(200,"操作成功",data);
+    }
+    public static ResultVo ERROR(Object data){
+        return new ResultVo(200,"操作成功",data);
+    }
+}

+ 6 - 4
src/main/resources/application.yml

@@ -30,19 +30,21 @@ springboot-zhentao:
     # 权限配置
     anon:
       # 排除静态资源
-      - /static/**,/templates/**
+      - /static/**
+      - /templates/**
       # 排除Swagger
       # 排除actuator
       - /actuator/**
       - # 排除首页
-      - /,/index.html
+      - /
+      - /index.html
       # front模块
       - /front/**
       # admin模块
       - /admin/passport/login
-
       - # service模块
       - /login
+      - /api/wx-login
       # job模块
       - /job/**
     # 多行字符串权限配置
@@ -57,4 +59,4 @@ spring:
     driver-class-name: com.mysql.cj.jdbc.Driver
     url: jdbc:mysql://47.111.130.63:3306/goose_course?serverTimezone=UTC
     username: root
-    password: root
+    password: Yizu@666