免密碼登入方式
首先在金蝶雲星空進行第三方登入授權。
第三方系統登入授權
登入接口定義:
/// 第三方系統登入授權
/// 資料中心ID
/// 使用者名稱
/// 第三方系統應用Id
/// 第三方系統應用秘鑰
/// 語言id,中文為2052,中文繁體為3076,英文為1033
///
public string LoginByAppSecret(string dbId, string userName, string appId, string appSecret, int lcid)
傳回結果:
{
"Message": null,
"MessageCode": null,
"LoginResultType": 1,// 0 密碼錯誤,1 登入成功, -1 登入失敗
"Context":{上下文資訊相關}
"KDSVCSessionId": null,
"FormId": null,
"RedirectFormParam": null,
"FormInputObject": null,
"ErrorStackTrace": null,
"Lcid": 0,
"AccessToken": null,
"KdAccessResult": null,
"IsSuccessByAPI": true
}
代碼示例
1)SDK輔助類示例(引用Kingdee.BOS.WebAPI.Client.dll)
引用元件Kingdee.BOS.WebApi.Client.dll
下載下傳連結: https://pan.baidu.com/s/1RthbrrtUgeqWGi-eLM-yjg
提取碼: eqin
private K3CloudApiClient apiClient = new K3CloudApiClient("http://localhost/k3cloud/");//serverUrl需要以“/”結尾
public bool LoginByAppSecret()
{
string appId = "203502_5f6p2avOzuDXX5XE617sywzt7Nw7Roru";
string appSecret = "2825766ee71f4002b24d78b6b9a9bc53";
string loginResult = apiClient.LoginByAppSecret(
"5dde42aa8b86d7",
"yz",
appId,
appSecret,
2052);
JObject loginResultObj = JObject.Parse(loginResult);
JToken loginResultType;
loginResultObj.TryGetValue("LoginResultType", out loginResultType);
// 登陸成功,開始儲存資料
//loginResultType.Value():
// 0 密碼錯誤
// 1 登入成功
// -1 登入失敗
if (loginResultType != null && loginResultType.Value() == 1)
{
return true;
}
else
{
return false;
}
}
2)無引用元件示例(不引用金蝶的元件):
http://ServerIp/K3Cloud/接口命名空間.接口實作類名.方法,元件名.common.kdsvc
string appId = "203502_5f6p2avOzuDXX5XE617sywzt7Nw7Roru";
string appSecret = "2825766ee71f4002b24d78b6b9a9bc53";
HttpClient httpClient = new HttpClient();
httpClient.Url = "http://localhost/k3cloud/Kingdee.BOS.WebApi.ServicesStub.AuthService.LoginByAppSecret.common.kdsvc";
List Parameters = new List();
Parameters.Add("5dde42aa8b86d7");//帳套Id
Parameters.Add("yz");//使用者名
Parameters.Add(appId);
Parameters.Add(appSecret);
Parameters.Add(2052);
httpClient.Content = JsonConvert.SerializeObject(Parameters);
var iResult = JObject.Parse(httpClient.AsyncRequest())["LoginResultType"].Value();
if (iResult == 1)
{
//todo:驗證成功,處理業務
}