Files
“wanyongkang” ed3b2c653e 接口文件
2024-04-10 13:55:27 +08:00

117 lines
3.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
};
}
}
}