同步代码
This commit is contained in:
parent
71a44f4588
commit
ee0abe3fbf
|
@ -130,4 +130,35 @@ public class LoginController {
|
||||||
userLoginResult.getUser().setManaLevel(null);
|
userLoginResult.getUser().setManaLevel(null);
|
||||||
return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult);
|
return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("商旅平台单点")
|
||||||
|
@Transactional
|
||||||
|
@PostMapping("/login/sso/mobile")
|
||||||
|
public Result<UserLoginResult> loginSSOMobile(@RequestBody UserLoginParam userLoginParam){
|
||||||
|
|
||||||
|
String employeeNo = pailaLoginStrategy.login(userLoginParam.getCode());
|
||||||
|
|
||||||
|
userLoginParam.setSfno(employeeNo);
|
||||||
|
UserLoginResult userLoginResult = authenticateService
|
||||||
|
.authenticateEmployeeNo(userLoginParam);
|
||||||
|
|
||||||
|
//异步执行更新用户信息到同程
|
||||||
|
User currentUser = userLoginResult.getUser();
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
BaseContext.setCurrentUser(currentUser);
|
||||||
|
lyUserRequest.saveCurrentUser();
|
||||||
|
BaseContext.removeCurrentUser();
|
||||||
|
});
|
||||||
|
//异步执行更新用户信息到携程
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
BaseContext.setCurrentUser(currentUser);
|
||||||
|
cTripUserSaveRequest.saveUserToCTrip();
|
||||||
|
BaseContext.removeCurrentUser();
|
||||||
|
});
|
||||||
|
|
||||||
|
//清除职级信息
|
||||||
|
userLoginResult.getUser().setProfLevel(null);
|
||||||
|
userLoginResult.getUser().setManaLevel(null);
|
||||||
|
return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,6 @@ public class PailaLoginStrategy implements LoginStrategy {
|
||||||
new BasicNameValuePair("client_secret", clientSecret),
|
new BasicNameValuePair("client_secret", clientSecret),
|
||||||
new BasicNameValuePair("code", code),
|
new BasicNameValuePair("code", code),
|
||||||
new BasicNameValuePair("redirect_uri", redirectUri)
|
new BasicNameValuePair("redirect_uri", redirectUri)
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
HttpPost getMethod = postRequest("/esc-sso/oauth2.0/accessToken", parameters);
|
HttpPost getMethod = postRequest("/esc-sso/oauth2.0/accessToken", parameters);
|
||||||
|
|
|
@ -0,0 +1,125 @@
|
||||||
|
package com.chint.application.services.login.strategy;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.chint.application.dtos.UserDTO;
|
||||||
|
import com.chint.application.services.login.LoginStrategy;
|
||||||
|
import com.chint.domain.exceptions.SSOLoginException;
|
||||||
|
import com.chint.domain.factoriy.user.UserFactory;
|
||||||
|
import com.chint.domain.repository.UserRepository;
|
||||||
|
import com.chint.interfaces.rest.user.UserHttpRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
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;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class PailaMobileLoginStrategy implements LoginStrategy {
|
||||||
|
|
||||||
|
@Value("${paila.base-url}")
|
||||||
|
private String baseUrl;
|
||||||
|
|
||||||
|
@Value("${paila.client-mobile-id}")
|
||||||
|
private String clientId;
|
||||||
|
|
||||||
|
@Value("${paila.client-mobile-secret}")
|
||||||
|
private String clientSecret;
|
||||||
|
|
||||||
|
@Value("${paila.redirect-mobile-url}")
|
||||||
|
private String redirectUri;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserHttpRequest userHttpRequest;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserFactory userFactory;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<String> getAccessToken(String code) {
|
||||||
|
|
||||||
|
log.info("开始执行登录");
|
||||||
|
List<NameValuePair> parameters = Arrays.asList(
|
||||||
|
new BasicNameValuePair("grant_type", "authorization_code"),
|
||||||
|
new BasicNameValuePair("client_id", clientId),
|
||||||
|
new BasicNameValuePair("client_secret", clientSecret),
|
||||||
|
new BasicNameValuePair("code", code),
|
||||||
|
new BasicNameValuePair("redirect_uri", redirectUri)
|
||||||
|
);
|
||||||
|
|
||||||
|
HttpPost getMethod = postRequest("/esc-sso/oauth2.0/accessToken", parameters);
|
||||||
|
return LoginStrategy.getAccessTokenMethod(getMethod, "access_token");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUserInfo(String accessToken) {
|
||||||
|
|
||||||
|
|
||||||
|
List<NameValuePair> userInfoParams = Collections.singletonList(
|
||||||
|
new BasicNameValuePair("access_token", accessToken)
|
||||||
|
);
|
||||||
|
|
||||||
|
HttpGet getMethodUserInfo = getRequest("/esc-sso/oauth2.0/profile", userInfoParams);
|
||||||
|
|
||||||
|
String userInfoResBody = null;
|
||||||
|
HttpClient client = HttpClients.createDefault();
|
||||||
|
try {
|
||||||
|
HttpResponse userInfoRes = client.execute(getMethodUserInfo);
|
||||||
|
userInfoResBody = EntityUtils.toString(userInfoRes.getEntity(), "UTF-8");
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
UserDTO userDTO = JSON.parseObject(userInfoResBody, UserDTO.class);
|
||||||
|
if (userDTO == null) {
|
||||||
|
throw new SSOLoginException(NOT_FOUND);
|
||||||
|
}
|
||||||
|
return userDTO.getAttributes().getAccount_no();
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpGet getRequest(String path, List<NameValuePair> parameters) {
|
||||||
|
String userInfoUrl = null;
|
||||||
|
try {
|
||||||
|
userInfoUrl = new URIBuilder(baseUrl).setPath(path)
|
||||||
|
.setParameters(parameters).build().toString();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
HttpGet request = new HttpGet(userInfoUrl);
|
||||||
|
request.setHeader("Content-Type", "application/json");
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpPost postRequest(String path, List<NameValuePair> 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,10 +25,7 @@ public interface JdbcLocationRepository extends CrudRepository<Location, Long> {
|
||||||
|
|
||||||
Location findByLocationName(String locationName);
|
Location findByLocationName(String locationName);
|
||||||
|
|
||||||
|
List<Location> findByLocationNameIn(Collection<String> locationName);
|
||||||
|
|
||||||
List<Location> findByLocationIdIn(Collection<Long> locationId);
|
List<Location> findByLocationIdIn(Collection<Long> locationId);
|
||||||
|
|
||||||
List<Location> findByLocationNameInAndLocationPathContainingAndLevel(Collection<String> locationName,
|
|
||||||
String locationPath,
|
|
||||||
Integer level);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,9 @@ paila:
|
||||||
client-id: 0053df85723db94491e8
|
client-id: 0053df85723db94491e8
|
||||||
client-secret: 7368bcec4c0f004c40585f6ed1087d887897
|
client-secret: 7368bcec4c0f004c40585f6ed1087d887897
|
||||||
redirect-url: https://gxdev03.chint.com/businesstravelhome/#/
|
redirect-url: https://gxdev03.chint.com/businesstravelhome/#/
|
||||||
|
client-mobile-id: 9b24c91ead42ee4b6918
|
||||||
|
client-mobile-secret: e54494f1272ffd41b818980f1f8524fd68ef
|
||||||
|
redirect-mobile-url: https://gxdev03.chint.com/businesstravelmhome/#/
|
||||||
base-url: https://signin-test.chint.com
|
base-url: https://signin-test.chint.com
|
||||||
token-name: token
|
token-name: token
|
||||||
|
|
||||||
|
|
|
@ -27,5 +27,8 @@ paila:
|
||||||
client-id: 0053df85723db94491e8
|
client-id: 0053df85723db94491e8
|
||||||
client-secret: 7368bcec4c0f004c40585f6ed1087d887897
|
client-secret: 7368bcec4c0f004c40585f6ed1087d887897
|
||||||
redirect-url: https://gxdev03.chint.com/businesstravelhome/#/
|
redirect-url: https://gxdev03.chint.com/businesstravelhome/#/
|
||||||
|
client-mobile-id: 9b24c91ead42ee4b6918
|
||||||
|
client-mobile-secret: e54494f1272ffd41b818980f1f8524fd68ef
|
||||||
|
redirect-mobile-url: https://gxdev03.chint.com/businesstravelmhome/#/
|
||||||
base-url: https://signin-test.chint.com
|
base-url: https://signin-test.chint.com
|
||||||
token-name: token
|
token-name: token
|
||||||
|
|
|
@ -46,6 +46,9 @@ paila:
|
||||||
client-id: 0053df85723db94491e8
|
client-id: 0053df85723db94491e8
|
||||||
client-secret: 7368bcec4c0f004c40585f6ed1087d887897
|
client-secret: 7368bcec4c0f004c40585f6ed1087d887897
|
||||||
redirect-url: https://gxdev03.chint.com/businesstravelhome/#/
|
redirect-url: https://gxdev03.chint.com/businesstravelhome/#/
|
||||||
|
client-mobile-id: 9b24c91ead42ee4b6918
|
||||||
|
client-mobile-secret: e54494f1272ffd41b818980f1f8524fd68ef
|
||||||
|
redirect-mobile-url: https://gxdev03.chint.com/businesstravelmhome/#/
|
||||||
base-url: https://signin-test.chint.com
|
base-url: https://signin-test.chint.com
|
||||||
token-name: token
|
token-name: token
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ class RouteApplicationTests {
|
||||||
System.out.println(login);
|
System.out.println(login);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
void arrayToStr(){
|
void arrayToStr(){
|
||||||
List<Long> ids = List.of(1L,2L,3L,4L);
|
List<Long> ids = List.of(1L,2L,3L,4L);
|
||||||
System.out.println(Arrays.toString(ids.toArray()));
|
System.out.println(Arrays.toString(ids.toArray()));
|
||||||
|
|
Loading…
Reference in New Issue