From cb98f347b5181a8be0db6e2129ba0fb36647dcf0 Mon Sep 17 00:00:00 2001 From: wanglf3 Date: Thu, 29 Feb 2024 08:44:50 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=AE=A2=E5=8D=95=E6=98=8E=E7=BB=86=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../out/OrderDetailController.java | 23 ++++++++++++++----- .../service/auth/AuthenticateService.java | 2 +- .../service/auth/AuthenticateServiceImpl.java | 8 +++---- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/chint/application/out/OrderDetailController.java b/src/main/java/com/chint/application/out/OrderDetailController.java index dd1a5b10..ea85a6bc 100644 --- a/src/main/java/com/chint/application/out/OrderDetailController.java +++ b/src/main/java/com/chint/application/out/OrderDetailController.java @@ -16,6 +16,7 @@ import com.chint.infrastructure.util.PageResult; import com.chint.infrastructure.util.Result; import com.chint.infrastructure.util.StringCheck; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -46,10 +47,19 @@ public class OrderDetailController { @ApiOperation("订单明细认证接口") @PostMapping("/pubilc/authentication") public Result queryAuthentication(@RequestBody AuthenticationDto authenticationDto) { -// Calendar calendar = Calendar.getInstance(); -// long timestamp = calendar.getTimeInMillis(); - OrderSearchResult orderSearchResult = authenticateService.authenticateClient(authenticationDto); - return Result.Success(SUCCESS, orderSearchResult); + + OrderSearchResult orderSearchResult = null; + try { + orderSearchResult = authenticateService.authenticateClient(authenticationDto); + if (orderSearchResult != null){ + return Result.Success(SUCCESS, orderSearchResult); + }else { + return Result.error("认证失败"); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } @ApiOperation("订单明细查询接口") @@ -59,13 +69,14 @@ public class OrderDetailController { String systemType = authenticationDto.getSystemType(); String startTime = authenticationDto.getStartTime(); String endTime = authenticationDto.getEndTime(); - String pageSize = authenticationDto.getEndTime().toString(); + String pageSize = authenticationDto.getPageSize().toString(); String pageNum = authenticationDto.getPageNum().toString(); String orgsign = authenticationDto.getSign(); String sign = Digest.md5(systemType + startTime + endTime + pageSize + pageNum); System.out.println(sign); - if (orgsign.equals(sign)) { + + if (StringUtils.isNotBlank(orgsign) && orgsign.equals(sign)) { return Result.Success(SUCCESS,sign); } else { return Result.error("签名错误"); diff --git a/src/main/java/com/chint/domain/service/auth/AuthenticateService.java b/src/main/java/com/chint/domain/service/auth/AuthenticateService.java index e0089bc1..01f58296 100644 --- a/src/main/java/com/chint/domain/service/auth/AuthenticateService.java +++ b/src/main/java/com/chint/domain/service/auth/AuthenticateService.java @@ -8,5 +8,5 @@ import com.chint.domain.value_object.UserLoginResult; public interface AuthenticateService { UserLoginResult authenticateEmployeeNo(UserLoginParam userLoginParam); - OrderSearchResult authenticateClient(AuthenticationDto authenticationDto); + OrderSearchResult authenticateClient(AuthenticationDto authenticationDto)throws Exception; } diff --git a/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java b/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java index 13ca6b71..f3b02909 100644 --- a/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java +++ b/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java @@ -4,6 +4,7 @@ import com.chint.application.dtos.AuthenticationDto; import com.chint.application.dtos.OrderSearchResult; import com.chint.domain.aggregates.order.Client; import com.chint.domain.aggregates.user.User; +import com.chint.domain.exceptions.AuthException; import com.chint.domain.factoriy.user.UserFactory; import com.chint.domain.repository.ClientRepository; import com.chint.domain.repository.UserRepository; @@ -83,7 +84,7 @@ public class AuthenticateServiceImpl implements AuthenticateService { } @Override - public OrderSearchResult authenticateClient(AuthenticationDto authenticationDto) { + public OrderSearchResult authenticateClient(AuthenticationDto authenticationDto) throws Exception{ Client client = clientRepository.findByClientId(authenticationDto.getClientid()); @@ -95,15 +96,12 @@ public class AuthenticateServiceImpl implements AuthenticateService { String jwt = JWTUtil.createJWT(AuthMessageConstant.SECRET,AuthMessageConstant.EXPIRATION_CLIENT_TIME_MS, AuthMessageConstant.SUBJECT,claims); - OrderSearchResult result = new OrderSearchResult(); result.setToken(Token.of(jwt)); return result; }else { - + throw new AuthException(AuthMessageConstant.JWT_INVALID); } - - return null; } } \ No newline at end of file