using System.Collections.Generic; using System.Linq; namespace MsgCenterClient.WechatMpTplMsg { public class MsgBase { /// /// /// /// 模板Id /// 物业Id /// 公众号AppId /// 用户OpenId public MsgBase(string templateId, int ownerId, string appId, string openId) { TemplateId = templateId; OwnerId = ownerId; AppId = appId; OpenId = openId; } /// /// 头部内容 /// public DataItem Head { get; set; } /// /// 底部内容 /// public DataItem Foot { get; set; } /// /// 模板Id /// public string TemplateId { get; } /// /// 物业Id /// public int OwnerId { get; } /// /// 公众号AppId /// public string AppId { get; } /// /// 用户openId /// public string OpenId { get; } /// /// 跳转的Url /// public string Url { get; set; } /// /// 跳转的小程序的Appid,为空的话默认跳转h5指定的url /// public string MiniAppId { get; set; } public object ToRequestObject() { SortedDictionary bodyDic = new SortedDictionary(); var type = GetType(); var properties = type.GetProperties(); foreach (var property in properties) { var bodyAttr = property.GetCustomAttributes(typeof(DataBodyAttribute), false); if (!bodyAttr.Any()) { continue; } int order = ((DataBodyAttribute) bodyAttr[0]).Order; DataItem value = property.GetValue(this, null) as DataItem; if (value == null) { value = new DataItem(); } bodyDic[order] = value; } return new { key = TemplateId, Content = new { Url, MiniAppId, first = new { value = Head?.Value, color = Head?.Color }, remark = new { value = Foot?.Value, color = Foot?.Color }, items = bodyDic.Values.Select(t => new {value = t.Value, color = t.Color}).ToList() }, OwnerId = OwnerId, From = AppId, To = OpenId }; } } }