// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
namespace Admin.NET.Plugin.WorkWeixin;
///
/// 应用推送消息基类
///
[HttpRemoteApi(Action = "appchat/send", Desc = "应用消息推送", HttpMethod = HttpMethodEnum.Post)]
public abstract class AppChatMessageInput : AuthWorkWxInput
{
///
/// 群聊id
///
/// 是否必填:是
[CustomJsonProperty("chatid")]
[Required(ErrorMessage = "群聊ID不能为空")]
public string ChatId { get; set; }
///
/// 消息类型
///
/// 是否必填:是
[CustomJsonProperty("msgtype")]
[Required(ErrorMessage = "消息类型不能为空")]
public abstract string MsgType { get; }
///
/// 表示是否是保密消息,0表示否,1表示是,默认0
///
/// 是否必填:否
[CustomJsonProperty("safe")]
[Range(0, 1, ErrorMessage = "安全标识只能是0或1")]
public int? Safe { get; set; }
}
///
/// 文本消息
///
///
///
特殊说明:content字段可以支持换行,换行符请用转义过的'\n'
///
public class TextAppChatMessage : AppChatMessageInput
{
public override string MsgType => "text";
///
/// 文本消息内容
///
[CustomJsonProperty("text")]
[Required(ErrorMessage = "文本消息内容不能为空")]
public TextContent Text { get; set; } = new TextContent();
}
///
/// 图片消息
///
public class ImageAppChatMessage : AppChatMessageInput
{
public override string MsgType => "image";
///
/// 图片消息内容
///
[CustomJsonProperty("image")]
[Required(ErrorMessage = "图片消息内容不能为空")]
public MediaContent Image { get; set; } = new MediaContent();
}
///
/// 语音消息
///
public class VoiceAppChatMessage : AppChatMessageInput
{
public override string MsgType => "voice";
///
/// 语音消息内容
///
[CustomJsonProperty("voice")]
[Required(ErrorMessage = "语音消息内容不能为空")]
public MediaContent Voice { get; set; } = new MediaContent();
}
///
/// 视频消息
///
public class VideoAppChatMessage : AppChatMessageInput
{
public override string MsgType => "video";
///
/// 视频消息内容
///
[CustomJsonProperty("video")]
[Required(ErrorMessage = "视频消息内容不能为空")]
public VideoContent Video { get; set; } = new VideoContent();
}
///
/// 文件消息
///
public class FileAppChatMessage : AppChatMessageInput
{
public override string MsgType => "file";
///
/// 文件消息内容
///
[CustomJsonProperty("file")]
[Required(ErrorMessage = "文件消息内容不能为空")]
public MediaContent File { get; set; } = new MediaContent();
}
///
/// 文本卡片消息
///
public class TextCardAppChatMessage : AppChatMessageInput
{
public override string MsgType => "textcard";
///
/// 文本卡片消息内容
///
[CustomJsonProperty("textcard")]
[Required(ErrorMessage = "文本卡片消息内容不能为空")]
public TextCardContent TextCard { get; set; } = new TextCardContent();
}
///
/// 图文消息
///
public class NewsAppChatMessage : AppChatMessageInput
{
public override string MsgType => "news";
///
/// 图文消息内容
///
[CustomJsonProperty("news")]
[Required(ErrorMessage = "图文消息内容不能为空")]
public NewsContent News { get; set; } = new NewsContent();
}
///
/// 图文消息(mpnews)
///
public class MpNewsAppChatMessage : AppChatMessageInput
{
public override string MsgType => "mpnews";
///
/// 图文消息内容
///
[CustomJsonProperty("mpnews")]
[Required(ErrorMessage = "图文消息内容不能为空")]
public MpNewsContent MpNews { get; set; } = new MpNewsContent();
}
///
/// Markdown消息
///
public class MarkdownAppChatMessage : AppChatMessageInput
{
public override string MsgType => "markdown";
///
/// Markdown消息内容
///
[CustomJsonProperty("markdown")]
[Required(ErrorMessage = "Markdown消息内容不能为空")]
public MarkdownContent Markdown { get; set; } = new MarkdownContent();
}
///
/// 文本消息内容
///
public class TextContent
{
///
/// 消息内容,最长不超过2048个字节
///
/// 是否必填:是
[CustomJsonProperty("content")]
[Required(ErrorMessage = "消息内容不能为空")]
[StringLength(2048, ErrorMessage = "消息内容长度不能超过2048个字节")]
public string Content { get; set; }
}
///
/// 媒体内容基类
///
public class MediaContent
{
///
/// 媒体文件id,可以调用上传临时素材接口获取
///
/// 是否必填:是
[CustomJsonProperty("media_id")]
[Required(ErrorMessage = "媒体文件ID不能为空")]
public string MediaId { get; set; }
}
///
/// 视频消息内容
///
public class VideoContent : MediaContent
{
///
/// 视频消息的标题,不超过128个字节,超过会自动截断
///
/// 是否必填:否
[CustomJsonProperty("title")]
[StringLength(128, ErrorMessage = "视频标题长度不能超过128个字节")]
public string Title { get; set; }
///
/// 视频消息的描述,不超过512个字节,超过会自动截断
///
/// 是否必填:否
[CustomJsonProperty("description")]
[StringLength(512, ErrorMessage = "视频描述长度不能超过512个字节")]
public string Description { get; set; }
}
///
/// 文本卡片消息内容
///
public class TextCardContent
{
///
/// 标题,不超过128个字节,超过会自动截断
///
/// 是否必填:是
[CustomJsonProperty("title")]
[Required(ErrorMessage = "标题不能为空")]
[StringLength(128, ErrorMessage = "标题长度不能超过128个字节")]
public string Title { get; set; }
///
/// 描述,不超过512个字节,超过会自动截断
///
/// 是否必填:是
[CustomJsonProperty("description")]
[Required(ErrorMessage = "描述不能为空")]
[StringLength(512, ErrorMessage = "描述长度不能超过512个字节")]
public string Description { get; set; }
///
/// 点击后跳转的链接
///
/// 是否必填:是
[CustomJsonProperty("url")]
[Required(ErrorMessage = "跳转链接不能为空")]
[Url(ErrorMessage = "链接格式不正确")]
public string Url { get; set; }
///
/// 按钮文字。默认为"详情",不超过4个文字,超过自动截断
///
/// 是否必填:否
[CustomJsonProperty("btntxt")]
[StringLength(4, ErrorMessage = "按钮文字长度不能超过4个字符")]
public string BtnTxt { get; set; }
}
///
/// 图文消息文章
///
public class Article
{
///
/// 标题,不超过128个字节,超过会自动截断
///
/// 是否必填:是
[CustomJsonProperty("title")]
[Required(ErrorMessage = "文章标题不能为空")]
[StringLength(128, ErrorMessage = "文章标题长度不能超过128个字节")]
public string Title { get; set; }
///
/// 描述,不超过512个字节,超过会自动截断
///
/// 是否必填:否
[CustomJsonProperty("description")]
[StringLength(512, ErrorMessage = "文章描述长度不能超过512个字节")]
public string Description { get; set; }
///
/// 点击后跳转的链接
///
/// 是否必填:是
[CustomJsonProperty("url")]
[Required(ErrorMessage = "文章链接不能为空")]
[Url(ErrorMessage = "文章链接格式不正确")]
public string Url { get; set; }
///
/// 图文消息的图片链接,支持JPG、PNG格式
///
/// 是否必填:否
[CustomJsonProperty("picurl")]
[Url(ErrorMessage = "图片链接格式不正确")]
public string PicUrl { get; set; }
}
///
/// 图文消息内容
///
public class NewsContent
{
///
/// 图文消息,一个图文消息支持1到8条图文
///
/// 是否必填:是
[CustomJsonProperty("articles")]
[Required(ErrorMessage = "图文消息不能为空")]
[MinLength(1, ErrorMessage = "至少需要1条图文消息")]
[MaxLength(8, ErrorMessage = "最多只能有8条图文消息")]
public List Articles { get; set; } = new List();
}
///
/// 图文消息(mpnews)文章
///
public class MpArticle
{
///
/// 标题,不超过128个字节,超过会自动截断
///
/// 是否必填:是
[CustomJsonProperty("title")]
[Required(ErrorMessage = "文章标题不能为空")]
[StringLength(128, ErrorMessage = "文章标题长度不能超过128个字节")]
public string Title { get; set; }
///
/// 图文消息缩略图的media_id,可以通过素材管理接口获得
///
/// 是否必填:是
[CustomJsonProperty("thumb_media_id")]
[Required(ErrorMessage = "缩略图媒体ID不能为空")]
public string ThumbMediaId { get; set; }
///
/// 图文消息的作者,不超过64个字节
///
/// 是否必填:否
[CustomJsonProperty("author")]
[StringLength(64, ErrorMessage = "作者长度不能超过64个字节")]
public string Author { get; set; }
///
/// 图文消息点击"阅读原文"之后的页面链接
///
/// 是否必填:否
[CustomJsonProperty("content_source_url")]
[Url(ErrorMessage = "原文链接格式不正确")]
public string ContentSourceUrl { get; set; }
///
/// 图文消息的内容,支持html标签,不超过666K个字节
///
/// 是否必填:是
[CustomJsonProperty("content")]
[Required(ErrorMessage = "文章内容不能为空")]
public string Content { get; set; }
///
/// 图文消息的描述,不超过512个字节,超过会自动截断
///
/// 是否必填:否
[CustomJsonProperty("digest")]
[StringLength(512, ErrorMessage = "摘要长度不能超过512个字节")]
public string Digest { get; set; }
}
///
/// 图文消息(mpnews)内容
///
public class MpNewsContent
{
///
/// 图文消息,一个图文消息支持1到8条图文
///
/// 是否必填:是
[CustomJsonProperty("articles")]
[Required(ErrorMessage = "图文消息不能为空")]
[MinLength(1, ErrorMessage = "至少需要1条图文消息")]
[MaxLength(8, ErrorMessage = "最多只能有8条图文消息")]
public List Articles { get; set; } = new List();
}
///
/// Markdown消息内容
///
public class MarkdownContent
{
///
/// markdown内容,最长不超过2048个字节,必须是utf8编码
///
/// 是否必填:是
[CustomJsonProperty("content")]
[Required(ErrorMessage = "Markdown内容不能为空")]
[StringLength(2048, ErrorMessage = "Markdown内容长度不能超过2048个字节")]
public string Content { get; set; }
}