前端代码:
- function openIsc(){
- $.get("${ctx}/singleSignOn/getUrltoisc", function(msg) {
- try {
- if(!msg){
- Dialog.error("无法跳转");
- }
- else{
- var url = msg;
- Windows.open(url,'_blank','noopener noreferrer');
- }
- } catch (e) {
- console.log(e);
- Dialog.error("无法跳转");
- }
- });
通过 Ajax 访问后台, 后台取出链接通过 Windows.open 打开.
后台代码:
- public class SingleSignOnService {
- private final String host = "172.18.247.XXX"; // artemis 网关服务器 ip 端口;
- private final String appKey = "12345678"; // 秘钥 appkey
- private final String appSecret = "XXXXXXXXXX";// 秘钥 appSecret
- private final String sevice = "https://172.18.247.13/portal/";// 南钢海康威视安防监控平台网址
- private final String urlHead = "https://172.18.247.13:443/bic/ssoService/v1/tokenLogin?"; // 拼接 URL 字符串开头;
- private String getIscToken(String useAccount) throws ServiceException {
- /**
- * STEP1: 设置平台参数, 根据实际情况, 设置 host appkey appsecret 三个参数.
- */
- ArtemisConfig.host = host; // artemis 网关服务器 ip 端口
- ArtemisConfig.appKey = appKey; // 秘钥 appkey
- ArtemisConfig.appSecret = appSecret;// 秘钥 appSecret
- /**
- * STEP2: 设置 OpenAPI 接口的上下文
- */
- final String ARTEMIS_PATH = "/artemis";
- /**
- * STEP3: 设置接口的 URI 地址
- */
- String getTokenUrl = ARTEMIS_PATH+"/api/cas/v1/tgt/login";
- Map<String, String> path = new HashMap<String, String>(2) {
- {
- put("https://", getTokenUrl); // 根据现场环境部署确认是 http 还是 https
- }
- };
- /**
- * STEP4: 设置参数提交方式
- */
- String contentType = "application/json";
- /**
- * STEP5: 组装请求参数
- */
- Map<String, String> body = new HashMap<String, String>();
- body.put("userCode", useAccount);
- body.put("service",sevice );
- body.put("language", "zh_CN");
- /**
- * STEP6: 调用接口
- */
- String result = ArtemisHttpUtil.doGetArtemis(path, body, null, contentType, null);// get 请求 application/JSON 类型参数
- JSONObject resData = JSONObject.parseObject(result);
- ServiceAssert.hasText(resData.toString(), "调用接口失败");
- ServiceAssert.isTrue(resData.containsKey("code"), "获取 token 失败");
- String dataString = resData.getString("data");
- JSONObject tokenData = JSONObject.parseObject(dataString);
- String token = tokenData.getString("token");
- return token;
- }
- /**
- * 获取 isc 单点登录 url55 * @date 2019 年 12 月 11 日 下午 5:34:20
- * @param userAccount 工号
- * @return
- * @throws ServiceException
- */
- public String getIscIndexURL(String useAccount) throws ServiceException {
- return urlHead+"token="+getIscToken(useAccount)+"&service="+sevice;
- }
- }
来源: http://www.bubuko.com/infodetail-3383305.html