rk
16 小时以前 3e210fac9492b90e21ca9bf76c1d9a8fda1f4388
server/services/src/main/java/com/doumee/config/jwt/WebMvcConfig.java
@@ -7,9 +7,11 @@
import com.doumee.core.constants.Constants;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.dao.business.model.DriverInfo;
import com.doumee.dao.business.model.Member;
import com.doumee.dao.business.model.ShopInfo;
import io.jsonwebtoken.JwtException;
import lombok.extern.log4j.Log4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -26,6 +28,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;
import java.util.logging.Logger;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@@ -74,19 +77,19 @@
                    }
                }else if (beanType.isAnnotationPresent(LoginShopRequired.class)) {
                    //获取token
                    String token = request.getHeader(JwtTokenUtil.HEADER_KEY);  // 从 http 请求头中取出 token
                    String token = request.getHeader(JwtTokenUtil.SHOP_HEADER_KEY);  // 从 http 请求头中取出 token
                    if (StringUtils.isNotBlank(token)) {
                        checkShopLogin(request,response);
                        checkShopLogin(token,request,response);
                    } else {
                        throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"未登录");
                        throw new BusinessException(ResponseStatus.SHOP_BE_OVERDUE.getCode(),"未登录");
                    }
                }else if (handlerMethod.hasMethodAnnotation(LoginShopRequired.class)){
                    //获取token
                    String token = request.getHeader(JwtTokenUtil.HEADER_KEY);  // 从 http 请求头中取出 token
                    String token = request.getHeader(JwtTokenUtil.SHOP_HEADER_KEY);  // 从 http 请求头中取出 token
                    if (StringUtils.isNotBlank(token)) {
                        checkShopLogin(request,response);
                        checkShopLogin(token,request,response);
                    } else {
                        throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"未登录");
                        throw new BusinessException(ResponseStatus.SHOP_BE_OVERDUE.getCode(),"未登录");
                    }
                }else if (beanType.isAnnotationPresent(LoginDriverRequired.class)) {
                    //获取token
@@ -115,6 +118,7 @@
    public Boolean checkMemberLogin(HttpServletRequest request, HttpServletResponse response){
        String token = request.getHeader(JwtTokenUtil.HEADER_KEY);
        System.out.println("会员token:=========>{}"+token);
        try {
            if(!token.startsWith(Constants.ZERO+"")){
                throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME);
@@ -144,48 +148,45 @@
    }
    public Boolean checkShopLogin(HttpServletRequest request, HttpServletResponse response){
        String token = request.getHeader(JwtTokenUtil.HEADER_KEY);
    public Boolean checkShopLogin(String token,HttpServletRequest request, HttpServletResponse response){
        System.out.println("门店token:=========>{}"+token);
        try {
            if(!token.startsWith(Constants.TWO+"")){
                throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME);
                throw new BusinessException(ResponseStatus.SHOP_TOKEN_EXCEED_TIME);
            }
            String tokenRedis = (String) redisTemplate.opsForValue().get(Constants.REDIS_TOKEN_KEY+token);
            if(StringUtils.isBlank(tokenRedis)){
                throw new BusinessException(ResponseStatus.BE_OVERDUE);
                throw new BusinessException(ResponseStatus.SHOP_BE_OVERDUE);
            }
            ShopInfo shop = JSONObject.parseObject(tokenRedis, ShopInfo.class);
            if(Objects.isNull(shop)){
                throw new BusinessException(ResponseStatus.BE_OVERDUE);
                throw new BusinessException(ResponseStatus.SHOP_BE_OVERDUE);
            }
            String openid = shop.getOpenid();
            Integer shopId = getTokenId(token);
            Integer isDeleted = dao.queryForObject(" select COALESCE(DELETED,0)  from shop_info where id  = ?", Integer.class, shopId);
            Integer shopId = shop.getId();//getTokenId(token);
            Integer isDeleted = dao.queryForObject(" select COALESCE(DELETED,0)  from shop_info where VERSION_TYPE = 0 and  id  = ?", Integer.class, shopId);
            if(isDeleted== Constants.ONE){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"商户已删除,请联系管理员");
            }
            Integer isForbidden = dao.queryForObject(" select COALESCE(STATUS,0)  from shop_info where id  = ?", Integer.class, shopId);
            Integer isForbidden = dao.queryForObject(" select COALESCE(STATUS,0)  from shop_info where VERSION_TYPE = 0 and id  = ?", Integer.class, shopId);
            if(isForbidden == Constants.ONE){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"商户已禁用,请联系管理员");
            }
            String dbOpenid = dao.queryForObject(" select ifnull(openid,'')  from shop_info where id  = ?", String.class, shopId);
            if(StringUtils.isBlank(dbOpenid)||!openid.equals(dbOpenid)){
                throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME);
            }
            Integer count = dao.queryForObject("select count(1) from shop_info where id  = ?", Integer.class, shopId);
            Integer count = dao.queryForObject("select count(1) from shop_info where VERSION_TYPE = 0 and  id  = ?", Integer.class, shopId);
            if (count != null && count > 0) {
                request.setAttribute(JwtTokenUtil.SHOP_ID, shop.getId());
                return true;
            }else{
                throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"用户信息出错");
                throw new BusinessException(ResponseStatus.SHOP_BE_OVERDUE.getCode(),"用户信息出错");
            }
        } catch (IllegalArgumentException | JwtException e) {
            throw new BusinessException(ResponseStatus.BE_OVERDUE);
            throw new BusinessException(ResponseStatus.SHOP_BE_OVERDUE);
        }
    }
    public Boolean checkDriverLogin(HttpServletRequest request, HttpServletResponse response){
        String token = request.getHeader(JwtTokenUtil.HEADER_KEY);
        System.out.println("司机token:=========>{}"+token);
        try {
            if(!token.startsWith(Constants.ONE+"")){
                throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME);
@@ -194,9 +195,14 @@
            if(StringUtils.isBlank(tokenRedis)){
                throw new BusinessException(ResponseStatus.BE_OVERDUE);
            }
            Integer memberId = getTokenId(token);
            Integer driverId = getTokenId(token);
            //查询司机信息
            Integer memberId = dao.queryForObject(" select COALESCE(member_id,0)  from driver_info where VERSION_TYPE = 0 and  id  = ?", Integer.class, driverId);
            if(Objects.isNull(memberId)||Constants.equalsInteger(memberId,Constants.ZERO)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"司机信息信息出错");
            }
            Integer isDeleted = dao.queryForObject(" select COALESCE(DELETED,1)  from member where user_type = 1 and   id  = ?", Integer.class, memberId);
            if(isDeleted== Constants.ONE){
            if(isDeleted == Constants.ONE){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"司机信息已删除,请联系管理员");
            }
            Integer isForbidden = dao.queryForObject(" select COALESCE(STATUS,0)  from member where user_type = 1 and  id  = ?", Integer.class, memberId);
@@ -205,7 +211,7 @@
            }
            Integer count = dao.queryForObject("select count(1) from member where  user_type = 1  and id  = ?", Integer.class, memberId);
            if (count != null && count > 0) {
                request.setAttribute(JwtTokenUtil.DRIVER_ID, memberId);
                request.setAttribute(JwtTokenUtil.DRIVER_ID, driverId);
                return true;
            }else{
                throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"司机信息出错");