Example #1
0
        /// <summary>
        /// t+接口登录获取Token
        /// </summary>
        /// <returns></returns>
        public static Result Login()
        {
            Result result = new Result();
            // v2 获取token 用户名 密码
            Config config         = new Config();
            string privateKeyPath = XmlPath.PemPath;

            if (string.IsNullOrEmpty(privateKeyPath) || !File.Exists(privateKeyPath))
            {
                result.Success = false;
                result.Message = "私钥文件丢失";
            }
            var header = new Dictionary <string, object>
            {
                { "appkey", config.Appkey },
                { "orgid", string.Empty },//90009444367
                { "appsecret", config.Appsecret }
            };

            RestSharp.Serializers.JsonSerializer jsonSerializer = new RestSharp.Serializers.JsonSerializer();
            string datas = jsonSerializer.Serialize(header);

            Ufida.T.EAP.Net.security.TokenManage tokenManage = new Ufida.T.EAP.Net.security.TokenManage();

            string signvalue = tokenManage.CreateSignedToken(datas, privateKeyPath);
            string authStr   = @"{""appKey"":""" + config.Appkey + @""",""authInfo"":""" + signvalue + @""",""orgId"":""""}";
            string encode    = Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(authStr));
            string serverUrl = config.TPlusUrl;

            if (serverUrl.Contains("api/v1"))
            {
                serverUrl = serverUrl.Replace("api/v1", "api/v2");
            }
            string        host       = serverUrl.Substring(0, serverUrl.IndexOf('/', serverUrl.IndexOf("//") + 2) + 1);
            TRestClient   restclient = new TRestClient(host);
            ITRestRequest restquest  = new TRestRequest();

            restquest.Resource = serverUrl.Replace(host, "") + "collaborationapp/GetRealNameTPlusToken?IsFree=1";
            restquest.AddParameter("Authorization", encode, TParameterType.HttpHeader);
            string pass = EncodeMD5(config.PassWord);
            string args = string.Format("{{userName:\"{0}\",password:\"{1}\",accNum:\"{2}\"}}", config.UserName, pass, config.AccountNum);

            restquest.AddParameter("_args", args);
            restquest.Method = TMethod.POST;
            string responsedata = restclient.Execute(restquest);

            Newtonsoft.Json.Linq.JObject token = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(responsedata);
            if (token["access_token"] != null)
            {
                string token_v2 = token["access_token"].ToString();
                result.Success = true;
                result.Message = token_v2;
            }
            else
            {
                result.Success = false;
                result.Message = responsedata;
            }
            return(result);
        }
Example #2
0
        private static string GetMetaservletCommand(object item)
        {
            var serializer = new RestSharp.Serializers.JsonSerializer();
            var serialized = serializer.Serialize(item);

            return(System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(serialized)));
        }
Example #3
0
        /// <summary>
        /// T+接口跑送数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static Result PostData(string token, string PostData, string ApiName)
        {
            Result result = new Result();

            //v2
            try
            {
                Config config = new Config();
                //业务请求的Authorization
                var customParas = new Dictionary <string, object>
                {
                    { "access_token", token },
                };

                //默认规则是当前参数+appsecret,组成签名的原值
                var bizheader = new Dictionary <string, object>
                {
                    { "appkey", config.Appkey },
                    { "orgid", string.Empty },
                    { "appsecret", config.Appsecret }
                };
                string privateKeyPath = XmlPath.PemPath;


                RestSharp.Serializers.JsonSerializer jsonSerializer = new RestSharp.Serializers.JsonSerializer();
                string bizdatas = jsonSerializer.Serialize(bizheader);
                Ufida.T.EAP.Net.security.TokenManage tokenManage = new Ufida.T.EAP.Net.security.TokenManage();
                string        bizAuthorization = tokenManage.CreateSignedToken(bizdatas, privateKeyPath, customParas);
                ITRestRequest restquest1       = new TRestRequest();
                restquest1.Method = TMethod.POST;
                string serverUrl = config.TPlusUrl;
                string host      = serverUrl.Substring(0, serverUrl.IndexOf('/', serverUrl.IndexOf("//") + 2) + 1);
                restquest1.Resource = serverUrl.Replace(host, "") + ApiName;
                string authStr1 = @"{""appKey"":""" + config.Appkey + @""",""authInfo"":""" + bizAuthorization + @""",""orgId"":" + @"""""" + @"}";
                string encode1  = Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(authStr1));
                restquest1.AddParameter("Authorization", encode1, TParameterType.HttpHeader);
                restquest1.AddParameter("_args", PostData);
                TRestClient restclient   = new TRestClient(host);
                string      responsedata = restclient.Execute(restquest1);
                try {
                    result.Success = true;
                    result.Message = responsedata;
                } catch {
                    result.Success = false;
                    result.Message = responsedata.Replace("'", "''");
                }
            }
            catch (RestException ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
        static void Main(string[] args)
        {
            ResponseDecoder json;
            LoanProSDK.Collections.CollectionsManager.SetCollectionsFilePath("../../collections.json");
            Communicator communicator = new Communicator();
            communicator.SetAuthorization("TOKEN HERE", "ID HERE");
            
            json = communicator.PerformRequest("odata.svc/Loans?$expand=LoanSetup,LoanSettings,Insurance,Collateral,Advancements");
            var loans = json.DecodeResponse("Loan");
            var serializer = new RestSharp.Serializers.JsonSerializer();
            Console.WriteLine(serializer.Serialize(loans));
            
            System.IO.File.WriteAllText("../../outputSingleThreaded.json", serializer.Serialize(loans));

            Console.WriteLine(LoanProSDK.Collections.CollectionsManager.IsValidCollection("loan.test.test"));
            Console.WriteLine(LoanProSDK.Collections.CollectionsManager.IsValidCollection("autopay.Status.Cancelled"));
            Console.WriteLine(LoanProSDK.Collections.CollectionsManager.TranslatePath("autopay.Amount Type.Fees Due"));

            LoanProSDK.LoanEntities.LoanSettings settings = new LoanProSDK.LoanEntities.LoanSettings();
            settings.cardFeeType = "Waive Fee3";
            Console.WriteLine(settings.cardFeeType);
            settings.cardFeeType = "Waive Fee";
            Console.WriteLine(settings.cardFeeType);

            json = communicator.PerformRequest("odata.svc/Loans?$expand=Payments/CustomFieldValues");
            var loans2 = json.DecodeResponse("Loan");
            var serializer2 = new RestSharp.Serializers.JsonSerializer();

            System.IO.File.WriteAllText("../../Received.json", json.ToString());
            System.IO.File.WriteAllText("../../Serialized.json", serializer2.Serialize(loans2));

            Console.WriteLine(serializer.Serialize(loans));

            Console.WriteLine("Press Any Key To Quit...");
            Console.ReadKey();
        }
Example #5
0
        static void Run(int postsNumber)
        {
            HackerNewsApi client     = new HackerNewsApi();
            List <int>    topStories = client.GetTopStories();

            int i = 1;
            int j = 0;

            while (i <= postsNumber && j <= topStories.Count)
            {
                HackerPost post    = client.GetHackerPost(topStories[j]);
                var        vc      = new ValidationContext(post, null);
                var        isValid = Validator.TryValidateObject(post, vc, null, true);
                if (isValid)
                {
                    RestSharp.Serializers.JsonSerializer serializer = new RestSharp.Serializers.JsonSerializer();
                    Console.WriteLine(serializer.Serialize(post));
                    i++;
                }
                j++;
            }
        }
Example #6
0
        public void it_serializes_to_the_correct_format()
        {
            // Arrange
            var serializer = new RestSharp.Serializers.JsonSerializer();

            // Act
            var json = serializer.Serialize(_query);

            // Assert
            Assert.AreEqual(String.Format("{{\"action\":\"query\",\"otherscope\":{{}},\"query\":\"{0}\"}}", _commandText), json);
        }