Bootstrap

泛微E9下开发单点登陆金蝶云星空

1、配置信息

需要金蝶方提供的参数

#账套id     金蝶提供
DBID=
#应用id   金蝶提供
appid=
#用户名   金蝶提供
usr=
#密钥   金蝶提供
appsecret=

将这些信息配置到一个固定的配置文件中。

2、封装加密签名

 User user = HrmUserVarify.getUser(request, response);
 //数据中心Id
 String dbid = baseBean.getPropValue("wn_senderp", "DBID");
 //用户名
 String username = user.getLoginid();
 //第三方系统登录授权的应用Id;
 String appId = baseBean.getPropValue("wn_senderp", "appid");
 //第三方系统登录授权的应用密钥;
 String appSecret = baseBean.getPropValue("wn_senderp", "appsecret");
 //语言标识 中文:2052,繁体:3067,英文:1033
 int lcId = 2052;
 // 获取时间戳,只精准到秒级
 long timestamp = System.currentTimeMillis() / 1000;
//获取签章数据
ArrayList<String> signeddataList = new ArrayList<>();
signeddataList.add(dbid);
signeddataList.add(appId);
signeddataList.add(appSecret);
signeddataList.add(username);
signeddataList.add(timestamp + "");
//获取加密签名
String signdata = null;
signdata = getUrlParam(signeddataList);

getUrlParam方法

/**
 * 循环数组,重新排列成新的字符串加密操作
 * @param keys
 * @return
 * @throws NoSuchAlgorithmException
 */
public static String getUrlParam(ArrayList<String> keys) throws NoSuchAlgorithmException {

    for (int i = 0; i < keys.size() - 1; i++) {
        for (int j = 0; j < keys.size() - i - 1; j++) {
            String pre = keys.get(j);
            String next = keys.get(j + 1);
            if (isMoreThan(pre, next)) {
                String temp = pre;
                keys.set(j, next);
                keys.set(j + 1, temp);
            }
        }
    }
    StringBuffer buffer = new StringBuffer();
    for (String str : keys) {
        buffer.append(str);
    }
    String gen = SHA1.gen(buffer.toString());
    return gen;
}

isMoreThan方案

该方法很重要

 /**
     * 比较两个字符串的大小,按照字母ASCII码进行比较
     * @param pre
     * @param next
     * @return
     */
    private static boolean isMoreThan(String pre, String next) {
        if (null == pre || null == next || "".equals(pre) || "".equals(next)) {
            return false;
        }

        char[] c_pre = pre.toCharArray();
        char[] c_next = next.toCharArray();

        int minSize = Math.min(c_pre.length, c_next.length);

        for (int i = 0; i < minSize; i++) {
            if ((int) c_pre[i] > (int) c_next[i]) {
                return true;
            } else if ((int) c_pre[i] < (int) c_next[i]) {
                return false;
            }
        }
        if (c_pre.length > c_next.length) {
            return true;
        }

        return false;
    }

3、封装跳转到参数并跳转

    String ud3 = "{'dbid':'" + dbid + "','username':'" + username + "','appid':'" + appId + "','signeddata':'" + signdata + "','timestamp':'" + timestamp + "','lcid':'" + lcId + "'," +
            "'origintype':'SimPas','entryrole':'','formid':'','formtype':'','pkid':'','otherargs':''}";
    log.info("ud3=" + ud3);
    JSONObject jsonObject = JSON.parseObject(ud3);
    Base64 base64 = new Base64();
    String base64Sign = null;
    base64Sign = base64.encode(jsonObject.toJSONString(), "UTF-8");
    log.info("base64Sign=" + base64Sign);
    String ssologinurl = baseBean.getPropValue("wn_senderp", "ssologinurl")+ base64Sign;
    log.info("ssologinurl=" + ssologinurl);
    response.sendRedirect(ssologinurl);
;