From 03a858f2882bedeb5925b65cb045ccbbb1202329 Mon Sep 17 00:00:00 2001 From: wayne <wayne8692wayne8692@gmail.com> Date: 星期三, 24 十一月 2021 16:01:04 +0800 Subject: [PATCH] [update] otp呼叫方式調整,並針對sit版本除錯 --- pamapi/src/main/java/com/pollex/pam/web/rest/TestLoginResource.java | 45 ++++++++++++++++++++------------------------- 1 files changed, 20 insertions(+), 25 deletions(-) diff --git a/pamapi/src/main/java/com/pollex/pam/web/rest/TestLoginResource.java b/pamapi/src/main/java/com/pollex/pam/web/rest/TestLoginResource.java index f9b11dc..d4286dc 100644 --- a/pamapi/src/main/java/com/pollex/pam/web/rest/TestLoginResource.java +++ b/pamapi/src/main/java/com/pollex/pam/web/rest/TestLoginResource.java @@ -29,11 +29,9 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; -import tw.com.softleader.otp.ws.OtpWebServicePortBindingStub; +import org.springframework.web.util.UriComponentsBuilder; import javax.net.ssl.SSLContext; -import javax.xml.rpc.ServiceException; -import java.rmi.RemoteException; import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; @@ -41,6 +39,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.UUID; // todo嚗����login�靘蹂蝙��get��撘�嚗��歇��OtpResource��ServiceResource嚗蜓閬����� @@ -67,48 +66,44 @@ TokenProvider tokenProvider; @GetMapping("/bySMS") - public ResponseEntity<OtpResponseDTO> sendOtpBySMS(@RequestParam("phone") String phone) throws ServiceException, RemoteException { + public ResponseEntity<OtpResponseDTO> sendOtpBySMS(@RequestParam("phone") String phone) { final OtpResponseDTO otpResponseDTO = otpWebService.sendByPhone(phone); return new ResponseEntity<>(otpResponseDTO, HttpStatus.OK); } @GetMapping("/byEmail") - public ResponseEntity<OtpResponseDTO> sendOtpByEmail(@RequestParam("email") String email) throws RemoteException, ServiceException { + public ResponseEntity<OtpResponseDTO> sendOtpByEmail(@RequestParam("email") String email) { final OtpResponseDTO otpResponseDTO = otpWebService.sendByEmail(email); return new ResponseEntity<>(otpResponseDTO, HttpStatus.OK); } @GetMapping("/verifyOtp") - public ResponseEntity<OtpResponseDTO> verifyOtp(@RequestParam("account") String account, @RequestParam("indexKey") String indexKey, @RequestParam("otpCode") String otpCode) throws ServiceException, RemoteException { - OtpWebServicePortBindingStub stub = otpWebService.getOtpWebServicePortBindingStub(); - log.info("call OtpService verifyOTP, systemType = {}, service password = {}, indexKey = {}, paxxword = {}", - applicationProperty.getOtpWebServiceSystemType(), applicationProperty.getOtpWebServicePassword(), indexKey, otpCode); - - String[] result = - stub.verifyOtp(applicationProperty.getOtpWebServicePassword(), applicationProperty.getOtpWebServiceSystemType(), indexKey, otpCode); - - return new ResponseEntity<>(new OtpResponseDTO(result), HttpStatus.OK); + public ResponseEntity<OtpResponseDTO> verifyOtp(@RequestParam("account") String account, @RequestParam("indexKey") String indexKey, @RequestParam("otpCode") String otpCode) { + final OtpResponseDTO otpResponseDTO = otpWebService.verifyOTP(indexKey, otpCode); + return new ResponseEntity<>(otpResponseDTO, HttpStatus.OK); } @GetMapping("/byEService") public ResponseEntity<EServiceResponse> loginByEService(@RequestParam("account") String account, @RequestParam("password") String password) throws Exception { - EServiceRequest dto = new EServiceRequest(); - dto.setFunc("ValidateUserLogin"); - dto.setId(account); - dto.setPin(password); - dto.setPwd(password); - dto.setSys("epos"); - - String dtoJson = new ObjectMapper().writeValueAsString(dto); - RestTemplate restTemplate = getTrustAllRestTemplate(); settingMessageConvertesToSpecifyType(restTemplate, MediaType.ALL); + + String urlTemplate = UriComponentsBuilder.fromHttpUrl(applicationProperty.geteServiceLoginUrl()) + .queryParam("func", applicationProperty.geteServiceLoginFunc()) + .queryParam("id", account) + .queryParam("pin", password) + .queryParam("pwd", password) + .queryParam("sys", applicationProperty.geteServiceLoginSys()) + .queryParam("transactionId", UUID.randomUUID().toString()) + .encode().toUriString(); + + log.debug("http get loginByEService, url = {}", urlTemplate); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity<String> entity = new HttpEntity<>(dtoJson, headers); - return restTemplate.exchange(applicationProperty.geteServiceLoginUrl(), HttpMethod.POST, entity, EServiceResponse.class); + HttpEntity<String> entity = new HttpEntity<>(headers); + return restTemplate.exchange(urlTemplate, HttpMethod.GET, entity, EServiceResponse.class); } private void settingMessageConvertesToSpecifyType(RestTemplate restTemplate, MediaType mediaType) { -- Gitblit v1.8.0