Merge branch 'cc_2250513_api' into 'master'

Cc 2250513 api

See merge request hangzhou/java/custom_zxjp!89
This commit is contained in:
苏竹红
2025-05-20 09:32:04 +00:00
18 changed files with 570 additions and 13 deletions

View File

@@ -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分钟之内");
throw new ServiceException(ErrorCodeEnum.SIGN_FAIL,"请求已过期请保证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 {

View File

@@ -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()));
}
}

View File

@@ -1,6 +1,7 @@
package com.cool.store.controller.webb;
import com.cool.store.dao.*;
import com.cool.store.dto.FoodTokenDTO;
import com.cool.store.dto.GetAccessTokenDTO;
import com.cool.store.dto.ModifyPasswordDTO;
import com.cool.store.entity.*;
@@ -295,6 +296,12 @@ public class PCTestController {
public ResponseResult<List<String>> getAuthRegionIdAndSubRegionIdByUserId(@RequestParam(value = "userId", required = true) String userId) {
return ResponseResult.success(userAuthMappingService.getAuthRegionIdAndSubRegionIdByUserId(userId));
}
@Resource
ThirdFoodService thirdFoodService;
@ApiOperation("获取菜品市场token")
@PostMapping("/getFoodToken")
public ResponseResult<String> getFoodToken(@RequestBody @Validated FoodTokenDTO dto) {
return ResponseResult.success(thirdFoodService.getFoodToken(dto));
}
}

View File

@@ -1,5 +1,6 @@
package com.cool.store.controller.webc;
import com.cool.store.dto.FoodTokenDTO;
import com.cool.store.dto.GetAccessTokenDTO;
import com.cool.store.dto.ModifyPasswordDTO;
import com.cool.store.dto.ShopAccount.ShopAccountDTO;
@@ -7,6 +8,7 @@ import com.cool.store.request.GetPasswordDTO;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.PushService;
import com.cool.store.service.ShopAccountService;
import com.cool.store.service.ThirdFoodService;
import com.cool.store.service.ThirdXinGuanJiaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -36,6 +38,9 @@ public class MiniShopAccountController {
@Resource
ThirdXinGuanJiaService thirdXinGuanJiaService;
@Resource
ThirdFoodService thirdFoodService;
@ApiOperation("根据门店shopId查询平台账号")
@GetMapping("/getShopAccountByShopId")
@@ -68,6 +73,12 @@ public class MiniShopAccountController {
return ResponseResult.success(pushService.getXzgToken(dto));
}
@ApiOperation("获取菜品市场token")
@PostMapping("/getFoodToken")
public ResponseResult<String> getFoodToken(@RequestBody @Validated FoodTokenDTO dto) {
return ResponseResult.success(thirdFoodService.getFoodToken(dto));
}
@ApiOperation("获取加密子串")
@PostMapping("/getEncryptedSubstring")
public ResponseResult<String> getEncryptedSubstring(@RequestBody GetPasswordDTO dto) {

View File

@@ -118,6 +118,8 @@ zx.big.data.appSecret=35b8b9a400b4430fa022190be0913cd6
xzg.api.auth.url=http://webapi.zhengxinfood.com
zx.food.url=https://datacenter.zhengxinshipin.com
cool.api.appKey=k8J7fG2qR5tY9vX3
cool.api.secret=wP4sN6dL8zK2xM9c

View File

@@ -121,6 +121,8 @@ yls.api.auth.secret=3b56198f096d4009072c927c96fbc8b6
#新掌柜账号
xzg.api.auth.url=http://webapi.zhengxinfood.com
zx.food.url=https://datacenter.zhengxinfood.com
cool.api.appKey=k8J7fG2qR5tY9vX3
cool.api.secret=wP4sN6dL8zK2xM9c