王 垚
2021-11-12 0ce538e3c3dc01153ce1bfc2d75276881206c222
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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("登录失败!");
            }
        }
 
    }
}