|
|
@ -7,12 +7,14 @@ package com.shop.cereshop.app.interceptor; |
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.shop.cereshop.app.dao.business.CerePlatformBusinessDAO; |
|
|
|
import com.shop.cereshop.app.redis.service.api.UserRedisService; |
|
|
|
import com.shop.cereshop.app.service.buyer.CereBuyerUserService; |
|
|
|
import com.shop.cereshop.app.utils.ContextUtil; |
|
|
|
import com.shop.cereshop.app.utils.TokenProvider; |
|
|
|
import com.shop.cereshop.commons.config.SecurityProperties; |
|
|
|
import com.shop.cereshop.commons.constant.CoReturnFormat; |
|
|
|
import com.shop.cereshop.commons.domain.business.CerePlatformBusiness; |
|
|
|
import com.shop.cereshop.commons.domain.buyer.CereBuyerUser; |
|
|
|
import com.shop.cereshop.commons.result.Result; |
|
|
|
import com.shop.cereshop.commons.utils.EmptyUtils; |
|
|
@ -48,6 +50,9 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { |
|
|
|
@Autowired |
|
|
|
private TokenProvider tokenProvider; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CerePlatformBusinessDAO cerePlatformBusinessDAO; |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
|
|
|
Result result = new Result(); |
|
|
@ -118,7 +123,20 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
String project = request.getHeader("project"); |
|
|
|
String project = ""; |
|
|
|
|
|
|
|
//获取访问的二级域名 |
|
|
|
String subDomain = getSubDomain(request); |
|
|
|
if (ObjectUtil.isNotEmpty(subDomain)){ |
|
|
|
//从商家设置的商城访问域名表中获取商家id,即project |
|
|
|
CerePlatformBusiness business = cerePlatformBusinessDAO.findByDomain(subDomain); |
|
|
|
if (ObjectUtil.isNotEmpty(business)){ |
|
|
|
project = String.valueOf(business.getBusinessId()); |
|
|
|
} |
|
|
|
}else { |
|
|
|
project = request.getHeader("project"); |
|
|
|
} |
|
|
|
|
|
|
|
if (EmptyUtils.isEmpty(project) || project.equals("undefined")) { |
|
|
|
project = "0"; |
|
|
|
} |
|
|
@ -178,4 +196,19 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { |
|
|
|
//防止乱码,适用于传输JSON数据 |
|
|
|
response.setHeader("Content-Type", "application/json;charset=UTF-8"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取访问的二级域名,如subdomain.example.com。获取的是subdomain |
|
|
|
* @param request |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String getSubDomain(HttpServletRequest request) { |
|
|
|
String host = request.getHeader("Host"); |
|
|
|
String[] parts = host.split("\\."); |
|
|
|
if (parts.length >= 3){ |
|
|
|
return parts[0]; |
|
|
|
} |
|
|
|
|
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |