/// <summary> /// 预览接口【订阅号与服务号认证后均可用】 /// 开发者可通过该接口发送消息给指定用户,在手机端查看消息的样式和排版。 /// 为了满足第三方平台开发者的需求,在保留对openID预览能力的同时, /// 增加了对指定微信号发送预览的能力,但该能力每日调用次数有限制(100次),请勿滥用。 /// </summary> /// <param name="accessToken"></param> /// <param name="sendType"></param> /// <param name="media"></param> /// <param name="openid"></param> /// <param name="wxname"></param> /// <returns></returns> public static Msg_Id MessagePreview(string accessToken, GroupSendType sendType, string media, string openid, string wxname = null) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token={0}", accessToken); dynamic jsonData = null; switch (sendType) { case GroupSendType.text: jsonData = new { towxname = wxname, touser = openid, text = new { content = media }, msgtype = GroupSendType.text.ToString() }; break; case GroupSendType.image: jsonData = new { towxname = wxname, touser = openid, image = new { media_id = media }, msgtype = GroupSendType.image.ToString() }; break; case GroupSendType.voice: jsonData = new { towxname = wxname, touser = openid, voice = new { media_id = media }, msgtype = GroupSendType.voice.ToString() }; break; case GroupSendType.mpnews: jsonData = new { towxname = wxname, touser = openid, mpnews = new { media_id = media }, msgtype = GroupSendType.mpnews.ToString() }; break; case GroupSendType.mpvideo: jsonData = new { towxname = wxname, touser = openid, mpvideo = new { media_id = media }, msgtype = GroupSendType.mpvideo.ToString() }; break; case GroupSendType.wxcard: jsonData = new { towxname = wxname, touser = openid, wxcard = new { card_id = media }, msgtype = GroupSendType.wxcard.ToString() }; break; } dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); Msg_Id wxResult = EntityHelper.GetJsonResultToEntity <Msg_Id>(result); return(wxResult); }
/// <summary> /// 根据分组进行群发【订阅号与服务号认证后均可用】 /// </summary> /// <param name="accessToken"></param> /// <param name="group_id"></param> /// <param name="sendType"></param> /// <param name="media">mediaId</param> /// <param name="is_to_all">群发到的分组的group_id,参加用户管理中用户分组接口,若is_to_all值为true,可不填写group_id</param> /// <returns></returns> public static GroupSendResult SendAllByGroup(string accessToken, string group_id, GroupSendType sendType, string media, bool is_to_all = false) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token={0}", accessToken); dynamic jsonData = null; switch (sendType) { case GroupSendType.text: jsonData = new { filter = new { is_to_all = is_to_all, group_id = group_id }, text = new { content = media }, msgtype = GroupSendType.text }; break; case GroupSendType.image: jsonData = new { filter = new { is_to_all = is_to_all, group_id = group_id, }, image = new { media_id = media }, msgtype = GroupSendType.image }; break; case GroupSendType.voice: jsonData = new { filter = new { is_to_all = is_to_all, group_id = group_id, }, voice = new { media_id = media }, msgtype = GroupSendType.voice }; break; case GroupSendType.mpnews: jsonData = new { filter = new { is_to_all = is_to_all, group_id = group_id, }, mpnews = new { media_id = media }, msgtype = GroupSendType.mpnews }; break; case GroupSendType.mpvideo: jsonData = new { filter = new { is_to_all = is_to_all, group_id = group_id, }, mpvideo = new { media_id = media }, msgtype = GroupSendType.mpvideo }; break; case GroupSendType.wxcard: jsonData = new { filter = new { is_to_all = is_to_all, group_id = group_id, }, wxcard = new { card_id = media }, msgtype = GroupSendType.wxcard }; break; } dynamic result = HttpService.WeChatPost(url, JsonHelper.getJsonString(jsonData)); GroupSendResult wxResult = EntityHelper.GetJsonResultToEntity <GroupSendResult>(result); return(wxResult); }