2020-12-28 14:55:48 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MsgCenterClient.WechatMpTplMsg
|
|
|
|
|
|
{
|
|
|
|
|
|
public class MsgBase
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="templateId">模板Id</param>
|
|
|
|
|
|
/// <param name="ownerId">物业Id</param>
|
|
|
|
|
|
/// <param name="appId">公众号AppId</param>
|
|
|
|
|
|
/// <param name="openId">用户OpenId</param>
|
|
|
|
|
|
public MsgBase(string templateId, int ownerId, string appId, string openId)
|
|
|
|
|
|
{
|
|
|
|
|
|
TemplateId = templateId;
|
|
|
|
|
|
OwnerId = ownerId;
|
|
|
|
|
|
AppId = appId;
|
|
|
|
|
|
OpenId = openId;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 头部内容
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public DataItem Head { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 底部内容
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public DataItem Foot { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 模板Id
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string TemplateId { get; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 物业Id
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int OwnerId { get; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 公众号AppId
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string AppId { get; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用户openId
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string OpenId { get; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 跳转的Url
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string Url { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 跳转的小程序的Appid,为空的话默认跳转h5指定的url
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string MiniAppId { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public object ToRequestObject()
|
|
|
|
|
|
{
|
|
|
|
|
|
SortedDictionary<int, DataItem> bodyDic = new SortedDictionary<int, DataItem>();
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-10-07 20:25:03 +08:00
|
|
|
|
}
|