public static JsonResponseMessage SendMessage <T>(string apiPath, IApiParameter body) where T : JsonResponseMessage, new() { var json = JsonConvert.SerializeObject(body); Log.Error("dxy interface call: url->{0},parameter->{1}", apiPath, json); var response = PostRequest(apiPath, Encoding.UTF8.GetBytes(json)); if (response == null) { return(null); } return(JsonConvert.DeserializeObject <T>(response)); }
public static string GetQueryString(this IApiParameter parameter) { var type = parameter.GetType(); var properties = type.GetHierarchyProperties(); var needSignProperties = properties.Where(x => { var instance = (ParameterProperty)x.GetCustomAttribute(typeof(ParameterProperty)); return(instance != null && instance.IsRequired); }).ToList(); needSignProperties = needSignProperties.OrderBy(x => x.Name, StringComparer.Ordinal).ToList(); var list = needSignProperties.Select(x => { var propertyInstance = (ParameterProperty)x.GetCustomAttribute(typeof(ParameterProperty)); if (propertyInstance != null && propertyInstance.Name != null) { return(string.Format("{0}={1}", propertyInstance.Name, x.GetValue(parameter))); } return(string.Format("{0}={1}", x.Name, x.GetValue(parameter))); }); return(string.Join("&", list.ToArray())); }
public RequestStringBuilder WithParameter(IApiParameter parameter) { _parameters.Add(parameter); return(this); }