| | |
| | | @Autowired |
| | | TokenProvider tokenProvider; |
| | | |
| | | @GetMapping("/bySMS") |
| | | public ResponseEntity<OtpResponseDTO> sendOtpBySMS(@RequestParam("phone") String phone) { |
| | | final OtpResponseDTO otpResponseDTO = otpWebService.sendByPhone(phone); |
| | | return new ResponseEntity<>(otpResponseDTO, HttpStatus.OK); |
| | | } |
| | | // @GetMapping("/bySMS") |
| | | // 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) { |
| | | // 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) { |
| | | // final OtpResponseDTO otpResponseDTO = otpWebService.verifyOTP(indexKey, otpCode); |
| | | // return new ResponseEntity<>(otpResponseDTO, HttpStatus.OK); |
| | | // } |
| | | |
| | | @GetMapping("/byEmail") |
| | | public ResponseEntity<OtpResponseDTO> sendOtpByEmail(@RequestParam("email") String email) { |
| | | final OtpResponseDTO otpResponseDTO = otpWebService.sendByEmail(email); |
| | | return new ResponseEntity<>(otpResponseDTO, HttpStatus.OK); |
| | | } |
| | | // @GetMapping("/byEService") |
| | | // public ResponseEntity<EServiceResponse> loginByEService(@RequestParam("account") String account, @RequestParam("password") String password) throws Exception { |
| | | // 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<>(headers); |
| | | // return restTemplate.exchange(urlTemplate, HttpMethod.GET, entity, EServiceResponse.class); |
| | | // } |
| | | |
| | | @GetMapping("/verifyOtp") |
| | | 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); |
| | | } |
| | | // private void settingMessageConvertesToSpecifyType(RestTemplate restTemplate, MediaType mediaType) { |
| | | // List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); |
| | | // MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); |
| | | // converter.setSupportedMediaTypes(Collections.singletonList(mediaType)); |
| | | // messageConverters.add(converter); |
| | | // restTemplate.setMessageConverters(messageConverters); |
| | | // } |
| | | |
| | | @GetMapping("/byEService") |
| | | public ResponseEntity<EServiceResponse> loginByEService(@RequestParam("account") String account, @RequestParam("password") String password) throws Exception { |
| | | 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<>(headers); |
| | | return restTemplate.exchange(urlTemplate, HttpMethod.GET, entity, EServiceResponse.class); |
| | | } |
| | | |
| | | private void settingMessageConvertesToSpecifyType(RestTemplate restTemplate, MediaType mediaType) { |
| | | List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); |
| | | MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); |
| | | converter.setSupportedMediaTypes(Collections.singletonList(mediaType)); |
| | | messageConverters.add(converter); |
| | | restTemplate.setMessageConverters(messageConverters); |
| | | } |
| | | |
| | | private RestTemplate getTrustAllRestTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { |
| | | SSLContext sslContext = SSLContexts.custom() |
| | | .loadTrustMaterial(null, (X509Certificate[] x509Certs, String s) -> true) |
| | | .build(); |
| | | SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier()); |
| | | CloseableHttpClient httpClient = HttpClients.custom() |
| | | .setSSLSocketFactory(csf) |
| | | .build(); |
| | | HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); |
| | | requestFactory.setHttpClient(httpClient); |
| | | requestFactory.setConnectTimeout(300000); |
| | | requestFactory.setReadTimeout(300000); |
| | | return new RestTemplate(requestFactory); |
| | | } |
| | | // private RestTemplate getTrustAllRestTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { |
| | | // SSLContext sslContext = SSLContexts.custom() |
| | | // .loadTrustMaterial(null, (X509Certificate[] x509Certs, String s) -> true) |
| | | // .build(); |
| | | // SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier()); |
| | | // CloseableHttpClient httpClient = HttpClients.custom() |
| | | // .setSSLSocketFactory(csf) |
| | | // .build(); |
| | | // HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); |
| | | // requestFactory.setHttpClient(httpClient); |
| | | // requestFactory.setConnectTimeout(300000); |
| | | // requestFactory.setReadTimeout(300000); |
| | | // return new RestTemplate(requestFactory); |
| | | // } |
| | | } |