@RestController @Controller differ
This commit is contained in:
parent
044860b324
commit
1458ab860c
@ -64,17 +64,11 @@ public class Aes128Cbc {
|
|||||||
InvalidKeyException {
|
InvalidKeyException {
|
||||||
|
|
||||||
System.out.println(encrypt("{\"PageNo\": \"1\", \"PageSize\": 49}", "8LpncubmWiPCzY3V", "av6A8QdnRaVRMXu6"));
|
System.out.println(encrypt("{\"PageNo\": \"1\", \"PageSize\": 49}", "8LpncubmWiPCzY3V", "av6A8QdnRaVRMXu6"));
|
||||||
// System.out.println(decryptString("ywyEEd5aKPJOTraAY/gXB/bA+UNprpYnSaOhfF5lKc/Zcv" +
|
System.out.println(encrypt("{\"StartChargeSeq\":\"MA5FF58R7202110221602214945\"," +
|
||||||
// "/BRasig4KSPJD7UmrH2vjLVIWXPw42EbLgV9bXr5SzUSVAT28ief2nk6hpWnT8Dcvhn3W4bj7UdEY" +
|
"\"ConnectorId\":\"5503141278230501\",\"QRCode\":\"ddg\",\"PlateNum\":\"dk4520\",\"ChargingAmt\":6," +
|
||||||
// "/AdONVXWuq2MZQocGYEVNvWcSD0OVCJ04fNTwPR4hs1xI/QDg9/hqYdQbvWt3go/y" +
|
"\"driverId\":\"15183246728\"}",
|
||||||
// "+M9wxd4vq8m44RPQ5zjW3vxFxc4oMg2t0oTdk6W5AzJzAGWhU/4xIv+8gLeh6/blpW/VBUK82+4tcdG2JSJv/DcaDM0" +
|
"8LpncubmWiPCzY3V"
|
||||||
// "/7C1LsCYY17o6gGd1mFVDSZhYcaOmOska+h+eyTKL4i8oHpT6uf+hFDRVBUC1OTjDeiL9NyIxcwd" +
|
, "av6A8QdnRaVRMXu6"));
|
||||||
// "/MMfAaF04wHOHrYMavL5wcBUZWwtU1QSLWXkUy7muJNYvVg4dmw92nNKaJtxgFycXVGkSP3Nc6y" +
|
|
||||||
// "/sAzYkTz9Wfn4RLVOkpyYJMOo1Tz93/OFEKQFPnjzSRQAVYiuPzuySKjXdcDY8AfqmDqYuVZ2FhH0iVU6FiSsK4" +
|
|
||||||
// "+al0hnLOcnftqYtYSd7ir2coP6XtNejOByqFPrShMp4rPQLvDpFibV87clFMwWOGBiB0eFRvRbOSntDYN7PBpFHHJXRkNi3VCMiJ" +
|
|
||||||
// "+Y=",
|
|
||||||
// "8LpncubmWiPCzY3V"
|
|
||||||
// , "av6A8QdnRaVRMXu6"));
|
|
||||||
System.out.println(new BigDecimal("244.0111117").setScale(6, RoundingMode.HALF_UP).doubleValue());
|
System.out.println(new BigDecimal("244.0111117").setScale(6, RoundingMode.HALF_UP).doubleValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,15 +3,16 @@ package com.xhpc.evcs.api;
|
|||||||
import com.xhpc.common.api.PileOrderService;
|
import com.xhpc.common.api.PileOrderService;
|
||||||
import com.xhpc.common.core.domain.R;
|
import com.xhpc.common.core.domain.R;
|
||||||
import com.xhpc.evcs.domain.AuthSecretToken;
|
import com.xhpc.evcs.domain.AuthSecretToken;
|
||||||
|
import com.xhpc.evcs.dto.CommonRequest;
|
||||||
import com.xhpc.evcs.dto.CommonResponse;
|
import com.xhpc.evcs.dto.CommonResponse;
|
||||||
import com.xhpc.evcs.dto.StartChargeRequest;
|
import com.xhpc.evcs.dto.StartChargeRequest;
|
||||||
import com.xhpc.evcs.dto.StartChargeResponse;
|
import com.xhpc.evcs.dto.StartChargeResponse;
|
||||||
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
|
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
|
||||||
import com.xhpc.evcs.utils.JSONUtil;
|
import com.xhpc.evcs.utils.JSONUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -19,7 +20,7 @@ import java.util.Optional;
|
|||||||
|
|
||||||
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||||
|
|
||||||
@Controller
|
@RestController
|
||||||
public class QueryStartChargeController {
|
public class QueryStartChargeController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -28,15 +29,17 @@ public class QueryStartChargeController {
|
|||||||
private PileOrderService pileOrderService;
|
private PileOrderService pileOrderService;
|
||||||
|
|
||||||
@PostMapping(value = "/v1/query_start_charge")
|
@PostMapping(value = "/v1/query_start_charge")
|
||||||
public CommonResponse queryStartCharge(@RequestBody StartChargeRequest startChargeRequest) throws Exception {
|
public CommonResponse queryStartCharge(@RequestBody CommonRequest<StartChargeRequest> commonRequest) throws Exception {
|
||||||
|
|
||||||
CommonResponse resp = new CommonResponse();
|
CommonResponse resp = new CommonResponse();
|
||||||
StartChargeResponse startChargeResponse = new StartChargeResponse();
|
StartChargeResponse startChargeResponse = new StartChargeResponse();
|
||||||
|
StartChargeRequest startChargeRequest = JSONUtil.readParams(commonRequest.getData(), StartChargeRequest.class);
|
||||||
String startChargeSeq = startChargeRequest.getStartChargeSeq();
|
String startChargeSeq = startChargeRequest.getStartChargeSeq();
|
||||||
String connectorID = startChargeRequest.getConnectorId();
|
String connectorID = startChargeRequest.getConnectorId();
|
||||||
String operatorId = startChargeSeq.substring(0, 9);
|
String operatorId = startChargeSeq.substring(0, 9);
|
||||||
//Checking the operator whether it has its token.
|
//Checking the operator whether it has its token.
|
||||||
Optional<AuthSecretToken> authSecretTokenIn = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId, "IN");
|
Optional<AuthSecretToken> authSecretTokenIn =
|
||||||
|
authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId, "IN");
|
||||||
if (!authSecretTokenIn.isPresent()) {
|
if (!authSecretTokenIn.isPresent()) {
|
||||||
startChargeResponse.setSuccStat(1);
|
startChargeResponse.setSuccStat(1);
|
||||||
startChargeResponse.setFailReason(3);
|
startChargeResponse.setFailReason(3);
|
||||||
|
|||||||
@ -132,7 +132,7 @@ public class EvcsFilter extends OncePerRequestFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//decrypt request
|
//decrypt request
|
||||||
byte[] decryptedData = null;
|
byte[] decryptedReq = null;
|
||||||
String erroMsg = "Decryption error";
|
String erroMsg = "Decryption error";
|
||||||
CommonResponse resp = new CommonResponse();
|
CommonResponse resp = new CommonResponse();
|
||||||
authSecretTokenIn = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId,
|
authSecretTokenIn = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId,
|
||||||
@ -142,19 +142,19 @@ public class EvcsFilter extends OncePerRequestFilter {
|
|||||||
&& authorization != null && authorization.substring(7).equals(authSecretTokenIn.getToken())) {
|
&& authorization != null && authorization.substring(7).equals(authSecretTokenIn.getToken())) {
|
||||||
try {
|
try {
|
||||||
if (authSecretTokenIn.isEncrypt()) {
|
if (authSecretTokenIn.isEncrypt()) {
|
||||||
decryptedData = decrypt(request, authSecretTokenIn, commonRequest, bodyString);
|
decryptedReq = decrypt(request, authSecretTokenIn, commonRequest, bodyString);
|
||||||
} else {
|
} else {
|
||||||
decryptedData = ((String) commonRequest.getData()).getBytes(StandardCharsets.UTF_8);
|
decryptedReq = ((String) commonRequest.getData()).getBytes(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
log.debug("in.dec: {}", new String(decryptedData));
|
log.debug("in.dec: {}", new String(decryptedReq));
|
||||||
} catch (BadPaddingException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | IllegalBlockSizeException | NoSuchPaddingException | InvalidKeyException e) {
|
} catch (BadPaddingException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | IllegalBlockSizeException | NoSuchPaddingException | InvalidKeyException e) {
|
||||||
erroMsg = e.getMessage();
|
erroMsg = e.getMessage();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
erroMsg = "Authorization error, check OperatorID or token expiry";
|
erroMsg = "Authorization error, check OperatorID or token expiry";
|
||||||
}
|
}
|
||||||
if (decryptedData != null && decryptedData.length > 0) {
|
if (decryptedReq != null && decryptedReq.length > 0) {
|
||||||
requestWrapper = new HttpServletRequestWritableWrapper(request, decryptedData);
|
requestWrapper = new HttpServletRequestWritableWrapper(request, decryptedReq);
|
||||||
} else {
|
} else {
|
||||||
resp.setRet("4004");
|
resp.setRet("4004");
|
||||||
resp.setMsg(erroMsg);
|
resp.setMsg(erroMsg);
|
||||||
@ -171,6 +171,8 @@ public class EvcsFilter extends OncePerRequestFilter {
|
|||||||
// } else {
|
// } else {
|
||||||
chain.doFilter(requestWrapper, responseWrapper);
|
chain.doFilter(requestWrapper, responseWrapper);
|
||||||
// }
|
// }
|
||||||
|
// responseWrapper.copyBodyToResponse();
|
||||||
|
// responseWrapper = new ContentCachingResponseWrapper(responseWrapper);
|
||||||
byte[] buf = responseWrapper.getContentAsByteArray();
|
byte[] buf = responseWrapper.getContentAsByteArray();
|
||||||
log.debug("out.plain: {}", new String(buf, StandardCharsets.UTF_8));
|
log.debug("out.plain: {}", new String(buf, StandardCharsets.UTF_8));
|
||||||
String encryptedData;
|
String encryptedData;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user