public async Task <T> SignAndSend <T>(string url, IDictionary <string, object> payload, string method, string publicKey = null, string privateKey = null) { IDictionary <string, string> headers = new Dictionary <string, string>(2); if (payload == null) { payload = new Dictionary <string, object>(1); } payload["ts"] = UnixTime.GetCurrent().ToString(CultureInfo.InvariantCulture); string form = null; string formForPayload = GetFormForPayload(payload); string sign; string mediaType = null; if (method != "POST") { var reqstr = '?' + formForPayload; url += reqstr; sign = CalcSign(reqstr, (privateKey == null ? this.privateKey : Encoding.UTF8.GetBytes(privateKey))); } else { form = JsonConvert.SerializeObject(payload); mediaType = "application/json"; sign = CalcSign(form, (privateKey == null ? this.privateKey : Encoding.UTF8.GetBytes(privateKey))); } headers["Key"] = publicKey ?? this.publicKey; headers["Sign"] = sign; headers["ts"] = UnixTime.GetCurrent().ToString(); string response = await this.client.MakeRequestAsync(this.baseUrl + url, method : method, headers : headers, form : form, mediaType : mediaType); return(JsonConvert.DeserializeObject <T>(response)); }
/// <summary> /// Initializes a new instance of the <see cref="Response"/> class. /// </summary> public Response() { this.Error = ErrorCode.Success; this.Timestamp = UnixTime.GetCurrent(); }