feat:askbot 门店获取方式变更
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.cool.store.config;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.exception.ServiceException;
|
||||
import com.cool.store.response.ResponseResult;
|
||||
import com.cool.store.utils.OpenSignatureUtil;
|
||||
import com.cool.store.utils.StringUtil;
|
||||
import com.cool.store.utils.UUIDUtils;
|
||||
@@ -11,10 +13,12 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
@@ -48,44 +52,63 @@ public class OpenApiValidateFilter implements Filter {
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
|
||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||
String uri = request.getRequestURI();
|
||||
if(!uri.startsWith("/zxjp/open/v1/getYlsToken")){
|
||||
if(!uri.startsWith("/zxjp/open/v1")){
|
||||
filterChain.doFilter(servletRequest, response);
|
||||
return;
|
||||
}
|
||||
MDC.put(CommonConstants.REQUEST_ID, UUIDUtils.get32UUID());
|
||||
|
||||
//statusRefresh 放开不需要验签
|
||||
if(uri.startsWith("/zxjp/open/v1/statusRefresh")){
|
||||
filterChain.doFilter(servletRequest, response);
|
||||
return;
|
||||
}
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
// 1. 验证时间戳
|
||||
try {
|
||||
String timestampStr = request.getHeader("timestamp");
|
||||
if (timestampStr == null) {
|
||||
log.info("timestampStr is null {}","缺少timestamp参数");
|
||||
throw new ServiceException(ErrorCodeEnum.SIGN_FAIL);
|
||||
res.setStatus(HttpStatus.OK.value());
|
||||
res.setCharacterEncoding("UTF-8");
|
||||
res.getWriter().write(JSON.toJSONString(
|
||||
ResponseResult.fail(ErrorCodeEnum.SIGN_FAIL,"缺少timestamp参数")));
|
||||
return;
|
||||
}
|
||||
long timestamp = Long.parseLong(timestampStr)/1000;
|
||||
long currentTime = System.currentTimeMillis()/1000;
|
||||
long timeDiff = Math.abs(currentTime - timestamp);
|
||||
try {
|
||||
|
||||
|
||||
if (timeDiff > 600) {
|
||||
log.info("OpenApiValidateFilter==>{}","请求已过期,服务器时间:" + currentTime + " 请求时间:" + timestamp);
|
||||
throw new ServiceException(ErrorCodeEnum.THIRD_API_ERROR,"请求已过期,请保证timestamp时间在10分钟之内");
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
log.info("OpenApiValidateFilter==>{}","非法timestamp格式");
|
||||
throw new ServiceException(ErrorCodeEnum.SIGN_FAIL);
|
||||
res.setStatus(HttpStatus.OK.value());
|
||||
res.setCharacterEncoding("UTF-8");
|
||||
res.getWriter().write(JSON.toJSONString(
|
||||
ResponseResult.fail(ErrorCodeEnum.SIGN_FAIL,"非法timestamp格式")));
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 验证签名
|
||||
String appKey = request.getHeader("appkey");
|
||||
if (appKey == null || !coolAppKey.equals(appKey)) {
|
||||
log.info("OpenApiValidateFilter==>{}","无效的appKey");
|
||||
throw new ServiceException(ErrorCodeEnum.THIRD_API_ERROR,"无效的appKey");
|
||||
res.setStatus(HttpStatus.OK.value());
|
||||
res.setCharacterEncoding("UTF-8");
|
||||
res.getWriter().write(JSON.toJSONString(
|
||||
ResponseResult.fail(ErrorCodeEnum.SIGN_FAIL,"无效的appKey")));
|
||||
return;
|
||||
}
|
||||
|
||||
String clientSign = request.getHeader("sign");
|
||||
if (clientSign == null) {
|
||||
throw new ServiceException(ErrorCodeEnum.THIRD_API_ERROR,"签名校验失败");
|
||||
res.setStatus(HttpStatus.OK.value());
|
||||
res.setCharacterEncoding("UTF-8");
|
||||
res.getWriter().write(JSON.toJSONString(
|
||||
ResponseResult.fail(ErrorCodeEnum.SIGN_FAIL,"签名为空")));
|
||||
return;
|
||||
}
|
||||
// 1. 读取请求体
|
||||
StringBuilder requestBody = new StringBuilder();
|
||||
@@ -112,7 +135,11 @@ public class OpenApiValidateFilter implements Filter {
|
||||
log.info("{}",serverSign);
|
||||
|
||||
if (!serverSign.equalsIgnoreCase(clientSign)) {
|
||||
throw new ServiceException(ErrorCodeEnum.SIGN_FAIL);
|
||||
res.setStatus(HttpStatus.OK.value());
|
||||
res.setCharacterEncoding("UTF-8");
|
||||
res.getWriter().write(JSON.toJSONString(
|
||||
ResponseResult.fail(ErrorCodeEnum.SIGN_FAIL,"签名校验失败")));
|
||||
return;
|
||||
}
|
||||
filterChain.doFilter(request, response);
|
||||
} finally {
|
||||
|
||||
@@ -4,11 +4,15 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.dto.AskBotTokenDTO;
|
||||
import com.cool.store.dto.GetAccessTokenDTO;
|
||||
import com.cool.store.dto.StatusRefreshDTO;
|
||||
import com.cool.store.dto.StoreDTO;
|
||||
import com.cool.store.request.OpenApiStoreRequest;
|
||||
import com.cool.store.response.ResponseResult;
|
||||
import com.cool.store.response.bigdata.ApiResponse;
|
||||
import com.cool.store.service.OpenApiService;
|
||||
import com.cool.store.service.PushService;
|
||||
import com.cool.store.service.ShopAccountService;
|
||||
import com.cool.store.service.StoreService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -34,6 +38,8 @@ public class OpenApiController {
|
||||
PushService pushService;
|
||||
@Resource
|
||||
ShopAccountService shopAccountService;
|
||||
@Resource
|
||||
StoreService storeService;
|
||||
|
||||
@PostMapping("/statusRefresh")
|
||||
public ApiResponse<Boolean> statusRefresh(@RequestBody StatusRefreshDTO statusRefreshDTO){
|
||||
@@ -49,4 +55,11 @@ public class OpenApiController {
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("获取门店信息")
|
||||
@PostMapping("/getStoreList")
|
||||
public ApiResponse<PageInfo<StoreDTO>> getStoreList(@RequestBody @Validated OpenApiStoreRequest dto) {
|
||||
return ApiResponse.success(storeService.getStoreExtendFieldInfo(dto.getPageSize(),dto.getPageNum()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user