using Kingdee.BOS.WebApi.Client;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using ZD.Share.Common;
|
|
namespace ZD.Cloud.WebApi
|
{
|
public class CloudClient : K3CloudApiClient
|
{
|
public const string KDApiUrl = "http://localhost/K3Cloud/";
|
public CloudClient(string serverUrl = KDApiUrl) : base(serverUrl)
|
{
|
var dbId = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "DbId");
|
var useName = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "UserName");
|
var pwd = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "PassWord");
|
//var url = GetKey(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "/kdapi.config", "KDApiUrl");
|
var loginResult = ValidateLogin(dbId, useName, pwd, 2052);
|
var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();
|
//登录结果类型等于1,代表登录成功
|
if (resultType != 1)
|
{
|
throw new Exception("登录失败!");
|
}
|
}
|
|
public CloudClient(string serverUrl = KDApiUrl, int timeout = 3600) : base(serverUrl, timeout)
|
{
|
var dbId = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "DbId");
|
var useName = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "UserName");
|
var pwd = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "PassWord");
|
//var url = GetKey(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "/kdapi.config", "KDApiUrl");
|
var loginResult = ValidateLogin(dbId, useName, pwd, 2052);
|
var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();
|
//登录结果类型等于1,代表登录成功
|
if (resultType != 1)
|
{
|
throw new Exception("登录失败!");
|
}
|
}
|
|
|
public static void K3ApiClient(string serverUrl = "", string dbId = "", string useName = "", string pwd = "")
|
{
|
if (string.IsNullOrEmpty(serverUrl))
|
{
|
serverUrl = KDApiUrl;
|
}
|
if (string.IsNullOrEmpty(dbId))
|
{
|
dbId = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "DbId");
|
}
|
if (string.IsNullOrEmpty(useName))
|
{
|
useName = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "UserName");
|
}
|
if (string.IsNullOrEmpty(pwd))
|
{
|
pwd = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "PassWord");
|
}
|
|
if (string.IsNullOrEmpty(dbId) || string.IsNullOrEmpty(useName) || string.IsNullOrEmpty(pwd))
|
throw new Exception("配置文件或传参有误!");
|
|
K3CloudApiClient apiClient = new K3CloudApiClient(serverUrl);
|
var loginResult = apiClient.ValidateLogin(dbId, useName, pwd, 2052);
|
var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();
|
//登录结果类型等于1,代表登录成功
|
if (resultType != 1)
|
{
|
throw new Exception("登录失败!");
|
}
|
}
|
|
}
|
}
|