现在已推出V2登录协议,请参考V2
https://vip.kingdee.com/article/9788
1 启用第三方系统登录授权
2 配置启动服务插件
在Kingdee\K3Cloud\WebSite\App_Data文件下,修改Common.config文件,
增加配置节 <add key ="StartAppPlugin" value="Kingdee.BOS.ServiceFacade.StartApp.MacVerify,Kingdee.BOS.ServiceFacade.StartApp"/>
3 测试第三方系统单点登陆
使用生成的链接测试是否能正常的单点登录。
4 在第三方系统中生成签名授权的URL
Silverlight示例: http://xxxx/k3cloud/silverlight/index.aspx?ud=|dbid|username|appid|signeddata|timestamp[|lcid]
协议内容解析
参数格式:ud=|dbid|username|appid|signeddata|timestamp[|lcid],其中ud为参数名;协议格式:|dbid|username|appid|signeddata|timestamp[|lcid]
dbid:数据中心的ID;
username:用户名称;
appid:应用程序ID,通过Administrator登录数据中心后,在【系统管理】分类的【第三方系统登录授权】功能里面进行新增维护;
signeddata:数据签名串,通过公钥和用户数据进行运算得到
timestamp:登录时间戳(Unix时间戳,定义为从格林威治时间1970年01月01日00时00分00秒起至现在的总秒数)
lcid(可选):语言ID,中文2052(默认),英文1033,繁体3076
.
NET示例代码如下:
using Kingdee.BOS.Authentication;
usingKingdee.BOS.ServiceFacade.KDServiceClient.User;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
classProgram
{
staticvoidMain(string[] args)
{
intl cId = 2052;
long timestamp = DateTimeFormatUtils.CurrentTimeMillis()/1000;//时间戳
string dbId = "57b11d0f7a3b1a";//数据中心ID
string usserName = "ly";//用户名称
string appId = "SRMLightApp";//第三方系统应用Id
string appSecret = "7d9169bfbdc34e9cbd96069db5e72917";//第三方系统应用秘钥
string[] arr = new string[]{ dbId, usserName, appId, appSecret, timestamp.ToString() };
string sign = Kingdee.BOS.Util.SHA1Util.GetSignature(arr);//签名
string urlPara= string.Format("|{0}|{1}|{2}|{3}|{4}|{5}",dbId, usserName, appId, sign, timestamp, lcId);
urlPara=System.Text.UTF8Encoding.Default.GetBytes(urlPara).ToBase64());// Base64编码
string url= http://localhost/K3Cloud/Silverlight/IndexSL.aspx?ud=+urlPara;// Silverlight入口链接
Console.ReadLine();
}
}
}
SHA1签名算法
/// <summary>
/// SHA1签名
/// </summary>
/// <param name="arr"></param>
/// <returns></returns>
public static string GetSignature(string[] arr)
{
//1. 将数组进行排序
//2. 将数组拼接成一个字符串进行sha1加密
Array.Sort(arr, StringComparer.Ordinal);
var arrString = string.Join("", arr);
var sha1 = SHA1.Create();
var sha1Arr = sha1.ComputeHash(Encoding.UTF8.GetBytes(arrString));
StringBuilder enText = new StringBuilder();
foreach (var b in sha1Arr)
{
enText.AppendFormat("{0:x2}", b);
}
return enText.ToString();
}
JAVA示例代码如下:
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Arrays;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
public class SignHelper {
public static void main(String[] args) throws UnsupportedEncodingException {
String dbId = "598bee37c71a46";// 数据中心ID
String usserName = "ly";// 用户名称
String appId = "hr";// 第三方系统应用Id
String appSecret = "3c2ca0f150354a0c938e3bdf082d4984";// 第三方系统应用秘钥
long currentTime = System.currentTimeMillis() / 1000;
String timestamp = Long.toString(currentTime);
String[] strArray = { dbId, usserName, appId, appSecret, timestamp };
Arrays.sort(strArray);
String combStr = null;
for (int i = 0; i < strArray.length; i++) {
if (combStr == null || combStr == "") {
combStr = strArray[i];
} else {
combStr = combStr + strArray[i];
}
}
byte[] strByte = combStr.getBytes("UTF-8");
byte[] strSign = DigestUtils.sha(strByte);
String sign = bytesToHexString(strSign);
String urlPara = String.format("|%s|%s|%s|%s|%s|%s", dbId, usserName, appId, sign, timestamp, "2052");
urlPara = java.net.URLEncoder.encode(urlPara, "UTF-8");
String url = "http://localhost/K3Cloud/Silverlight/IndexSL.aspx?ud=" + urlPara;// Silverlight入口链接
System.out.println(url);
}
public static String bytesToHexString(byte[] src) {
StringBuilder stringBuilder = new StringBuilder();
if (src == null || src.length <= 0) {
return null;
}
for (int i = 0; i < src.length; i++) {
int v = src[i] & 0xFF;
String hv = Integer.toHexString(v);
if (hv.length() < 2) {
stringBuilder.append(0);
}
stringBuilder.append(hv);
}
return stringBuilder.toString();
}
}
5 从第三方系统注销用户(此功能计划2018年7月份V7补丁发布)
接口地址:http://ip/K3Cloud/Kingdee.BOS.ServiceFacade.ServicesStub.User.UserService.LogoutByOtherSystem.common.kdsvc
请求类型:post
参数
参数名称:ap0
参数值:{"AcctID":"5ab22542230aaf","AppId":"hr","Username":"txt","SignedData":"4cdde33b74d55c328291a24f299cb745a50621bc","Timestamp":1525413177}
AcctID:数据中心ID
Username:为要注销的用户名称
AppId:应用ID
SignedData:签名数据,算法同上
Timestamp:时间戳
推荐阅读