<%@page pageEncoding="GBK" contentType="text/html; charset=GBK" %>
<%@page import="java.security.SecureRandom"%>
<%@page import="javax.crypto.Cipher"%>
<%@page import="javax.crypto.SecretKey"%>
<%@page import="javax.crypto.SecretKeyFactory"%>
<%@page import="javax.crypto.spec.DESKeySpec"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
<script language=javascript src="jquery.js"></script>
<title></title>
</head>
<%!
private static String DES = "DES";
private static String PASSWORD_CRYPT_KEY = "xbandfamily";
public static String decrypt(String data) {
try {
return new String(decrypt(hex2byte(data.getBytes()),
PASSWORD_CRYPT_KEY.getBytes()));
} catch (Exception e) {
}
return null;
}
public static byte[] hex2byte(byte[] b) {
if ((b.length % 2) != 0)
throw new IllegalArgumentException("长度不是偶数");
byte[] b2 = new byte[b.length / 2];
for (int n = 0; n < b.length; n += 2) {
String item = new String(b, n, 2);
b2[n / 2] = (byte) Integer.parseInt(item, 16);
}
return b2;
}
public static byte[] decrypt(byte[] src, byte[] key) throws Exception {
// DES算法要求有一个可信任的随机数源
SecureRandom sr = new SecureRandom();
// 从原始密匙数据创建一个DESKeySpec对象
DESKeySpec dks = new DESKeySpec(key);
// 创建一个密匙工厂,然后用它把DESKeySpec对象转换成
// 一个SecretKey对象
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
// Cipher对象实际完成解密操作
Cipher cipher = Cipher.getInstance(DES);
// 用密匙初始化Cipher对象
cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
// 现在,获取数据并解密
// 正式执行解密操作
return cipher.doFinal(src);
}
//String usercode = nc.uap.lfw.core.LfwRuntimeEnvironment.getLfwSessionBean().getUser_code();
%>
<%String pk_user = decrypt(request.getParameter("pk_user"));
String date = decrypt(request.getParameter("date"));
String key = decrypt(request.getParameter("key"));
String parameters = "&pk_user="+pk_user+"&date="+date+"&key="+key;
String ip=request.getParameter("ip");
%>
<body>
<script>
$.ajax({
url:"<%=ip%>/sale-reminder/index2?<%=parameters%>",//单点登录的管理平台报表服务器
dataType:"jsonp",//跨域采用jsonp方式
//data:{"pk_user":"100112100000003MGA9F","fr_password":"rfchina38882777"},//获取用户名密码
jsonp:"callback",
timeout:5000,//超时时间(单位:毫秒)
success:function(data) { //http://192.168.6.211:8881
if (data.status === "success") {
//window.open("<%=ip%>/sale-reminder/index");//认证成功跳转页面,因为ajax不支持重定向所有需要跳转的设置
//登录成功
window.top.location.href = "<%=ip%>/sale-reminder/index";
} else if (data.status === "fail"){
alert("用户名或密码错误");//登录失败(用户名或密码错误)
}
},
error:function(){
alert("超时或服务器其他错误");// 登录失败(超时或服务器其他错误)
}
});
</script>
</body>
</html>