jc 2 недель назад
Родитель
Сommit
9abb67f798
26 измененных файлов с 855 добавлено и 1147 удалено
  1. 74 0
      pom.xml
  2. 14 0
      src/main/java/com/xet/domain/user/dto/LoginDto.java
  3. 12 0
      src/main/java/com/xet/domain/user/dto/WxLoginDto.java
  4. 35 0
      src/main/java/com/xet/domain/user/pojo/Auth.java
  5. 50 0
      src/main/java/com/xet/domain/user/pojo/Users.java
  6. 0 73
      src/main/java/com/xet/properties/JwtProperties.java
  7. 0 27
      src/main/java/com/xet/properties/ShiroPermissionProperties.java
  8. 0 39
      src/main/java/com/xet/properties/ShiroProperties.java
  9. 0 29
      src/main/java/com/xet/shiro/config/JwtCredentialsMatcher.java
  10. 0 169
      src/main/java/com/xet/shiro/config/JwtFilter.java
  11. 0 99
      src/main/java/com/xet/shiro/config/JwtRealm.java
  12. 0 294
      src/main/java/com/xet/shiro/config/ShiroConfig.java
  13. 0 79
      src/main/java/com/xet/shiro/utils/JwtToken.java
  14. 0 87
      src/main/java/com/xet/shiro/utils/JwtTokenUtil.java
  15. 0 186
      src/main/java/com/xet/shiro/utils/JwtUtil.java
  16. 0 59
      src/main/java/com/xet/shiro/utils/SaltUtil.java
  17. 47 0
      src/main/java/com/xet/user/controller/LoginController.java
  18. 13 0
      src/main/java/com/xet/user/mapper/UserMapper.java
  19. 17 0
      src/main/java/com/xet/user/service/UserService.java
  20. 130 0
      src/main/java/com/xet/user/service/impl/UserServiceImpl.java
  21. 311 0
      src/main/java/com/xet/util/HttpUtils.java
  22. 22 0
      src/main/java/com/xet/util/jie/ApiException.java
  23. 46 0
      src/main/java/com/xet/util/jie/ApiServiceExceptionEnum.java
  24. 18 0
      src/main/java/com/xet/util/jie/BaseExceptionEnum.java
  25. 66 0
      src/main/java/com/xet/util/jie/ResultVo.java
  26. 0 6
      src/main/resources/static/index.html

+ 74 - 0
pom.xml

@@ -34,6 +34,80 @@
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid</artifactId>
+            <version>1.2.23</version>
+        </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+            <version>3.5.4</version>
+        </dependency>
+
+        <dependency>
+            <groupId>io.jsonwebtoken</groupId>
+            <artifactId>jjwt</artifactId>
+            <version>0.9.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.auth0</groupId>
+            <artifactId>java-jwt</artifactId>
+            <version>3.10.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-spring</artifactId>
+            <version>1.8.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.9</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-collections4</artifactId>
+            <version>4.4</version>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.83</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-json</artifactId>
+        </dependency>
+        <!-- AOP依赖,必须,否则shiro权限拦截验证不生效 -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
+        <!-- ini格式处理 -->
+        <dependency>
+            <groupId>org.ini4j</groupId>
+            <artifactId>ini4j</artifactId>
+            <version>0.5.4</version>
+        </dependency>
+
+<!--        //验证码-->
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.13</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpcore</artifactId>
+            <version>4.4.14</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>2.6</version>
+        </dependency>
+
     </dependencies>
     <dependencyManagement>
         <dependencies>

+ 14 - 0
src/main/java/com/xet/domain/user/dto/LoginDto.java

@@ -0,0 +1,14 @@
+package com.xet.domain.user.dto;
+
+import lombok.Data;
+
+/**
+ * @Date 2025/5/5 20:40
+ * @Author neko
+ **/
+@Data
+public class LoginDto {
+    private String phone;
+    private String password;
+    private Integer smsCode;
+}

+ 12 - 0
src/main/java/com/xet/domain/user/dto/WxLoginDto.java

@@ -0,0 +1,12 @@
+package com.xet.domain.user.dto;
+
+import lombok.Data;
+
+/**
+ * @Date 2025/5/6 19:28
+ * @Author neko
+ **/
+@Data
+public class WxLoginDto {
+
+}

+ 35 - 0
src/main/java/com/xet/domain/user/pojo/Auth.java

@@ -0,0 +1,35 @@
+package com.xet.domain.user.pojo;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @Date 2025/5/5 19:26
+ * @Author neko
+ **/
+@Data
+@TableName("auth")
+public class Auth {
+    //主键id
+    private String authId;
+    //用户id
+    private String userId;
+    //真实姓名
+    private String realName;
+    //身份证号
+    private String idCardNumber;
+    //身份证照片-正面
+    private String idCardFront;
+    //身份证照片-反面
+    private String idCardBack;
+    //认证状态 0未通过 1通过 2审核中 3审核不通过
+    private Integer authStatus;
+    //认证时间
+    private Date authTime;
+    //创建时间
+    private Date createTime;
+    //更新时间
+    private Date updateTime;
+}

+ 50 - 0
src/main/java/com/xet/domain/user/pojo/Users.java

@@ -0,0 +1,50 @@
+package com.xet.domain.user.pojo;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import org.omg.PortableInterceptor.INACTIVE;
+
+import java.util.Date;
+
+/**
+ * @Date 2025/5/5 19:13
+ * @Author neko
+ **/
+@Data
+@TableName("users")
+public class Users {
+    //用户id
+    private String userId;
+    //用户名称
+    private String nickname;
+    //密码
+    private String password;
+    //盐
+    private String salt;
+    //手机号
+    private String phone;
+    //邮箱
+    private String email;
+    //头像
+    private String avatar;
+    //性别
+    private String sex;
+    //年龄
+    private Integer age;
+    //生日
+    private Date birthday;
+    //状态 0正常 1禁用
+    private Integer status;
+    //注册时间
+    private Date registerTime;
+    //最后登录时间
+    private Date lastLoginTime;
+    //是否是VIP 0否 1是
+    private Integer isVip;
+    //VIP购买时间
+    private Date vipPurchaseTime;
+    //VIP到期时间
+    private Date vipExpireTime;
+    //是否实名认证 0否 1是
+    private Integer isAuth;
+}

+ 0 - 73
src/main/java/com/xet/properties/JwtProperties.java

@@ -1,73 +0,0 @@
-
-
-package com.xet.properties;
-
-import com.xet.constants.CommonConstant;
-import lombok.Data;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.stereotype.Component;
-
-/**
- * JWT属性配置
- **/
-@Data
-@Component
-@ConfigurationProperties(prefix = "spring-boot-futu.jwt")
-public class JwtProperties {
-
-    /**
-     * token名称,默认名称为:token,可自定义
-     */
-    private String tokenName = CommonConstant.JWT_DEFAULT_TOKEN_NAME;
-
-    /**
-     * 密码
-     */
-    private String secret = CommonConstant.JWT_DEFAULT_SECRET;
-
-    /**
-     * 签发人
-     */
-    private String issuer;
-
-    /**
-     * 主题
-     */
-    private String subject;
-
-    /**
-     * 签发的目标
-     */
-    private String audience;
-
-    /**
-     * token失效时间,默认1小时,60*60=3600
-     */
-    private Long expireSecond = CommonConstant.JWT_DEFAULT_EXPIRE_SECOND;
-
-    /**
-     * 是否刷新token,默认为true
-     */
-    private boolean refreshToken = true;
-
-    /**
-     * 刷新token倒计时,默认10分钟,10*60=600
-     */
-    private Integer refreshTokenCountdown;
-
-    /**
-     * redis校验jwt token是否存在
-     */
-    private boolean redisCheck;
-
-    /**
-     * 单用户登录,一个用户只能又一个有效的token
-     */
-    private boolean singleLogin;
-
-    /**
-     * 是否进行盐值校验
-     */
-    private boolean saltCheck;
-
-}

+ 0 - 27
src/main/java/com/xet/properties/ShiroPermissionProperties.java

@@ -1,27 +0,0 @@
-
-
-package com.xet.properties;
-
-import lombok.Data;
-
-/**
- * Shiro权限配置映射类
- **/
-@Data
-public class ShiroPermissionProperties {
-
-    /**
-     * 路径
-     */
-    private String url;
-    /**
-     * 路径数组
-     */
-    private String[] urls;
-
-    /**
-     * 权限
-     */
-    private String permission;
-
-}

+ 0 - 39
src/main/java/com/xet/properties/ShiroProperties.java

@@ -1,39 +0,0 @@
-
-
-package com.xet.properties;
-
-import lombok.Data;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.boot.context.properties.NestedConfigurationProperty;
-
-import java.util.List;
-
-/**
- * Shiro配置映射类
- **/
-@Data
-@ConfigurationProperties(prefix = "spring-boot-futu.shiro")
-public class ShiroProperties {
-
-    /**
-     * 是否启用
-     */
-    private boolean enable;
-
-    /**
-     * 路径权限配置
-     */
-    private String filterChainDefinitions;
-
-    /**
-     * 设置无需权限路径集合
-     */
-    private List<String[]> anon;
-
-    /**
-     * 权限配置集合
-     */
-    @NestedConfigurationProperty
-    private List<ShiroPermissionProperties> permission;
-
-}

+ 0 - 29
src/main/java/com/xet/shiro/config/JwtCredentialsMatcher.java

@@ -1,29 +0,0 @@
-
-
-package com.xet.shiro.config;
-
-import com.xet.shiro.utils.JwtUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.shiro.authc.AuthenticationInfo;
-import org.apache.shiro.authc.AuthenticationToken;
-import org.apache.shiro.authc.credential.CredentialsMatcher;
-
-/**
- * JWT证书匹配
- **/
-@Slf4j
-public class JwtCredentialsMatcher implements CredentialsMatcher {
-
-    @Override
-    public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) {
-        String token = authenticationToken.getCredentials().toString();
-        String salt = authenticationInfo.getCredentials().toString();
-        try {
-            return JwtUtil.verifyToken(token, salt);
-        } catch (Exception e) {
-            log.error("JWT Token CredentialsMatch Exception:" + e.getMessage(), e);
-        }
-        return false;
-    }
-
-}

+ 0 - 169
src/main/java/com/xet/shiro/config/JwtFilter.java

@@ -1,169 +0,0 @@
-package com.xet.shiro.config;
-
-import com.xet.properties.JwtProperties;
-import com.xet.shiro.utils.JwtToken;
-import com.xet.shiro.utils.JwtTokenUtil;
-import com.xet.shiro.utils.JwtUtil;
-import com.xet.shiro.utils.SaltUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shiro.authc.AuthenticationException;
-import org.apache.shiro.authc.AuthenticationToken;
-import org.apache.shiro.subject.Subject;
-import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
-import org.apache.shiro.web.servlet.ShiroHttpServletRequest;
-import org.apache.shiro.web.util.WebUtils;
-
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * Shiro JWT授权过滤器
- **/
-@Slf4j
-public class JwtFilter extends AuthenticatingFilter {
-    private JwtProperties jwtProperties;
-
-    public JwtFilter(   JwtProperties jwtProperties) {
-         this.jwtProperties = jwtProperties;
-    }
-
-    /**
-     * 将JWT Token包装成AuthenticationToken
-     *
-     * @param servletRequest
-     * @param servletResponse
-     * @return
-     * @throws Exception
-     */
-    @Override
-    protected AuthenticationToken createToken(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
-        String url = ((ShiroHttpServletRequest) servletRequest).getRequestURI();
-        String model = JwtTokenUtil.getModel(url);
-        String token = JwtTokenUtil.getToken(model);
-        if (StringUtils.isBlank(token)) {
-            throw new AuthenticationException("token不能为空");
-        }
-        if (JwtUtil.isExpired(token)) {
-            throw new AuthenticationException("JWT Token已过期,token:" + token);
-        }
-
-        // 如果开启redis二次校验,或者设置为单个用户token登录,则先在redis中判断token是否存在
-        if (jwtProperties.isRedisCheck() || jwtProperties.isSingleLogin()) {
-            boolean redisExpired = false;
-//            if(url.startsWith("/api/admin/")){
-//                redisExpired = adminLoginRedisService.exists(token);
-//            }else if(url.startsWith("/api/shop/")){
-//                redisExpired = shopLoginRedisService.exists(token);
-//            }else if(url.startsWith("/api/supplier/")){
-//                redisExpired = supplierLoginRedisService.exists(token);
-//            }else if(url.startsWith("/api/service/")){
-//                redisExpired = serviceLoginRedisService.exists(token);
-//            }
-//            if (!redisExpired) {
-//                throw new AuthenticationException("Redis Token不存在,token:" + token);
-//            }
-        }
-
-        String username = JwtUtil.getUsername(token);
-        String salt = SaltUtil.getSalt("futuvip", String.valueOf(jwtProperties));
-        if (jwtProperties.isSaltCheck()) {
-//            if(url.startsWith("/api/admin/")) {
-//                salt = adminLoginRedisService.getSalt(username);
-//            }else if(url.startsWith("/api/shop/")){
-//                salt = shopLoginRedisService.getSalt(username);
-//            }else if(url.startsWith("/api/supplier/")){
-//                salt = supplierLoginRedisService.getSalt(username);
-//            }else if(url.startsWith("/api/service/")){
-//                salt = serviceLoginRedisService.getSalt(username);
-//            }
-        } else {
-            salt = jwtProperties.getSecret();
-        }
-        return JwtToken.build(token, username, salt, jwtProperties.getExpireSecond());
-    }
-
-    /**
-     * 访问失败处理
-     *
-     * @param request
-     * @param response
-     * @return
-     * @throws Exception
-     */
-    @Override
-    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
-        HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
-        HttpServletResponse httpServletResponse = WebUtils.toHttp(response);
-        // 返回-1未登录
-        String url = httpServletRequest.getRequestURI();
-        log.error("onAccessDenied url:{}", url);
-//        ApiResult<Boolean> apiResult = ApiResult.fail(ApiCode.NOT_LOGIN);
-//        HttpServletResponseUtil.printJson(httpServletResponse, apiResult);
-        return false;
-    }
-
-    /**
-     * 判断是否允许访问
-     *
-     * @param request
-     * @param response
-     * @param mappedValue
-     * @return
-     */
-    @Override
-    protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
-        String url = WebUtils.toHttp(request).getRequestURI();
-        log.debug("isAccessAllowed url:{}", url);
-        if (this.isLoginRequest(request, response)) {
-            return true;
-        }
-        boolean allowed = false;
-        try {
-            allowed = executeLogin(request, response);
-        } catch (IllegalStateException e) { //not found any token
-            log.error("Token不能为空", e);
-        } catch (Exception e) {
-            log.error("访问错误", e);
-        }
-        return allowed || super.isPermissive(mappedValue);
-    }
-
-    /**
-     * 登录成功处理
-     *
-     * @param token
-     * @param subject
-     * @param request
-     * @param response
-     * @return
-     * @throws Exception
-     */
-    @Override
-    protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request, ServletResponse response) throws Exception {
-        String url = WebUtils.toHttp(request).getRequestURI();
-        log.debug("鉴权成功,token:{},url:{}", token, url);
-        // 刷新token
-        JwtToken jwtToken = (JwtToken) token;
-        HttpServletResponse httpServletResponse = WebUtils.toHttp(response);
-//        shiroLoginService.refreshToken(jwtToken, url, httpServletResponse);
-        return true;
-    }
-
-    /**
-     * 登录失败处理
-     *
-     * @param token
-     * @param e
-     * @param request
-     * @param response
-     * @return
-     */
-    @Override
-    protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request, ServletResponse response) {
-        log.error("登录失败,token:" + token + ",error:" + e.getMessage(), e);
-        return false;
-    }
-}

+ 0 - 99
src/main/java/com/xet/shiro/config/JwtRealm.java

@@ -1,99 +0,0 @@
-
-
-package com.xet.shiro.config;
-
-import com.xet.shiro.utils.JwtToken;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shiro.authc.AuthenticationException;
-import org.apache.shiro.authc.AuthenticationInfo;
-import org.apache.shiro.authc.AuthenticationToken;
-import org.apache.shiro.authc.SimpleAuthenticationInfo;
-import org.apache.shiro.authz.AuthorizationInfo;
-import org.apache.shiro.authz.SimpleAuthorizationInfo;
-import org.apache.shiro.realm.AuthorizingRealm;
-import org.apache.shiro.subject.PrincipalCollection;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import javax.servlet.http.HttpServletRequest;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Shiro 授权认证
- **/
-@Slf4j
-public class JwtRealm extends AuthorizingRealm {
-
-
-
-    @Autowired
-    private HttpServletRequest request;
-
-    @Override
-    public boolean supports(AuthenticationToken token) {
-        return token != null && token instanceof JwtToken;
-    }
-
-    /**
-     * 授权认证,设置角色/权限信息
-     *
-     * @param principalCollection
-     * @return
-     */
-    @Override
-    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
-        log.debug("doGetAuthorizationInfo principalCollection..."+request.getRequestURI());
-        // 设置角色/权限信息
-        JwtToken jwtToken = (JwtToken) principalCollection.getPrimaryPrincipal();
-        // 获取username
-        String username = jwtToken.getUsername();
-        SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
-        //这里应是查数据库
-        Map<String,Set<String>> map=new HashMap<>();
-        Set<String> permissions=new HashSet<>();
-        permissions.add("emp:get");
-        permissions.add("emp:add");
-        map.put("admin",permissions);
-        Set<String> pw=new HashSet<>();
-        pw.add("emp:add");
-        map.put("user001",pw);
-
-       Set<String>user_permission= map.get(username);
-       if(!user_permission.isEmpty()) {
-           authorizationInfo.setStringPermissions(user_permission);
-       }
-
-        return authorizationInfo;
-    }
-
-    /**
-     * 登录认证
-     *
-     * @param authenticationToken
-     * @return
-     * @throws AuthenticationException
-     */
-    @Override
-    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
-        log.debug("doGetAuthenticationInfo authenticationToken...");
-        // 校验token
-        JwtToken jwtToken = (JwtToken) authenticationToken;
-        if (jwtToken == null) {
-            throw new AuthenticationException("jwtToken不能为空");
-        }
-        String salt = jwtToken.getSalt();
-        if (StringUtils.isBlank(salt)) {
-            throw new AuthenticationException("salt不能为空");
-        }
-        return new SimpleAuthenticationInfo(
-                jwtToken,
-                salt,
-                getName()
-        );
-
-    }
-
-}

+ 0 - 294
src/main/java/com/xet/shiro/config/ShiroConfig.java

@@ -1,294 +0,0 @@
-
-
-package com.xet.shiro.config;
-
-import com.alibaba.fastjson.JSON;
-import com.xet.properties.JwtProperties;
-import com.xet.properties.ShiroPermissionProperties;
-import com.xet.properties.ShiroProperties;
-import com.xet.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;
-    }
-
-}

+ 0 - 79
src/main/java/com/xet/shiro/utils/JwtToken.java

@@ -1,79 +0,0 @@
-
-
-package com.xet.shiro.utils;
-
-import com.auth0.jwt.interfaces.DecodedJWT;
-import com.xet.util.IpUtil;
-import lombok.Data;
-import lombok.experimental.Accessors;
-import org.apache.shiro.authc.HostAuthenticationToken;
-
-import java.util.Date;
-
-/**
- * Shiro JwtToken对象
- **/
-@Data
-@Accessors(chain = true)
-public class JwtToken implements HostAuthenticationToken {
-	private static final long serialVersionUID = 5101247566043093405L;
-
-	/**
-     * 登录ip
-     */
-    private String host;
-    /**
-     * 登录用户名称
-     */
-    private String username;
-    /**
-     * 登录盐值
-     */
-    private String salt;
-    /**
-     * 登录token
-     */
-    private String token;
-    /**
-     * 创建时间
-     */
-    private Date createDate;
-    /**
-     * 多长时间过期,默认一小时
-     */
-    private long expireSecond;
-    /**
-     * 过期日期
-     */
-    private Date expireDate;
-
-    private String principal;
-
-    private String credentials;
-
-    @Override
-    public Object getPrincipal() {
-        return token;
-    }
-
-    @Override
-    public Object getCredentials() {
-        return token;
-    }
-
-    public static JwtToken build(String token, String username, String salt, long expireSecond) {
-        DecodedJWT decodedJwt = JwtUtil.getJwtInfo(token);
-        Date createDate = decodedJwt.getIssuedAt();
-        Date expireDate = decodedJwt.getExpiresAt();
-        return new JwtToken()
-                .setUsername(username)
-                .setToken(token)
-                .setHost(IpUtil.getRequestIp())
-                .setSalt(salt)
-                .setCreateDate(createDate)
-                .setExpireSecond(expireSecond)
-                .setExpireDate(expireDate);
-
-    }
-
-}

+ 0 - 87
src/main/java/com/xet/shiro/utils/JwtTokenUtil.java

@@ -1,87 +0,0 @@
-
-
-package com.xet.shiro.utils;
-
-import com.xet.properties.JwtProperties;
-import com.xet.util.HttpServletRequestUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.stereotype.Component;
-
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * JwtToken工具类
- **/
-@Slf4j
-@Component
-public class  JwtTokenUtil {
-
-    private static String tokenName;
-
-    public JwtTokenUtil(JwtProperties jwtProperties) {
-        tokenName = jwtProperties.getTokenName();
-        log.debug("tokenName:{}", tokenName);
-    }
-
-    /**
-     * 获取token名称
-     *
-     * @return
-     */
-    public static String getTokenName(String model) {
-        if(model.equals("")){
-            return tokenName;
-        }else{
-            return tokenName + "" + model;
-        }
-    }
-
-    /**
-     * 从请求头或者请求参数中
-     *
-     * @return
-     */
-    public static String getToken(String model) {
-        return getToken(HttpServletRequestUtil.getRequest(), model);
-    }
-
-    public static String getModel(String path){
-        String model = "";
-        if(path.startsWith("/api/admin/")){
-            model = "admin";
-        }else if(path.startsWith("/api/shop/")){
-            model = "shop";
-        }else if(path.startsWith("/api/supplier/")) {
-            model = "supplier";
-        }else if(path.startsWith("/api/service/")){
-            model = "service";
-        }
-        return model;
-    }
-
-    /**
-     * 从请求头或者请求参数中
-     *
-     * @param request
-     * @return
-     */
-    public static String getToken(HttpServletRequest request, String model) {
-        if (request == null) {
-            throw new IllegalArgumentException("request不能为空");
-        }
-        String realTokenName = "";
-        if(model.equals("")){
-            realTokenName = tokenName;
-        }else{
-            realTokenName = tokenName + "" + model;
-        }
-        // 从请求头中获取token
-        String token = request.getHeader(realTokenName);
-        if (StringUtils.isBlank(token)) {
-            // 从请求参数中获取token
-            token = request.getParameter(realTokenName);
-        }
-        return token;
-    }
-}

+ 0 - 186
src/main/java/com/xet/shiro/utils/JwtUtil.java

@@ -1,186 +0,0 @@
-
-
-package com.xet.shiro.utils;
-
-import com.alibaba.fastjson.JSON;
-import com.auth0.jwt.JWT;
-import com.auth0.jwt.JWTVerifier;
-import com.auth0.jwt.algorithms.Algorithm;
-import com.auth0.jwt.interfaces.DecodedJWT;
-import com.xet.constants.CommonConstant;
-import com.xet.properties.JwtProperties;
-import com.xet.util.UUIDUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.time.DateUtils;
-import org.springframework.stereotype.Component;
-
-import java.time.Duration;
-import java.util.Date;
-
-/**
- * JWT工具类
- * https://github.com/auth0/java-jwt
- **/
-@Slf4j
-@Component
-public class JwtUtil {
-
-    private static JwtProperties jwtProperties;
-
-    public JwtUtil(JwtProperties jwtProperties) {
-        JwtUtil.jwtProperties = jwtProperties;
-        log.info(JSON.toJSONString(JwtUtil.jwtProperties));
-    }
-
-    /**
-     * 生成JWT Token
-     *
-     * @param username       用户名
-     * @param salt           盐值
-     * @param expireDuration 过期时间和单位
-     * @return token
-     */
-    public static String generateToken(String username, String salt, Duration expireDuration) {
-        try {
-            if (StringUtils.isBlank(username)) {
-                log.error("username不能为空");
-                return null;
-            }
-            log.debug("username:{}", username);
-
-            // 如果盐值为空,则使用默认值:888888
-            if (StringUtils.isBlank(salt)) {
-                salt = jwtProperties.getSecret();
-            }
-            log.debug("salt:{}", salt);
-
-            // 过期时间,单位:秒
-            Long expireSecond;
-            // 默认过期时间为1小时
-            if (expireDuration == null) {
-                expireSecond = jwtProperties.getExpireSecond();
-            } else {
-                expireSecond = expireDuration.getSeconds();
-            }
-            log.debug("expireSecond:{}", expireSecond);
-            Date expireDate = DateUtils.addSeconds(new Date(), expireSecond.intValue());
-            log.debug("expireDate:{}", expireDate);
-
-            // 生成token
-            Algorithm algorithm = Algorithm.HMAC256(salt);
-            String token = JWT.create()
-                    .withClaim(CommonConstant.JWT_USERNAME, username)
-                    // jwt唯一id
-                    .withJWTId(UUIDUtil.getUuid())
-                    // 签发人
-                    .withIssuer(jwtProperties.getIssuer())
-                    // 主题
-                    .withSubject(jwtProperties.getSubject())
-                    // 签发的目标
-                    .withAudience(jwtProperties.getAudience())
-                    // 签名时间
-                    .withIssuedAt(new Date())
-                    // token过期时间
-                    .withExpiresAt(expireDate)
-                    // 签名
-                    .sign(algorithm);
-            return token;
-        } catch (Exception e) {
-            log.error("generateToken exception", e);
-        }
-        return null;
-    }
-
-    public static boolean verifyToken(String token, String salt) {
-        try {
-            Algorithm algorithm = Algorithm.HMAC256(salt);
-            JWTVerifier verifier = JWT.require(algorithm)
-                    // 签发人
-                    .withIssuer(jwtProperties.getIssuer())
-                    // 主题
-                    .withSubject(jwtProperties.getSubject())
-                    // 签发的目标
-                    .withAudience(jwtProperties.getAudience())
-                    .build();
-            DecodedJWT jwt = verifier.verify(token);
-            if (jwt != null) {
-                return true;
-            }
-        } catch (Exception e) {
-            log.error("Verify Token Exception", e);
-        }
-        return false;
-    }
-
-    /**
-     * 解析token,获取token数据
-     *
-     * @param token
-     * @return
-     */
-    public static DecodedJWT getJwtInfo(String token) {
-        return JWT.decode(token);
-    }
-
-    /**
-     * 获取用户名
-     *
-     * @param token
-     * @return
-     */
-    public static String getUsername(String token) {
-        if (StringUtils.isBlank(token)){
-            return null;
-        }
-        DecodedJWT decodedJwt = getJwtInfo(token);
-        if (decodedJwt == null) {
-            return null;
-        }
-        String username = decodedJwt.getClaim(CommonConstant.JWT_USERNAME).asString();
-        return username;
-    }
-
-    /**
-     * 获取创建时间
-     *
-     * @param token
-     * @return
-     */
-    public static Date getIssuedAt(String token) {
-        DecodedJWT decodedJwt = getJwtInfo(token);
-        if (decodedJwt == null) {
-            return null;
-        }
-        return decodedJwt.getIssuedAt();
-    }
-
-    /**
-     * 获取过期时间
-     *
-     * @param token
-     * @return
-     */
-    public static Date getExpireDate(String token) {
-        DecodedJWT decodedJwt = getJwtInfo(token);
-        if (decodedJwt == null) {
-            return null;
-        }
-        return decodedJwt.getExpiresAt();
-    }
-
-    /**
-     * 判断token是否已过期
-     *
-     * @param token
-     * @return
-     */
-    public static boolean isExpired(String token) {
-        Date expireDate = getExpireDate(token);
-        if (expireDate == null) {
-            return true;
-        }
-        return expireDate.before(new Date());
-    }
-
-}

+ 0 - 59
src/main/java/com/xet/shiro/utils/SaltUtil.java

@@ -1,59 +0,0 @@
-
-
-package com.xet.shiro.utils;
-
-import com.xet.properties.JwtProperties;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shiro.crypto.SecureRandomNumberGenerator;
-import org.springframework.util.DigestUtils;
-
-/**
- * 盐值包装工具类
- **/
-public class SaltUtil {
-
-    /**
-     * 盐值包装
-     *
-     * @param secret 配置文件中配置的附加盐值
-     * @param salt   数据库中保存的盐值
-     * @return
-     */
-    public static String getSalt(String secret, String salt) {
-        if (StringUtils.isBlank(secret) && StringUtils.isBlank(salt)) {
-            return null;
-        }
-        // 加密方法
-        String newSalt = DigestUtils.md5DigestAsHex((secret + salt).getBytes());
-        return newSalt;
-    }
-
-    /**
-     * 生成6位随机盐
-     *
-     * @return
-     */
-    public static String generateSalt() {
-        return new SecureRandomNumberGenerator().nextBytes(3).toHex();
-    }
-
-    /**
-     * 加工盐值
-     *
-     * @param salt
-     * @param jwtProperties
-     * @return
-     */
-    public static String getSalt(String salt, JwtProperties jwtProperties) {
-        String newSalt;
-        if (jwtProperties.isSaltCheck()) {
-            // 包装盐值
-            newSalt = SaltUtil.getSalt(jwtProperties.getSecret(), salt);
-        } else {
-            newSalt = jwtProperties.getSecret();
-        }
-        return newSalt;
-    }
-
-}
-

+ 47 - 0
src/main/java/com/xet/user/controller/LoginController.java

@@ -0,0 +1,47 @@
+package com.xet.user.controller;
+
+import com.xet.domain.user.dto.LoginDto;
+import com.xet.domain.user.dto.WxLoginDto;
+import com.xet.user.service.UserService;
+import com.xet.util.jie.ResultVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Date 2025/5/5 20:03
+ * @Author neko
+ **/
+@RestController
+@RequestMapping("/users")
+public class LoginController {
+    @Autowired
+    UserService userService;
+
+    /*
+     * 手机号 密码/验证码 登录
+     */
+    @RequestMapping("phone_login")
+    public ResultVo phoneLogin(@RequestBody LoginDto loginDto){
+        return userService.phoneLogin(loginDto);
+    }
+
+    /*
+     * 微信一键登录
+     */
+    @RequestMapping("wx_login")
+    public ResultVo wxLogin(@RequestBody WxLoginDto wxLoginDto){
+        return userService.wxLogin(wxLoginDto);
+    }
+
+
+    /*
+    * 获取验证码
+    */
+    @RequestMapping("yan")
+    public ResultVo yan(String phone){
+        return userService.yan(phone);
+    }
+
+}

+ 13 - 0
src/main/java/com/xet/user/mapper/UserMapper.java

@@ -0,0 +1,13 @@
+package com.xet.user.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.xet.domain.user.pojo.Users;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @Date 2025/5/5 20:03
+ * @Author neko
+ **/
+@Mapper
+public interface UserMapper extends BaseMapper<Users> {
+}

+ 17 - 0
src/main/java/com/xet/user/service/UserService.java

@@ -0,0 +1,17 @@
+package com.xet.user.service;
+
+import com.xet.domain.user.dto.LoginDto;
+import com.xet.domain.user.dto.WxLoginDto;
+import com.xet.util.jie.ResultVo;
+
+/**
+ * @Date 2025/5/5 20:04
+ * @Author neko
+ **/
+public interface UserService {
+    ResultVo phoneLogin(LoginDto loginDto);
+
+    ResultVo yan(String phone);
+
+    ResultVo wxLogin(WxLoginDto wxLoginDto);
+}

+ 130 - 0
src/main/java/com/xet/user/service/impl/UserServiceImpl.java

@@ -0,0 +1,130 @@
+package com.xet.user.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.xet.domain.user.dto.LoginDto;
+import com.xet.domain.user.dto.WxLoginDto;
+import com.xet.domain.user.pojo.Users;
+import com.xet.user.mapper.UserMapper;
+import com.xet.user.service.UserService;
+import com.xet.util.HttpUtils;
+import com.xet.util.jie.ApiServiceExceptionEnum;
+import com.xet.util.jie.ResultVo;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpResponse;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.DigestUtils;
+import org.springframework.util.StringUtils;
+
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+
+/**
+ * @Date 2025/5/5 20:04
+ * @Author neko
+ **/
+@Slf4j
+@Service
+public class UserServiceImpl implements UserService {
+    @Autowired
+    UserMapper userMapper;
+
+    @Override
+    public ResultVo phoneLogin(LoginDto loginDto) {
+        if(StringUtils.isEmpty(loginDto.getPhone())){
+            return ResultVo.error(ApiServiceExceptionEnum.PHONE_NOTNULL);
+        }
+        if(loginDto.getPassword()!=null){
+            log.info("手机号密码登录",loginDto.getPhone());
+            QueryWrapper<Users> queryWrapper = new QueryWrapper<>();
+            queryWrapper.lambda().eq(Users::getPhone,loginDto.getPhone());
+            Users u = userMapper.selectOne(queryWrapper);
+            String salt = u.getSalt();
+            String md5Pwd = DigestUtils.md5DigestAsHex((salt+loginDto.getPassword()).getBytes(StandardCharsets.UTF_8));
+            if(!loginDto.getPhone().matches("^1[3-9]\\d{9}$")){
+                return ResultVo.error(ApiServiceExceptionEnum.PHONE_ERROR);
+            }
+            if(!md5Pwd.equals(u.getPassword())){
+                return ResultVo.error(ApiServiceExceptionEnum.PASSWORD_ERROR);
+            }
+
+            String token = "";
+            Map<String, Object> map = new HashMap<>();
+            map.put("token",token);
+            return ResultVo.success();
+        }else{
+            log.info("手机号验证码 登录/注册"+loginDto.getPhone());
+            if(!loginDto.getPhone().matches("^1[3-9]\\d{9}$")){
+                return ResultVo.error(ApiServiceExceptionEnum.PHONE_ERROR);
+            }
+
+            QueryWrapper<Users> queryWrapper = new QueryWrapper<>();
+            queryWrapper.lambda().eq(Users::getPhone,loginDto.getPhone());
+            Users u = userMapper.selectOne(queryWrapper);
+            if(u==null){
+                Users users = new Users();
+                users.setPhone(loginDto.getPhone());
+                users.setNickname("用户"+loginDto.getPhone());
+                userMapper.insert(users);
+                log.info("新用户注册成功"+users.getNickname());
+            }
+
+            String token = "";
+            Map<String, Object> map = new HashMap<>();
+            map.put("token",token);
+            return ResultVo.success();
+        }
+
+    }
+
+    @Override
+    public ResultVo yan(String phone) {
+        String host = "https://gyytz.market.alicloudapi.com";
+        String path = "/sms/smsSend";
+        String method = "POST";
+        String appcode = "8e678d7c72f14e9193e29747f9d73a6d";
+        Map<String, String> headers = new HashMap<String, String>();
+        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
+        headers.put("Authorization", "APPCODE " + appcode);
+//        System.err.println(phone);
+
+        //生成一个随机6位的验证码
+        Random random = new Random();
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < 6; i++) {
+            int digit = random.nextInt(10);
+            sb.append(digit);
+        }
+        String sixDigitNumber = sb.toString();
+
+        Map<String, String> querys = new HashMap<String, String>();
+        querys.put("mobile", phone);
+        querys.put("param", "**code**:"+sixDigitNumber+",**minute**:6");
+
+        querys.put("smsSignId", "2e65b1bb3d054466b82f0c9d125465e2");
+        querys.put("templateId", "908e94ccf08b4476ba6c876d13f084ad");
+        Map<String, String> bodys = new HashMap<String, String>();
+
+
+        try {
+            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
+            System.out.println(response.toString());
+            //获取response的body
+            //System.out.println(EntityUtils.toString(response.getEntity()));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return ResultVo.success("短信发送成功");
+    }
+
+    @Override
+    public ResultVo wxLogin(WxLoginDto wxLoginDto) {
+
+        return null;
+    }
+
+
+}

+ 311 - 0
src/main/java/com/xet/util/HttpUtils.java

@@ -0,0 +1,311 @@
+package com.xet.util;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.message.BasicNameValuePair;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class HttpUtils {
+
+	/**
+	 * get
+	 *
+	 * @param host
+	 * @param path
+	 * @param method
+	 * @param headers
+	 * @param querys
+	 * @return
+	 * @throws Exception
+	 */
+	public static HttpResponse doGet(String host, String path, String method,
+			Map<String, String> headers,
+			Map<String, String> querys)
+            throws Exception {
+    	HttpClient httpClient = wrapClient(host);
+
+    	HttpGet request = new HttpGet(buildUrl(host, path, querys));
+        for (Map.Entry<String, String> e : headers.entrySet()) {
+        	request.addHeader(e.getKey(), e.getValue());
+        }
+
+        return httpClient.execute(request);
+    }
+
+	/**
+	 * post form
+	 *
+	 * @param host
+	 * @param path
+	 * @param method
+	 * @param headers
+	 * @param querys
+	 * @param bodys
+	 * @return
+	 * @throws Exception
+	 */
+	public static HttpResponse doPost(String host, String path, String method,
+			Map<String, String> headers,
+			Map<String, String> querys,
+			Map<String, String> bodys)
+            throws Exception {
+    	HttpClient httpClient = wrapClient(host);
+
+    	HttpPost request = new HttpPost(buildUrl(host, path, querys));
+        for (Map.Entry<String, String> e : headers.entrySet()) {
+        	request.addHeader(e.getKey(), e.getValue());
+        }
+
+        if (bodys != null) {
+            List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
+
+            for (String key : bodys.keySet()) {
+                nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
+            }
+            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
+            formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
+            request.setEntity(formEntity);
+        }
+
+        return httpClient.execute(request);
+    }
+
+	/**
+	 * Post String
+	 *
+	 * @param host
+	 * @param path
+	 * @param method
+	 * @param headers
+	 * @param querys
+	 * @param body
+	 * @return
+	 * @throws Exception
+	 */
+	public static HttpResponse doPost(String host, String path, String method,
+			Map<String, String> headers,
+			Map<String, String> querys,
+			String body)
+            throws Exception {
+    	HttpClient httpClient = wrapClient(host);
+
+    	HttpPost request = new HttpPost(buildUrl(host, path, querys));
+        for (Map.Entry<String, String> e : headers.entrySet()) {
+        	request.addHeader(e.getKey(), e.getValue());
+        }
+
+        if (StringUtils.isNotBlank(body)) {
+        	request.setEntity(new StringEntity(body, "utf-8"));
+        }
+
+        return httpClient.execute(request);
+    }
+
+	/**
+	 * Post stream
+	 *
+	 * @param host
+	 * @param path
+	 * @param method
+	 * @param headers
+	 * @param querys
+	 * @param body
+	 * @return
+	 * @throws Exception
+	 */
+	public static HttpResponse doPost(String host, String path, String method,
+			Map<String, String> headers,
+			Map<String, String> querys,
+			byte[] body)
+            throws Exception {
+    	HttpClient httpClient = wrapClient(host);
+
+    	HttpPost request = new HttpPost(buildUrl(host, path, querys));
+        for (Map.Entry<String, String> e : headers.entrySet()) {
+        	request.addHeader(e.getKey(), e.getValue());
+        }
+
+        if (body != null) {
+        	request.setEntity(new ByteArrayEntity(body));
+        }
+
+        return httpClient.execute(request);
+    }
+
+	/**
+	 * Put String
+	 * @param host
+	 * @param path
+	 * @param method
+	 * @param headers
+	 * @param querys
+	 * @param body
+	 * @return
+	 * @throws Exception
+	 */
+	public static HttpResponse doPut(String host, String path, String method,
+			Map<String, String> headers,
+			Map<String, String> querys,
+			String body)
+            throws Exception {
+    	HttpClient httpClient = wrapClient(host);
+
+    	HttpPut request = new HttpPut(buildUrl(host, path, querys));
+        for (Map.Entry<String, String> e : headers.entrySet()) {
+        	request.addHeader(e.getKey(), e.getValue());
+        }
+
+        if (StringUtils.isNotBlank(body)) {
+        	request.setEntity(new StringEntity(body, "utf-8"));
+        }
+
+        return httpClient.execute(request);
+    }
+
+	/**
+	 * Put stream
+	 * @param host
+	 * @param path
+	 * @param method
+	 * @param headers
+	 * @param querys
+	 * @param body
+	 * @return
+	 * @throws Exception
+	 */
+	public static HttpResponse doPut(String host, String path, String method,
+			Map<String, String> headers,
+			Map<String, String> querys,
+			byte[] body)
+            throws Exception {
+    	HttpClient httpClient = wrapClient(host);
+
+    	HttpPut request = new HttpPut(buildUrl(host, path, querys));
+        for (Map.Entry<String, String> e : headers.entrySet()) {
+        	request.addHeader(e.getKey(), e.getValue());
+        }
+
+        if (body != null) {
+        	request.setEntity(new ByteArrayEntity(body));
+        }
+
+        return httpClient.execute(request);
+    }
+
+	/**
+	 * Delete
+	 *
+	 * @param host
+	 * @param path
+	 * @param method
+	 * @param headers
+	 * @param querys
+	 * @return
+	 * @throws Exception
+	 */
+	public static HttpResponse doDelete(String host, String path, String method,
+			Map<String, String> headers,
+			Map<String, String> querys)
+            throws Exception {
+    	HttpClient httpClient = wrapClient(host);
+
+    	HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
+        for (Map.Entry<String, String> e : headers.entrySet()) {
+        	request.addHeader(e.getKey(), e.getValue());
+        }
+
+        return httpClient.execute(request);
+    }
+
+	private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
+    	StringBuilder sbUrl = new StringBuilder();
+    	sbUrl.append(host);
+    	if (!StringUtils.isBlank(path)) {
+    		sbUrl.append(path);
+        }
+    	if (null != querys) {
+    		StringBuilder sbQuery = new StringBuilder();
+        	for (Map.Entry<String, String> query : querys.entrySet()) {
+        		if (0 < sbQuery.length()) {
+        			sbQuery.append("&");
+        		}
+        		if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
+        			sbQuery.append(query.getValue());
+                }
+        		if (!StringUtils.isBlank(query.getKey())) {
+        			sbQuery.append(query.getKey());
+        			if (!StringUtils.isBlank(query.getValue())) {
+        				sbQuery.append("=");
+        				sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
+        			}
+                }
+        	}
+        	if (0 < sbQuery.length()) {
+        		sbUrl.append("?").append(sbQuery);
+        	}
+        }
+
+    	return sbUrl.toString();
+    }
+
+	private static HttpClient wrapClient(String host) {
+		HttpClient httpClient = new DefaultHttpClient();
+		if (host.startsWith("https://")) {
+			sslClient(httpClient);
+		}
+
+		return httpClient;
+	}
+
+	private static void sslClient(HttpClient httpClient) {
+        try {
+            SSLContext ctx = SSLContext.getInstance("TLS");
+            X509TrustManager tm = new X509TrustManager() {
+                public X509Certificate[] getAcceptedIssuers() {
+                    return null;
+                }
+                public void checkClientTrusted(X509Certificate[] xcs, String str) {
+
+                }
+                public void checkServerTrusted(X509Certificate[] xcs, String str) {
+
+                }
+            };
+            ctx.init(null, new TrustManager[] { tm }, null);
+            SSLSocketFactory ssf = new SSLSocketFactory(ctx);
+            ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+            ClientConnectionManager ccm = httpClient.getConnectionManager();
+            SchemeRegistry registry = ccm.getSchemeRegistry();
+            registry.register(new Scheme("https", 443, ssf));
+        } catch (KeyManagementException ex) {
+            throw new RuntimeException(ex);
+        } catch (NoSuchAlgorithmException ex) {
+        	throw new RuntimeException(ex);
+        }
+    }
+}

+ 22 - 0
src/main/java/com/xet/util/jie/ApiException.java

@@ -0,0 +1,22 @@
+package com.xet.util.jie;
+
+import lombok.Data;
+
+
+@Data
+public class ApiException extends RuntimeException{
+
+	public Integer code;
+	public String msg;
+	public ApiException(BaseExceptionEnum baseExceptionEnum) {
+		super(baseExceptionEnum.getMessage());
+		this.code = baseExceptionEnum.getCode();
+		this.msg = baseExceptionEnum.getMessage();
+	}
+	public ApiException(Integer code, String message) {
+		super(message);
+		this.code=code;
+		this.msg=message;
+	}
+
+}

+ 46 - 0
src/main/java/com/xet/util/jie/ApiServiceExceptionEnum.java

@@ -0,0 +1,46 @@
+package com.xet.util.jie;
+
+public enum ApiServiceExceptionEnum implements BaseExceptionEnum{
+	SUCCESS(1, "成功"),
+	RESULT_SUCCES(1,"成功"),
+    RESULT_ERROR(0,"失败"),
+    Login_SUCCESS(1,"登录成功"),
+    Login_ERROR(0,"登录失败"),
+    REG_SUCCESS(1,"注册成功"),
+    REG_ERROR(0,"注册失败"),
+    ISEXISTS_ERROR(0,"已存在"),
+    SHOP_NOEXISTS_ERROR(1001,"店铺不存在"),
+    SHOP_AUDIT_STATUS(1010,"审核中"),
+    SHOP_AUDIT_REN(1010,"转人工"),
+    SHOP_AUDIT_ERROR(1011,"审核 失败"),
+    USER_NOT_EXISTS(1024,"用户不存在"),
+    DATA_NOT_EXISTS(1023,"数据不存在"),
+    PASSWORD_ERROR(1022,"密码错误"),
+    PHONE_ERROR(1021,"手机号错误"),
+    PHONE_NOTNULL(1020,"手机号不能为空");
+
+
+
+
+     ApiServiceExceptionEnum(Integer code , String message) {
+
+    	 this.code=code;
+    	 this.message=message;
+    }
+     private Integer code;
+
+     private String message;
+
+    @Override
+	public Integer getCode() {
+		// TODO Auto-generated method stub
+		return code;
+	}
+
+	@Override
+	public String getMessage() {
+		// TODO Auto-generated method stub
+		return message;
+	}
+
+}

+ 18 - 0
src/main/java/com/xet/util/jie/BaseExceptionEnum.java

@@ -0,0 +1,18 @@
+package com.xet.util.jie;
+
+/**
+ * 抽象接口
+ *
+ */
+public interface BaseExceptionEnum {
+
+    /**
+     * 获取异常编码
+     */
+    Integer getCode();
+
+    /**
+     * 获取异常信息
+     */
+    String getMessage();
+}

+ 66 - 0
src/main/java/com/xet/util/jie/ResultVo.java

@@ -0,0 +1,66 @@
+package com.xet.util.jie;
+
+import com.sun.org.apache.regexp.internal.RE;
+import lombok.Data;
+
+import java.awt.*;
+
+@Data
+public class ResultVo<T> {
+    private Integer code;
+    private String msg;
+    private  T obj;
+
+    public ResultVo(Integer code, String msg) {
+        this.code=code;
+        this.msg=msg;
+    }
+    public ResultVo() {}
+
+    public ResultVo(ApiServiceExceptionEnum dataNotExists) {
+        this.code=dataNotExists.getCode();
+        this.msg=dataNotExists.getMessage();
+    }
+
+    public static ResultVo success(Object object) {
+        ResultVo resultVO = new ResultVo(200,"成功");
+        resultVO.setObj(object);
+        return resultVO;
+    }
+    public static ResultVo success(Integer code,String msg,Object object) {
+        ResultVo resultVO = new ResultVo();
+        resultVO.setCode(code);
+        resultVO.setMsg(msg);
+        resultVO.setObj(object);
+        return resultVO;
+    }
+
+    public static ResultVo success() {
+        return success(null);
+    }
+    public static ResultVo error(Integer code, String msg) {
+        ResultVo resultVO = new ResultVo();
+        resultVO.setCode(code);
+        resultVO.setMsg(msg);
+        return resultVO;
+    }
+    public static ResultVo error(){
+        ResultVo resultVO=new ResultVo();
+        resultVO.setCode(0);
+        resultVO.setMsg("失败");
+        return resultVO;
+    }
+    public static ResultVo error(Integer code,String msg,Object obj){
+        ResultVo resultVO=new ResultVo();
+        resultVO.setCode(0);
+        resultVO.setMsg(msg);
+        resultVO.setObj(obj);
+        return resultVO;
+    }
+    public static ResultVo error(ApiServiceExceptionEnum apiServiceExceptionEnum){
+        ResultVo resultVO=new ResultVo();
+        resultVO.setCode(apiServiceExceptionEnum.getCode());
+        resultVO.setMsg(apiServiceExceptionEnum.getMessage());
+        return resultVO;
+    }
+}

+ 0 - 6
src/main/resources/static/index.html

@@ -1,6 +0,0 @@
-<html>
-<body>
-<h1>hello word!!!</h1>
-<p>this is a html page</p>
-</body>
-</html>