102 lines
2.8 KiB
C#
102 lines
2.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace MsgCenterClient.WechatMpTplMsg
|
|
{
|
|
public class MiniAppMsgBase
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="templateId">模板Id</param>
|
|
/// <param name="ownerId">物业Id</param>
|
|
/// <param name="appId">公众号AppId</param>
|
|
/// <param name="openId">用户OpenId</param>
|
|
public MiniAppMsgBase(string templateId, int ownerId, string appId, string openId)
|
|
{
|
|
TemplateId = templateId;
|
|
OwnerId = ownerId;
|
|
AppId = appId;
|
|
OpenId = openId;
|
|
}
|
|
|
|
/// <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>
|
|
/// 跳转的小程序页面
|
|
/// </summary>
|
|
public string Page { get; set; }
|
|
|
|
/// <summary>
|
|
/// 表单id
|
|
/// </summary>
|
|
public string FormId { get; set; }
|
|
|
|
/// <summary>
|
|
/// 强调的字,可以为空
|
|
/// </summary>
|
|
public string EmphasisKeyword { 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,
|
|
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()
|
|
}
|
|
};
|
|
}
|
|
}
|
|
} |