Files
juipnet/Infrastructure/WxApi/TemplateMessage/TemplateModel.cs
“wanyongkang” ed3b2c653e 接口文件
2024-04-10 13:55:27 +08:00

130 lines
4.0 KiB
C#
Raw 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;
using System.Collections.Generic;
namespace Hncore.Wx.Open
{
public class TemplateBaseModel
{
public string touser { get; set; }
public string template_id { get; set; }
public List<TemplateDataItem> Items { get; set; } = new List<TemplateDataItem>();
//{
// "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<string, Object> ToData()
{
var data = new Dictionary<string, Object>() {
{ "touser",touser},
{"template_id",template_id}
};
var index = 1;
var dataItems = new Dictionary<string, Object>() { };
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<string, Object> ToData()
{
var ret = base.ToData();
var data = ret ["data"] as Dictionary<string, Object>;
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<string, Object> 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; }
}
/// <summary>
/// 小程序订阅消息
/// </summary>
public class SubscribeMiniAppModel : TemplateBaseModel
{
public string page { get; set; }
public override Dictionary<string, Object> ToData()
{
var ret = base.ToData();
var data = new Dictionary<string, Object>() {
{ "touser",touser},
{"template_id",template_id}
};
var index = 1;
var dataItems = new Dictionary<string, Object>() { };
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;
}
}
}