/// <summary> /// 发送文本消息 /// </summary> /// <returns></returns> public Dictionary <string, object> CustomSendText(CustomSend send) { return(ApiHandler.TryCommonApi(delegate(string accessToken) { HttpContent content = new StringContent(JsonConvert.SerializeObject(send)); var result = ApiHandler.PostGetJson <Dictionary <string, object> >(string.Format(ApiConfig.customSend, accessToken), content); return result; })); }
/// <summary> /// 发送客服消息 /// </summary> /// <param name="access_token"></param> /// <param name="msgSend"></param> /// <returns></returns> public static Custom_SendRes Custom_Send(string access_token, CustomSend msgSend) { string url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="; url += access_token; dynamic dpost = new ExpandoObject(); dpost.touser = msgSend.touser; dpost.msgtype = msgSend.msgtype; if (!string.IsNullOrEmpty(msgSend.kf_account)) { dpost.customservice = new { kf_account = msgSend.kf_account }; } #region 转换成所所需要的json switch (msgSend.msgtype) { case "text": { dpost.text = new { content = msgSend.content }; break; } case "image": { dpost.image = new { media_id = msgSend.media_id }; break; } case "voice": { dpost.voice = new { media_id = msgSend.media_id }; break; } case "video": { dpost.video = new { media_id = msgSend.media_id, thumb_media_id = msgSend.thumb_media_id, title = msgSend.title, description = msgSend.description }; break; } case "music": { dpost.music = new { title = msgSend.title, description = msgSend.description, musicurl = msgSend.musicurl, hqmusicurl = msgSend.hqmusicurl, thumb_media_id = msgSend.thumb_media_id }; break; } case "news": { dpost.news = new { articles = msgSend.articles }; break; } case "mpnews": { dpost.mpnews = new { media_id = msgSend.media_id }; break; } case "wxcard": { dpost.mpnews = new { card_id = msgSend.card_id, card_ext = msgSend.card_ext }; break; } } #endregion var ps = JsonConvert.SerializeObject(dpost); return(PostObject <Custom_SendRes>(url, ps)); }
public ActionResult <Dictionary <string, object> > CustomSendText(CustomSend send) { return(_customService.CustomSendText(send)); }