1、拿到ticket
2、解析

public String login(String ticket, String redirectUri) {
        // 组装GET请求的参数
        Map<String, Object> param = new HashMap<>(2);
        param.put("ticket", ticket);
        param.put("service", redirectPrefix + "?redirectUri=sdnu-consume-bill-web");
        String result = HttpUtil.get(getUserInfoPrefix, param, 2000);
        System.out.println(result);
        Document xml = XmlUtil.parseXml(result);

        String userNo = null;
        String userName = null;
        String unitNo = null;

        try {
            userNo = xml.getElementsByTagName("cas:user").item(0).getTextContent();
            userName = xml.getElementsByTagName("cas:cn").item(0).getTextContent();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

        //生成老版token
        Map<String, Object> cookieMap = new HashMap<>(4);
        cookieMap.put(JwtUtil.KEY_USER_NO, userNo);
        cookieMap.put(JwtUtil.KEY_USER_NAME, userName);
        // TODO 去表里查
        cookieMap.put(JwtUtil.KEY_UNIT_NO, unitNo);
        String token = JwtUtil.generateToken(cookieMap);
        //生成zbpToken
        JwtUserInfo userInfo = new JwtUserInfo();
        userInfo.setUserId(userNo);
        userInfo.setName(userName);
        userInfo.setUnitNo(unitNo);
        userInfo.setTokenType(JwtUserInfo.TokenType.ADMIN);
        AuthorInfo authorInfo = tokenUtil.createAuthInfo(userInfo, null);
        String zbpToken = authorInfo.getToken();

        return String.format("<!DOCTYPE html>\n" +
                "<html lang='en'>\n" +
                "<head>\n" +
                "  <meta charset='UTF-8'>\n" +
                "  <title>正在登录</title>\n" +
                "</head>\n" +
                "<body>\n" +
                "  正在登录...\n" +
                "  <script>\n" +
                "    document.cookie = 'token=%s; path=/';\n" +
                "    document.cookie = 'userNo=%s; path=/';\n" +
                "    document.cookie = 'userName=%s; path=/';\n" +
                "    document.cookie = 'username=%s; path=/';\n" +
                // zbpToken相关
                "    document.cookie = 'zbpToken=%s; path=/';\n" +
                "    const url = sessionStorage.getItem('url');\n" +
                "    setTimeout(function(){\n" +
                "       if(url){" +
                "           window.location.href = url;\n" +
                "       }else{" +
                "           window.location.href = '%s';\n" +
                "       }\n" +
                "   },150);\n" +
                "  </script>\n" +
                "</body>\n" +
                "\n" +
                "</html>", token, userNo, userName, userName, zbpToken, redirectPrefix + redirectUri);
    }
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐