|
单点登录的代码
单点登录的代码:
<html>
<head>
<title>灵当CRM单点登录接口??示</title>
<script>
var chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
//根??用户名称的长度生成随机??
function generateMixed(n) {
var res = "";
for(var i = 0; i < n ; i ++) {
var id = Math.ceil(Math.random()*15);
res += chars[id];
}
return res;
}
//name:表示登录用户名称
function createTokenByName(name)
{
var strlen=name.length;
return generateMixed(strlen);
}
//转换用户名称或token循环遍历str,替换每个字符串
function convert_str(str)
{
var strlen=str.length;
var digit="0123456789";
var loweralpha="abcdefghijklmnopqrstuvwxyz";
var upperalpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var ret_name="";
for(var i=0;i<strlen;i++)
{
var ch=str.substr(i,1);
if(digit.indexOf(ch)>=0)//,如果是??字
{
//10:变量digit的字符长度
ret_name+=digit.substr(9-digit.indexOf(ch),1);//对调
}
else if(loweralpha.indexOf(ch)>=0)
{
ret_name+=loweralpha.substr(25-loweralpha.indexOf(ch),1);//对调
}
else if(upperalpha.indexOf(ch)>=0)
{
ret_name+=upperalpha.substr(25-upperalpha.indexOf(ch),1);//对调
}
else
{
ret_name+=ch;
}
}
return ret_name;
}
function createName(token,name)
{
var token_name=name+token;
token_name=token_name.split("").reverse().join("");//逆序name
return token_name;
}
function loadcrm()
{
var token_authcode="aaabbbb"; //系统参??->接口参??中的“API接口授权码”,注意不是“API接口KEY”
var sso_loginuser="libb"; //??改为需要单点登录的用户账号
var after_str=convert_str(sso_loginuser);
var token=createTokenByName(after_str);
var user_name=createName(convert_str(token),after_str);
window.location="https://71mis.com/ldcrm/index.php?module=Users&action=Authenticate&name="+user_name+"&token="+token+"&tokenkey="+token_authcode;
}
</script>
</head>
<body>
</div>
<input type='button' onclick='loadcrm()' value='单点登录CRM'/>
</div>
</body>
</html>
|
|