using System; using System.Collections.Generic; namespace Hncore.Wx.Open { public class TemplateBaseModel { public string touser { get; set; } public string template_id { get; set; } public List Items { get; set; } = new List(); //{ // "touser":"touser", // "template_id": "TEMPLATE_ID", // "data": { // "keyword1": { // "value": "339208499" // }, // "keyword2": { // "value": "2015年01月05日 12:30" // }, // "keyword3": { // "value": "腾讯微信总部" // } , // "keyword4": { // "value": "广州市海珠区新港中路397号" // } // } //} public virtual Dictionary ToData() { var data = new Dictionary() { { "touser",touser}, {"template_id",template_id} }; var index = 1; var dataItems = new Dictionary() { }; Items.ForEach(m => { dataItems[$"keyword{index}"] = m; index++; }); data["data"] = dataItems; return data; } } public class TemplateMPModel: TemplateBaseModel { public string Url { get; set; } public string MiniAppId { get; set; } public TemplateDataItem first { get; set; } public TemplateDataItem remark { get; set; } public override Dictionary ToData() { var ret = base.ToData(); var data = ret ["data"] as Dictionary; if (first != null) data["first"] = first; if (remark != null) data["remark"] = remark; if (!string.IsNullOrWhiteSpace(Url)) ret["url"] = Url; if (!string.IsNullOrWhiteSpace(MiniAppId)) ret["miniprogram"] = new { appid = MiniAppId, pagepath = Url }; return ret; } } public class TemplateMiniAppModel : TemplateBaseModel { public string page { get; set; } public string form_id { get; set; } public string emphasis_keyword { get; set; } public override Dictionary ToData() { var ret = base.ToData(); if (!string.IsNullOrWhiteSpace(page)) ret["page"] = page; if (!string.IsNullOrWhiteSpace(form_id)) ret["form_id"] = form_id; if (!string.IsNullOrWhiteSpace(emphasis_keyword)) ret["emphasis_keyword"] = emphasis_keyword; return ret; } } public class TemplateDataItem { public TemplateDataItem(string v, string c = "#173177") { value = v; color = c; } public string name { get; set; } public string value { get; set; } // // 摘要: // 16进制颜色代码,如:#FF0000 public string color { get; set; } } /// /// 小程序订阅消息 /// public class SubscribeMiniAppModel : TemplateBaseModel { public string page { get; set; } public override Dictionary ToData() { var ret = base.ToData(); var data = new Dictionary() { { "touser",touser}, {"template_id",template_id} }; var index = 1; var dataItems = new Dictionary() { }; Items.ForEach(m => { var num = index.ToString().PadLeft(2, '0'); dataItems[m.name] = new { value = m.value }; index++; }); data["data"] = dataItems; if (!string.IsNullOrWhiteSpace(page)) ret["page"] = page; return data; } } }