Browse Source

协鼎登录更改

lihui007 3 years ago
parent
commit
04ae357ff8

+ 18 - 9
user_auth/src/main/java/com/huaxu/dto/thirdparty/XieDingResultDto.java

@@ -8,20 +8,29 @@ import lombok.Data;
 public class XieDingResultDto {
 
     @ApiModelProperty(value="状态")
-    private boolean status;
+    private boolean success;
 
     @ApiModelProperty(value="消息")
-    private String  msg;
+    private String  message;
 
-    @ApiModelProperty(value="密码")
-    private String password;
+    @ApiModelProperty(value="数据返回")
+    private XieDingData data;
 
-    @ApiModelProperty(value="singleKey")
-    private String singleKey;
-
-    @ApiModelProperty(value="token")
-    private String token;
+    @ApiModelProperty(value="code")
+    private String code;
 
     @ApiModelProperty(value="请求第三方的前缀url地址")
     private String prefixUrl;
+
+    @Data
+    public static class XieDingData {
+        @ApiModelProperty(value="密码")
+        private String password;
+
+        @ApiModelProperty(value="singleKey")
+        private String singleKey;
+
+        @ApiModelProperty(value="token")
+        private String token;
+    }
 }

+ 18 - 14
user_auth/src/main/java/com/huaxu/service/impl/thirdparty/XiedingLoginServiceImpl.java

@@ -42,15 +42,19 @@ public class XiedingLoginServiceImpl implements ThirdPartyLoginService {
 
     @Override
     public String getToken(LoginQueryDto queryDto) {
-        return this.httpInfo(queryDto).getToken();
+        return this.httpInfo(queryDto).getData().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());
+        try {
+            XieDingResultDto resultDto = this.httpInfo(queryDto);
+            String token     = resultDto.getData().getToken();
+            String prefixUrl = resultDto.getPrefixUrl();
+            return String.format(ssoConfig.getLoginUrl(), prefixUrl, token, queryDto.getSystemType());
+        } catch (NullPointerException e) {
+            throw new ServiceException(ResultStatus.ERROR.getStatus(), "获取第三登录请求出错!");
+        }
     }
 
     /**
@@ -79,24 +83,24 @@ public class XiedingLoginServiceImpl implements ThirdPartyLoginService {
         // 1.根据账户获取密码
         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());
+        if (StringUtils.isEmpty(resultDto.getData().getPassword())) {
+            throw new ServiceException(ResultStatus.ERROR.getStatus(), resultDto.getMessage());
         }
 
         // 2.绑定单点登陆用户
-        result    = HttpClientPoolUtil.sendGet(String.format(ssoConfig.getBindSingleUrl(), prefixUrl, account, resultDto.getPassword(), orgCode), charset);
+        result    = HttpClientPoolUtil.sendGet(String.format(ssoConfig.getBindSingleUrl(), prefixUrl, account, resultDto.getData().getPassword(), orgCode), charset);
         resultDto = JSONObject.parseObject(result, XieDingResultDto.class);
-        if (!resultDto.isStatus()) {
-            throw new ServiceException(ResultStatus.ERROR.getStatus(), resultDto.getMsg());
+        if (!resultDto.isSuccess()) {
+            throw new ServiceException(ResultStatus.ERROR.getStatus(), resultDto.getMessage());
         }
         // 3.获取token
-        String singleKey = resultDto.getSingleKey();
+        String singleKey = resultDto.getData().getSingleKey();
         Long timestamp   = System.currentTimeMillis();
-        String sign      = MD5Util.digest(resultDto.getSingleKey() + timestamp + secretKey);
+        String sign      = MD5Util.digest(resultDto.getData().getSingleKey() + timestamp + secretKey);
         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());
+        if (!resultDto.isSuccess()) {
+            throw new ServiceException(ResultStatus.ERROR.getStatus(), resultDto.getMessage());
         }
         // 设置请求的前缀
         resultDto.setPrefixUrl(prefixUrl);