|
@@ -1,9 +1,8 @@
|
|
|
package com.huaxu.service.impl.thirdparty;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.alibaba.nacos.client.config.utils.MD5;
|
|
|
-import com.alibaba.nacos.common.util.Md5Utils;
|
|
|
import com.huaxu.config.SsoConfig;
|
|
|
+import com.huaxu.dao.AuthTenantMenuMapper;
|
|
|
import com.huaxu.dao.UserMapper;
|
|
|
import com.huaxu.dto.thirdparty.LoginQueryDto;
|
|
|
import com.huaxu.dto.thirdparty.XieDingResultDto;
|
|
@@ -38,11 +37,36 @@ public class XiedingLoginServiceImpl implements ThirdPartyLoginService {
|
|
|
@Autowired
|
|
|
private UserMapper userMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AuthTenantMenuMapper authMenuMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public String getToken(LoginQueryDto queryDto) {
|
|
|
- String httpIpPortUrl = "http://www.xdwater365.com/yhfw/security/security";
|
|
|
+ return this.httpInfo(queryDto).getToken();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getLoginUrl(LoginQueryDto queryDto) {
|
|
|
+ XieDingResultDto resultDto = this.httpInfo(queryDto);
|
|
|
+ String token = resultDto.getToken();
|
|
|
+ String prefixUrl = resultDto.getPrefixUrl();
|
|
|
+ return String.format(ssoConfig.getLoginUrl(), prefixUrl, token, queryDto.getSystemType());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Author lihui
|
|
|
+ * @Description 请求信息
|
|
|
+ * @Date 15:01 2021/4/19
|
|
|
+ * @Param [queryDto]
|
|
|
+ * @return com.huaxu.dto.thirdparty.XieDingResultDto
|
|
|
+ **/
|
|
|
+ private XieDingResultDto httpInfo(LoginQueryDto queryDto){
|
|
|
LoginUser currentUser = UserUtil.getCurrentUser();
|
|
|
- User user = userMapper.findThirdPartytLoginInfo(currentUser.getTenantId(), currentUser.getPhoneNumber());
|
|
|
+ String prefixUrl = authMenuMapper.findLinkPath(currentUser.getTenantId(), queryDto.getMenuId());
|
|
|
+ if (StringUtils.isEmpty(prefixUrl)) {
|
|
|
+ throw new ServiceException(ResultStatus.ERROR.getStatus(), "未设置请求地址");
|
|
|
+ }
|
|
|
+ User user = userMapper.findThirdPartytLoginInfo(currentUser.getId());
|
|
|
if (user == null || StringUtils.isEmpty(user.getLoginAccount())){
|
|
|
throw new ServiceException(ResultStatus.ERROR.getStatus(), "未设置登录账号");
|
|
|
}
|
|
@@ -53,13 +77,14 @@ public class XiedingLoginServiceImpl implements ThirdPartyLoginService {
|
|
|
String orgCode = user.getLoginOrgCode();
|
|
|
Charset charset = Charset.forName("utf-8");
|
|
|
// 1.根据账户获取密码
|
|
|
- String result = HttpClientPoolUtil.sendGet(String.format(ssoConfig.getPwdUrl(), httpIpPortUrl, account, orgCode), charset);
|
|
|
+ String result = HttpClientPoolUtil.sendGet(String.format(ssoConfig.getPwdUrl(), prefixUrl, account, orgCode), charset);
|
|
|
XieDingResultDto resultDto = JSONObject.parseObject(result, XieDingResultDto.class);
|
|
|
if (StringUtils.isEmpty(resultDto.getPassword())) {
|
|
|
throw new ServiceException(ResultStatus.ERROR.getStatus(), resultDto.getMsg());
|
|
|
}
|
|
|
+
|
|
|
// 2.绑定单点登陆用户
|
|
|
- result = HttpClientPoolUtil.sendGet(String.format(ssoConfig.getBindSingleUrl(), httpIpPortUrl, account, resultDto.getPassword(), orgCode), charset);
|
|
|
+ result = HttpClientPoolUtil.sendGet(String.format(ssoConfig.getBindSingleUrl(), prefixUrl, account, resultDto.getPassword(), orgCode), charset);
|
|
|
resultDto = JSONObject.parseObject(result, XieDingResultDto.class);
|
|
|
if (!resultDto.isStatus()) {
|
|
|
throw new ServiceException(ResultStatus.ERROR.getStatus(), resultDto.getMsg());
|
|
@@ -68,12 +93,13 @@ public class XiedingLoginServiceImpl implements ThirdPartyLoginService {
|
|
|
String singleKey = resultDto.getSingleKey();
|
|
|
Long timestamp = System.currentTimeMillis();
|
|
|
String sign = MD5Util.digest(resultDto.getSingleKey() + timestamp + secretKey);
|
|
|
- result = HttpClientPoolUtil.sendGet(String.format(ssoConfig.getTokenUrl(), httpIpPortUrl, singleKey, timestamp, sign, code), charset);
|
|
|
+ result = HttpClientPoolUtil.sendGet(String.format(ssoConfig.getTokenUrl(), prefixUrl, singleKey, timestamp, sign, code), charset);
|
|
|
resultDto = JSONObject.parseObject(result, XieDingResultDto.class);
|
|
|
if (!resultDto.isStatus()) {
|
|
|
throw new ServiceException(ResultStatus.ERROR.getStatus(), resultDto.getMsg());
|
|
|
}
|
|
|
- return resultDto.getToken();
|
|
|
+ // 设置请求的前缀
|
|
|
+ resultDto.setPrefixUrl(prefixUrl);
|
|
|
+ return resultDto;
|
|
|
}
|
|
|
-
|
|
|
}
|