feat:云流水

This commit is contained in:
苏竹红
2025-04-17 16:02:12 +08:00
parent 1b7e1928cd
commit d54537937a
16 changed files with 124 additions and 29 deletions

View File

@@ -3,6 +3,7 @@ import com.cool.store.constants.CommonConstants;
import com.cool.store.enums.ErrorCodeEnum;
import com.cool.store.exception.ServiceException;
import com.cool.store.utils.OpenSignatureUtil;
import com.cool.store.utils.StringUtil;
import com.cool.store.utils.UUIDUtils;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -48,7 +49,7 @@ public class OpenApiValidateFilter implements Filter {
MDC.put(CommonConstants.REQUEST_ID, UUIDUtils.get32UUID());
HttpServletRequest request = (HttpServletRequest) servletRequest;
String uri = request.getRequestURI();
if(!uri.startsWith("/zxjp/open1")){
if(!uri.startsWith("/zxjp/open/v1/getYlsToken")){
filterChain.doFilter(servletRequest, response);
return;
}
@@ -60,15 +61,15 @@ public class OpenApiValidateFilter implements Filter {
log.info("timestampStr is null {}","缺少timestamp参数");
throw new ServiceException(ErrorCodeEnum.SIGN_FAIL);
}
long timestamp = Long.parseLong(timestampStr)/1000;
long currentTime = System.currentTimeMillis()/1000;
long timeDiff = Math.abs(currentTime - timestamp);
try {
long timestamp = Long.parseLong(timestampStr)/1000;
long currentTime = System.currentTimeMillis()/1000;
long timeDiff = Math.abs(currentTime - timestamp);
if (timeDiff > 600) {
log.info("OpenApiValidateFilter==>{}","请求已过期,服务器时间:" + currentTime + " 请求时间:" + timestamp);
throw new ServiceException(ErrorCodeEnum.SIGN_FAIL);
throw new ServiceException(ErrorCodeEnum.THIRD_API_ERROR,"请求已过期请保证timestamp时间在10分钟之内");
}
} catch (NumberFormatException e) {
log.info("OpenApiValidateFilter==>{}","非法timestamp格式");
@@ -79,12 +80,12 @@ public class OpenApiValidateFilter implements Filter {
String appKey = request.getHeader("appkey");
if (appKey == null || !coolAppKey.equals(appKey)) {
log.info("OpenApiValidateFilter==>{}","无效的appKey");
throw new ServiceException(ErrorCodeEnum.SIGN_FAIL);
throw new ServiceException(ErrorCodeEnum.THIRD_API_ERROR,"无效的appKey");
}
String clientSign = request.getHeader("sign");
if (clientSign == null) {
throw new ServiceException(ErrorCodeEnum.SIGN_FAIL);
throw new ServiceException(ErrorCodeEnum.THIRD_API_ERROR,"签名校验失败");
}
// 1. 读取请求体
StringBuilder requestBody = new StringBuilder();
@@ -103,6 +104,8 @@ public class OpenApiValidateFilter implements Filter {
jsonBody,
new TypeReference<TreeMap<String, String>>() {}
);
params.put("appKey",appKey);
params.put("timestamp", String.valueOf(timestamp));
String serverSign = OpenSignatureUtil.generateSign(params, coolAppSecret);

View File

@@ -1,11 +1,18 @@
package com.cool.store.controller.webb;
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.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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@@ -23,6 +30,10 @@ public class OpenApiController {
@Resource
OpenApiService openApiService;
@Resource
PushService pushService;
@Resource
ShopAccountService shopAccountService;
@PostMapping("/statusRefresh")
public ApiResponse<Boolean> statusRefresh(@RequestBody StatusRefreshDTO statusRefreshDTO){
@@ -30,4 +41,12 @@ public class OpenApiController {
return ApiResponse.success(openApiService.statusRefresh(statusRefreshDTO));
}
@ApiOperation("获取云流水免登token")
@PostMapping("/getYlsToken")
public ApiResponse<String> getYlsToken(@RequestBody @Validated AskBotTokenDTO dto) {
String ylsCode = shopAccountService.shopCodeToYlsCode(dto.getShopCode());
return ApiResponse.success(pushService.getYlsToken(new GetAccessTokenDTO(ylsCode,ylsCode)));
}
}

View File

@@ -77,7 +77,7 @@ public class MiniShopAccountController {
@ApiOperation("门店编码换云流水编码")
@GetMapping("/shopCodeToYlsCode")
public ResponseResult<String> shopCodeToYlsCode(@RequestParam(value = "shopId",required = true) Long shopId) {
return ResponseResult.success(accountService.shopCodeToYlsCode(shopId));
return ResponseResult.success(accountService.shopIdToYlsCode(shopId));
}
}

View File

@@ -95,15 +95,35 @@ xgj.open.organization.X-Secret = 3fe724f9607448728ee3393eff75718a
xgj.open.organization.url = https://masterdata.zhengxinfood.com/dmp/one-id
#huoma pos
api.auth.url=https://api.zhengxindzg.cn
api.auth.username=GkqgAhUJ7p9swJo
api.auth.secret=NzVrnS3OWiupdDY
#xingguanjia
xgj.api.auth.url=https://masterdata.zhengxinfood.com/dmp/one-id
xgj.api.auth.username=6446346061e043e392dd53c9c8d1af0b
xgj.api.auth.secret=3ba6e4c5632547b8b2b3acefe08667bb
#yunliushui
yls.api.auth.url=http://yuanguiwuliu.com
yls.api.auth.username=096d4009072c927c
yls.api.auth.secret=3b56198f096d4009072c927c96fbc8b6
#机会点地址 已确定
third.party.appKey=IGSAEQoakR2HEaYx
third.party.appSecret=aPsA99K1obFeFm3m
zx.opportunity.url=https://snp.wenmatech.com/
#大数据地址 已确定
zx.big.data.url=https://ds.zhengxinfood.com/
zx.big.data.appKey=ff203b5567744feaaae49fb86f58c5bf
zx.big.data.appSecret=35b8b9a400b4430fa022190be0913cd6
#新掌柜账号
xzg.api.auth.url=http://webapi.zhengxinfood.com
cool.api.appKey=k8J7fG2qR5tY9vX3
cool.api.secret=wP4sN6dL8zK2xM9c

View File

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