/// <summary> /// 根据OpenID列表群发-视频消息 /// </summary> /// <param name="access_token">公众号access token</param> /// <param name="touser">openid 列表</param> /// <param name="media_id">用于群发的消息的media_id</param> /// <param name="title">视频消息的标题</param> /// <param name="description">视频消息的描述</param> /// <param name="clientmsgid">使用 clientmsgid 参数,避免重复推送</param> /// <returns></returns> public MassResult MassVideo(string access_token, IEnumerable <string> touser, string media_id, string title, string description, string clientmsgid) { VideoConvertResult video = this.ConvertVideo(access_token, media_id, title, description); DynamicDictionary dic = new DynamicDictionary(); dic.SetMember("msgtype", "mpvideo"); dic.SetMember("mpvideo", video); dic.SetMember("touser", touser); return(this.Mass(access_token, this.Send, dic, clientmsgid)); }
/// <summary> /// 根据标签进行群发-视频消息 /// </summary> /// <param name="access_token">公众号access token</param> /// <param name="tag_id">标签id,如果标签id为空,则群发所有人</param> /// <param name="media_id">用于群发的消息的media_id</param> /// <param name="title">视频消息的标题</param> /// <param name="description">视频消息的描述</param> /// <param name="clientmsgid">使用 clientmsgid 参数,避免重复推送</param> /// <returns></returns> public MassResult MassVideo(string access_token, string tag_id, string media_id, string title, string description, string clientmsgid) { VideoConvertResult video = this.ConvertVideo(access_token, media_id, title, description); DynamicDictionary dic = new DynamicDictionary(); dic.SetMember("filter", this.GetMassFilter(tag_id)); dic.SetMember("mpvideo", new { video.media_id }); dic.SetMember("msgtype", "mpvideo"); return(this.Mass(access_token, this.SendAll, dic, clientmsgid)); }
public VideoConvertResult ConvertVideo(string access_token, string media_id, string title, string description) { string url = $"{Config.WxApi}cgi-bin/media/uploadvideo?access_token={access_token}"; var obj = new { media_id, title, description }; string resultStr = WxAPI.Request(url, obj, Method.POST); VideoConvertResult result = SerializerHelper.ToObject <VideoConvertResult>(resultStr); if (result.errcode != 0 || string.IsNullOrEmpty(result.media_id)) { throw new DataConvertException($"video素材转换失败:{resultStr}"); } return(result); }
/// <summary> /// 预览接口 /// </summary> /// <param name="access_token">公众号access token</param> /// <param name="type">预览消息类型</param> /// <param name="send_value">需要发送的值</param> /// <param name="touser">根据openid发送, towxname和touser同时赋值时,以towxname优先</param> /// <param name="towxname">根据微信号发送, towxname和touser同时赋值时,以towxname优先</param> /// <returns></returns> private MassResult Preview(string access_token, MassType type, string send_value, string touser, string towxname) { DynamicDictionary dic = new DynamicDictionary(); string msgtype = type.ToString(); if (!string.IsNullOrEmpty(touser)) { dic.SetMember("touser", touser); } if (!string.IsNullOrEmpty(towxname)) { dic.SetMember("towxname", towxname); } switch (msgtype) { case "text": dic.SetMember("text", new { content = send_value }); break; case "wxcard": dic.SetMember("wxcard", new { card_id = send_value }); break; case "mpvideo": VideoConvertResult result = this.ConvertVideo(access_token, send_value, "", ""); dic.SetMember("mpvideo", new { media_id = send_value }); break; default: dic.SetMember(msgtype, new { media_id = send_value }); break; } dic.SetMember("msgtype", msgtype); string url = $"{Config.WxApi}cgi-bin/message/mass/preview?access_token={access_token}"; return(WxAPI.Request <MassResult>(url, dic.GetMembers(), Method.POST)); }