package com.doumee.api.web; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.doumee.api.BaseController; import com.doumee.biz.system.SystemDictDataBiz; import com.doumee.core.annotation.excel.ExcelExporter; import com.doumee.core.annotation.pr.PreventRepeat; import com.doumee.core.constants.Constants; import com.doumee.core.model.ApiResponse; import com.doumee.core.model.LoginUserInfo; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.core.utils.HttpsUtil; import com.doumee.dao.business.dto.LoginRequestNewParam; import com.doumee.dao.business.model.Category; import com.doumee.dao.system.model.SystemJob; import com.doumee.service.business.CategoryService; import com.sun.deploy.net.HttpUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.UUID; /** * @author 江蹄蹄 * @date 2025/07/09 12:00 */ @Api(tags = "web登录相关接口") @RestController @RequestMapping("/web") @Slf4j public class LoginController extends BaseController { @Autowired private CategoryService categoryService; @Autowired private SystemDictDataBiz systemDictDataBiz; @ApiOperation("UK单点登录") @RequestMapping("/ukLogin") public void ukLogin(String tick, Object obj, HttpServletRequest request, HttpServletResponse response) throws Exception { LoginRequestNewParam requestParam = new LoginRequestNewParam(); // UK_ERROR_URL = "http://u.zhibang.com/sso/web/token/error"; String errorUrl =systemDictDataBiz.queryByCode(Constants.ZBOM_PARAM,Constants.ZBOM_UK_ERROR_URL).getCode(); try { log.error("请求参数TICK最原始===========:" + tick); JSONObject urlParams = new JSONObject(); log.info("请求参数:" + JSON.toJSONString(urlParams)); //TICKET_LOGIN_TEST = "http://testsso.zhibang.com:8080/esc-idm/api/v1/getUserInfo"; //TICKET_LOGIN = "https://sso.zbom.com/esc-idm/api/v1/getUserInfo"; String url = systemDictDataBiz.queryByCode(Constants.ZBOM_PARAM,Constants.ZBOM_TICKET_LOGIN_URL).getCode() + "?tick=" + URLEncoder.encode(tick,Constants.UTF); String post = HttpsUtil.get(url,true); log.info("返回参数:" + post); JSONObject json = JSONObject.parseObject(post); if (StringUtils.equals(json.getString("code"), "0")) { JSONObject userInfo = json.getJSONObject("data"); requestParam = JSONObject.toJavaObject(userInfo, LoginRequestNewParam.class); } else { log.error("案例库系统单点登录失败 错误原因获取tick失败" + json.getString("message")); response.sendRedirect(errorUrl + "?title=" + enCode("登陆错误") + "&msg="+ enCode(json.getString("message"))); return; } } catch (Exception e) { log.error("ticket接口请求错误:" + e.getMessage()); response.sendRedirect(errorUrl + "?title=" + enCode("登陆错误") + "&msg=" + enCode("系统繁忙,请稍后重试~")); return; } requestParam.setRediUrl("http://localhost:10087/#/login"); String token = UUID.randomUUID().toString()+"_doumee"; response.sendRedirect(requestParam.getRediUrl()+"?token="+token); } private String enCode(String string) { // TODO Auto-generated method stub String str = ""; try { str = java.net.URLEncoder.encode(string, "utf-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return str; } }