using Kingdee.BOS.WebApi.Client;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Configuration;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace Demo.Utility
|
{
|
public class CloudClient : K3CloudApiClient
|
{
|
public const string KDApiUrl = "http://localhost//k3cloud/";
|
public CloudClient(string serverUrl = KDApiUrl) : base(serverUrl)
|
{
|
var dbId = GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "DbId");
|
var useName = GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "UserName");
|
var pwd = 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 = GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "DbId");
|
var useName = GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "UserName");
|
var pwd = 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 String GetConfigKey(String configPath, String key)
|
{
|
Configuration ConfigurationInstance = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap()
|
{
|
ExeConfigFilename = configPath
|
}, ConfigurationUserLevel.None);
|
|
|
if (ConfigurationInstance.AppSettings.Settings[key] != null)
|
return ConfigurationInstance.AppSettings.Settings[key].Value;
|
else
|
|
return string.Empty;
|
}
|
}
|
}
|