using Newtonsoft.Json; using WIDESEA.Core.Enums; using WIDESEA.Core.Extensions; namespace WIDESEA.Core.Utilities { public class ApiResponseContent { public ApiResponseContent() { } public ApiResponseContent(int status) { this.Status = status; } [JsonProperty(PropertyName = "message")] /// /// 返回消息 /// public string Message { get; set; } [JsonProperty(PropertyName = "status")] /// /// 返回状态 /// public int Status { get; set; } [JsonProperty(PropertyName = "data")] /// /// 所有返回的业务数据 /// public object Data { get; set; } public ApiResponseContent OK(string msg = null) { return this.Set(ResponseType.OperSuccess, msg, ApiStatutsCode.Ok); } public ApiResponseContent Set(ResponseType responseType, ApiStatutsCode? status = null) { return this.Set(responseType, null, status); } /// /// /// /// /// 返回消息类型 /// 返回消息,若msg为null,则取responseType的描述信息 /// 返回状态,目前只有0、失败,1、成功,2、token过期 public ApiResponseContent Set(ResponseType responseType, string msg, ApiStatutsCode? status = null) { if (status != null) this.Status = (int)status; if (!string.IsNullOrEmpty(msg)) { this.Message = msg; return this; } if (!string.IsNullOrEmpty(this.Message)) return this; this.Message = responseType.GetMsg(); return this; } } }