コード例 #1
0
 public void TestInitialize()
 {
     _openApiProxyClient = new OpenApiClient(new ProxyClientConfig
     {
         ApiKey = TestsHelper.GetCdiscountOpenApiKey()
     });
 }
コード例 #2
0
ファイル: SearchTests.cs プロジェクト: Cellenza/smart-apero
 public void TestInitialize()
 {
     _openApiProxyClient = new OpenApiClient(new ProxyClientConfig
     {
         ApiKey = TestsHelper.GetCdiscountOpenApiKey()
     });
 }
コード例 #3
0
 public void TestInitialize()
 {
     _openApiProxyClient = new OpenApiClient(new ProxyClientConfig
     {
         ApiKey = null
     });
 }
コード例 #4
0
 public void TestInitialize()
 {
     _openApiProxyClient = new OpenApiClient(new ProxyClientConfig
     {
         ApiKey = null
     });
 }
コード例 #5
0
        public ClientResponse Retranslate([FromBody] dynamic requestData)
        {
            try
            {
                var response = OpenApiClient.GetResponse(requestData, Request.Headers, new HttpMethod(Request.Method), Request.Path);

                var res = response.Content?.ReadAsStringAsync().Result;

                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    return new ClientResponse()
                           {
                               Status = new ApiResponseStatus()
                               {
                                   Code   = -2,
                                   Detail = String.Format("Response status code is {0}.", response.StatusCode)
                               }
                           }
                }
                ;

                ApiResponse openApirespoinse = System.Text.Json.JsonSerializer.Deserialize <ApiResponse>(res);
                dynamic     data             = openApirespoinse.Data is null ? null : Decryptor.DecriptRespose(openApirespoinse);

                return(new ClientResponse()
                {
                    Status = openApirespoinse.Status,
                    Data = data is null ? null : JsonConvert.DeserializeObject <ExpandoObject>(data, new ExpandoObjectConverter())
                });
            }
コード例 #6
0
        static async Task Main(string[] args)
        {
            OpenApiClient client = new OpenApiClient(new System.Net.Http.HttpClient());
            var           c      = await client.GetNearestStopAreasAsync(55.707919, 13.186684, 400);

            Console.WriteLine(c.GetType());
        }
コード例 #7
0
        static void Main()
        {
            var handler = new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => true
            };

            using (var httpClient = new HttpClient(handler))
            {
                httpClient.DefaultRequestHeaders.Add("ContentType", "application/json");
                var    plainTextBytes = System.Text.Encoding.UTF8.GetBytes("user1:password1");
                string val            = Convert.ToBase64String(plainTextBytes);
                httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + val);

                var client = new OpenApiClient("https://localhost:44359/", httpClient);

                var result = client.GetModulesAsync().Result;
                foreach (var module in result)
                {
                    Console.WriteLine($"{module.Id} : {module.SystemName}");
                }
            }

            Console.ReadLine();
        }
コード例 #8
0
ファイル: LoanController.cs プロジェクト: xuzhishen/open-sdk
        /// <summary>
        /// 可投标列表获取
        /// </summary>
        /// <returns></returns>
        // GET: Loan
        public ActionResult Index()
        {
            try
            {
                AuthInfo auth = Session["auth"] as AuthInfo;
                if (auth == null)
                {
                    return(Redirect("/auth"));
                }

                Result result = OpenApiClient.Send(Get_LoanList_URL, auth.AccessToken,
                                                   new PropertyObject("timestamp", DateTime.Now.ToString(), ValueTypeEnum.String));

                if (result.IsSucess)
                {
                    var model = JsonConvert.DeserializeObject <LoanListModels>(result.Context);

                    if (model.Result == 0)
                    {
                        string param = Request.QueryString["query"];

                        if (!string.IsNullOrEmpty(param))
                        {
                            param = param.Trim();

                            if (param == "AAA")
                            {
                                model.LoanList = model.LoanList.Where(p => p.CreditCode == "AAA").ToList();
                            }
                            else if (param == "rate")
                            {
                                model.LoanList = model.LoanList.Where(p => p.Rate >= 22).ToList();
                            }
                        }

                        model.LoanList = model.LoanList.OrderByDescending(p => p.Rate).ToList();
                        return(View("List", model.LoanList));
                    }
                    else
                    {
                        return(Content(model.ResultMessage));
                    }
                }
                else
                {
                    return(Content(result.ErrorMessage));
                }
            }
            catch (FormatException ex)
            {
                return(Content("密钥无效,请更换有效密钥"));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }
コード例 #9
0
        /// <summary>
        /// 获取令牌
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public ActionResult GetToken(string code)
        {
            try
            {
                AuthInfo authInfo = OpenApiClient.Authorize(code);

                if (string.IsNullOrEmpty(authInfo.ErrMsg))
                {
                    Session.Add("auth", authInfo);

                    return(new RedirectResult("/loan"));
                }

                return(Content(authInfo.ErrMsg));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }
コード例 #10
0
        /// <summary>
        /// 投标动作
        /// </summary>
        /// <returns></returns>
        public ActionResult DoBid()
        {
            try
            {
                AuthInfo auth = Session["auth"] as AuthInfo;
                if (auth == null)
                {
                    return(Redirect("/auth"));
                }

                int id     = int.Parse(Request.QueryString["id"]);
                int amount = int.Parse(Request.QueryString["amount"]);

                string request = string.Format("{{ \"ListingId\": {0},  \"Amount\": {1} }}", id, amount);

                Result result = OpenApiClient.Send(Bid_URL, auth.AccessToken,
                                                   new PropertyObject("ListingId", id, ValueTypeEnum.Int32), new PropertyObject("Amount", amount, ValueTypeEnum.Int32));

                if (result.IsSucess)
                {
                    return(Content(result.Context));
                }
                else
                {
                    return(Content(result.ErrorMessage));
                }
            }
            catch (FormatException ex)
            {
                return(Content("密钥无效,请更换有效密钥"));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }
コード例 #11
0
        public ActionResult DoBid2(BidModel model)
        {
            AuthInfo auth = Session["auth"] as AuthInfo;

            if (auth == null)
            {
                return(Redirect("/auth"));
            }

            Result result = OpenApiClient.Send(LoanController.Get_LoanList_URL, auth.AccessToken,
                                               new PropertyObject("timestamp", DateTime.Now, ValueTypeEnum.DateTime));

            if (result.IsSucess)
            {
                var  loanList = JsonConvert.DeserializeObject <LoanListModels>(result.Context);
                bool isCertificateValidate    = model.Tags.Any(p => p == "CertificateValidate");
                bool isMobileRealnameValidate = model.Tags.Any(p => p == "MobileRealnameValidate");
                bool isRate22        = model.Tags.Any(p => p == "rate22");
                bool isCreditCodeAAA = model.Tags.Any(p => p == "CreditCodeAAA");
                bool isCreditCodeD   = model.Tags.Any(p => p == "CreditCodeD");

                StringBuilder sb = new StringBuilder();

                foreach (var loan in loanList.LoanList.OrderByDescending(p => p.Rate))
                {
                    if (isCertificateValidate && loan.CertificateValidate != 1)
                    {
                        continue;
                    }

                    if (isMobileRealnameValidate && loan.MobileRealnameValidate != 1)
                    {
                        continue;
                    }

                    if (isRate22 && loan.Rate < 22)
                    {
                        continue;
                    }

                    if (isCreditCodeAAA && loan.CreditCode != "AAA")
                    {
                        continue;
                    }

                    if (isCreditCodeD && (loan.CreditCode == "E" || loan.CreditCode == "F"))
                    {
                        continue;
                    }

                    try
                    {
                        Result bidResp = OpenApiClient.Send(Bid_URL, auth.AccessToken,
                                                            new PropertyObject("ListingId", loan.ListingId, ValueTypeEnum.Int32), new PropertyObject("Amount", 50, ValueTypeEnum.Int32));

                        if (bidResp.IsSucess)
                        {
                            BidResult bidResult = JsonConvert.DeserializeObject <BidResult>(bidResp.Context);
                            sb.AppendLine(string.Format("投标:{0}  ,结果: {1}", loan.ListingId, bidResult.ResultMessage));
                        }
                        else
                        {
                            sb.AppendLine(string.Format("投标:{0}  ,结果: {1}", loan.ListingId, bidResp.ErrorMessage));
                        }

                        model.Amount -= 50;
                        if (model.Amount < 50)
                        {
                            break;
                        }
                    }
                    catch (Exception ex) {
                        sb.AppendLine(string.Format("投标:{0}  ,结果: {1}", loan.ListingId, ex.Message));
                    }
                }

                if (sb.Length == 0)
                {
                    return(Content("没有满足条件的标的"));
                }

                return(Content(sb.ToString()));
            }

            return(Content("获取投资列表失败"));
        }
コード例 #12
0
 public StopAreaFetcher(OpenApiClient openApiClient)
 {
     client = openApiClient;
 }
コード例 #13
0
 public DepartureFetcher(OpenApiClient openApiClient)
 {
     client = openApiClient;
 }