From 92fe2073748248ce327ed149186cf58fa01d2a2c Mon Sep 17 00:00:00 2001 From: lulz1 Date: Wed, 28 Feb 2024 11:49:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/chint/application/dtos/UserDTO.java | 17 ++++++++---- .../login/strategy/PailaLoginStrategy.java | 26 +++++++++++++++---- src/main/resources/application-dev.yml | 6 ++--- src/main/resources/application-prod.yml | 6 ++--- src/main/resources/application-test.yml | 6 ++--- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/chint/application/dtos/UserDTO.java b/src/main/java/com/chint/application/dtos/UserDTO.java index 715ca635..eeb5e1dd 100644 --- a/src/main/java/com/chint/application/dtos/UserDTO.java +++ b/src/main/java/com/chint/application/dtos/UserDTO.java @@ -5,14 +5,21 @@ import lombok.Data; @Data public class UserDTO { - private String accountId; - private String mobile; - private String userName; - private String uid; - private String email; + private UserData attributes; + private String id; // 构造函数和其他方法(getter 和 setter)可以根据需要添加 // Getter 和 Setter 方法 + @Data + public static class UserData{ + private String user_name; + private String mobile; + private String account_no; + private long token_gtime; + private String token_expired; + private String email; + private String user_uid; + } } \ No newline at end of file diff --git a/src/main/java/com/chint/application/services/login/strategy/PailaLoginStrategy.java b/src/main/java/com/chint/application/services/login/strategy/PailaLoginStrategy.java index 0b883e87..99b764be 100644 --- a/src/main/java/com/chint/application/services/login/strategy/PailaLoginStrategy.java +++ b/src/main/java/com/chint/application/services/login/strategy/PailaLoginStrategy.java @@ -12,6 +12,7 @@ import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; import org.apache.http.client.utils.URIBuilder; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; @@ -59,13 +60,15 @@ public class PailaLoginStrategy implements LoginStrategy { log.info("开始执行登录"); List parameters = Arrays.asList( + new BasicNameValuePair("grant_type", "authorization_code"), new BasicNameValuePair("client_id", clientId), new BasicNameValuePair("client_secret", clientSecret), - new BasicNameValuePair("redirect_uri", redirectUri), - new BasicNameValuePair("code", code) + new BasicNameValuePair("code", code), + new BasicNameValuePair("redirect_uri", redirectUri) + ); - HttpGet getMethod = getRequest("/profile/oauth2/accessToken", parameters); + HttpPost getMethod = postRequest("/esc-sso/oauth2.0/accessToken", parameters); return LoginStrategy.getAccessTokenMethod(getMethod, "access_token"); } @@ -77,7 +80,7 @@ public class PailaLoginStrategy implements LoginStrategy { new BasicNameValuePair("access_token", accessToken) ); - HttpGet getMethodUserInfo = getRequest("/profile/oauth2/profile", userInfoParams); + HttpGet getMethodUserInfo = getRequest("/esc-sso/oauth2.0/profile", userInfoParams); String userInfoResBody = null; HttpClient client = HttpClients.createDefault(); @@ -91,7 +94,7 @@ public class PailaLoginStrategy implements LoginStrategy { if (userDTO == null) { throw new NotFoundException(NOT_FOUND); } - return userDTO.getUid(); + return userDTO.getAttributes().getAccount_no(); } private HttpGet getRequest(String path, List parameters) { @@ -106,4 +109,17 @@ public class PailaLoginStrategy implements LoginStrategy { request.setHeader("Content-Type", "application/json"); return request; } + + private HttpPost postRequest(String path, List parameters) { + String userInfoUrl = null; + try { + userInfoUrl = new URIBuilder(baseUrl).setPath(path) + .setParameters(parameters).build().toString(); + } catch (URISyntaxException e) { + log.error(e.getMessage()); + } + HttpPost request = new HttpPost(userInfoUrl); + request.setHeader("Content-Type", "application/json"); + return request; + } } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 9cf97bb1..123b1bb0 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -10,7 +10,7 @@ chint: database: itinerary_booking username: tripbook password: W@Xgf25d&lRk*L0X# - url: https://gxdev03.chint.com/businesstravel/ + url: https://gxdev03.chint.com/businesstravelhome/ logging: level: org.springframework.jdbc.core.JdbcTemplate: DEBUG @@ -56,8 +56,8 @@ FSSC: paila: client-id: 0053df85723db94491e8 client-secret: 7368bcec4c0f004c40585f6ed1087d887897 - redirect-url: https://gxdev03.chint.com/businesstravel/ - base-url: http://signin-test.chint.com + redirect-url: https://gxdev03.chint.com/businesstravelhome/*.* + base-url: https://signin-test.chint.com token-name: token diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 7921bb8d..4fc270e2 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -9,7 +9,7 @@ chint: database: itinerary_booking username: root password: 123456 - url: https://gxdev03.chint.com/businesstravel/ + url: https://gxdev03.chint.com/businesstravelhome/ cTrip: baseUrl: https://ct.ctrip.com @@ -26,6 +26,6 @@ FSSC: paila: client-id: 0053df85723db94491e8 client-secret: 7368bcec4c0f004c40585f6ed1087d887897 - redirect-url: https://gxdev03.chint.com/businesstravel/ - base-url: http://signin-test.chint.com + redirect-url: https://gxdev03.chint.com/businesstravelhome/*.* + base-url: https://signin-test.chint.com token-name: token diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 676ed1bd..cc10ab02 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -21,7 +21,7 @@ chint: database: itinerary_booking username: tripbook password: W@Xgf25d&lRk*L0X# - url: https://gxdev03.chint.com/businesstravel/ + url: https://gxdev03.chint.com/businesstravelhome/ logging: level: @@ -45,8 +45,8 @@ FSSC: paila: client-id: 0053df85723db94491e8 client-secret: 7368bcec4c0f004c40585f6ed1087d887897 - redirect-url: https://gxdev03.chint.com/businesstravel/ - base-url: http://signin-test.chint.com + redirect-url: https://gxdev03.chint.com/businesstravelhome/*.* + base-url: https://signin-test.chint.com token-name: token bpm: