123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using cuidian.OpenApi.Exceptions;
- using cuidian.OpenApi.Http;
- using cuidian.OpenApi.Utils;
- using Logs;
- namespace cuidian.OpenApi
- {
- /// <summary>
- /// 开放平台 API 基类
- /// </summary>
- public class Trade
- {
- private static readonly string ERR_MSG_SDK_RUNTIME_ERROR = "OpenAPI-SDK Runtime Error.";
- private IDictionary<string, string> systemParameters = new Dictionary<string, string>();
- private string appKey;
- private string fromAccount;
- private string baseUrl;
- public static Http.WebUtils Client = new Http.WebUtils();
- public Trade()
- {
- try
- {
- this.LoadConfig();
- }
- catch (Exception e)
- {
- LogHelper.Error(e.Message);
- throw new ApiException(ERR_MSG_SDK_RUNTIME_ERROR, e);
- }
- }
- public Trade(string fromAccount, string appKey, string appSecret)
- : this()
- {
- this.fromAccount = fromAccount;
- this.appKey = appKey;
- }
- private void LoadConfig()
- {
- this.appKey = ApiConfig.AppKey;
- this.fromAccount = ApiConfig.FromAccount;
- this.baseUrl = ApiConfig.BaseUrl;
- }
- private IDictionary<string, string> GetSystemParameters()
- {
- if (this.systemParameters.Count == 0)
- {
- this.systemParameters.Add("app_key", this.appKey);
- this.systemParameters.Add("token", TokenManager.GetToken());
- if (!String.IsNullOrEmpty(this.fromAccount))
- this.systemParameters.Add("from_account", this.fromAccount);
- }
- return this.systemParameters;
- }
- private string Url
- {
- get { return this.baseUrl + "system/" + this.ResourceId; }
- }
- /// <summary>
- /// 资源名称
- /// </summary>
- public string ResourceId
- {
- get { return "tradeid"; }
- }
- public BusinessObject Get()
- {
- try
- {
- return BusinessObject.Get(this.ResourceId, new Response(Client.Get(this.Url, this.GetSystemParameters())));
- }
- catch (Exception e)
- {
- LogHelper.Error(e.Message);
- throw new ApiException(ERR_MSG_SDK_RUNTIME_ERROR, e);
- }
- }
- }
- }
|