类别:程序开发
日期:2020-03-29 浏览:2764 评论:0
客服消息发送比较简单
注:指定openid和消息内容使用Post发送就可以,很多时候需要在触发事件或相应的情况下发送
官方文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140547
1.获取发送地址
/// <summary> /// 客服发送消息-POST /// </summary> /// <returns></returns> public string GetKFSend() { string url = string.Format("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}", config.Access_Token); return url; }
2.Post发送文本消息
/// <summary> /// 发送文本消息 /// </summary> /// <param name="content"></param> /// <returns></returns> public string SendText(string openid, string content) { string url = new LinkManage().GetKFSend(); JObject data = new JObject(); data.Add("touser", openid); data.Add("msgtype", "text"); data.Add("text", JObject.FromObject(new { content = content })); string result = NetHelper.Post(url, data.ToString()); return result; }
3.Post发送图片消息
/// <summary> /// 发送图片消息 /// </summary> /// <param name="openid"></param> /// <param name="media_id"></param> /// <returns></returns> public string SendImage(string openid, string media_id) { string url = new LinkManage().GetKFSend(); JObject data = new JObject(); data.Add("touser", openid); data.Add("msgtype", "image"); data.Add("image", JObject.FromObject(new { media_id = media_id })); string result = NetHelper.Post(url, data.ToString()); return result; }
————————————————
版权声明:本文为CSDN博主「天马3798」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011127019/article/details/78922149
发表评论 / 取消回复