using System.Collections.Generic; using System.Linq; namespace MsgCenterClient.WechatMpTplMsg { public class MiniAppMsgBase { /// /// /// /// 模板Id /// 物业Id /// 公众号AppId /// 用户OpenId public MiniAppMsgBase(string templateId, int ownerId, string appId, string openId) { TemplateId = templateId; OwnerId = ownerId; AppId = appId; OpenId = openId; } /// /// 模板Id /// public string TemplateId { get; } /// /// 物业Id /// public int OwnerId { get; } /// /// 公众号AppId /// public string AppId { get; } /// /// 用户openId /// public string OpenId { get; } /// /// 跳转的小程序页面 /// public string Page { get; set; } /// /// 表单id /// public string FormId { get; set; } /// /// 强调的字,可以为空 /// public string EmphasisKeyword { 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, OwnerId = OwnerId, From = AppId, To = OpenId, Content = new { page=this.Page, form_id=this.FormId, emphasis_keyword=this.EmphasisKeyword, items = bodyDic.Values.Select(t => new {value = t.Value, color = t.Color}).ToList() } }; } } }