钉钉微应用发送消息
Posted lonelyxmas
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了钉钉微应用发送消息相关的知识,希望对你有一定的参考价值。
原文:钉钉微应用发送消息
微应用就是网站,钉钉自带的E应用难用,而且前端UI都不是很好,所以倾向使用网站来开发
string UrlUserID = "https://oapi.dingtalk.com/message/send?access_token=" + token; //获取自己的Token string PostData = "{ "touser":"", "; //职员代码,不知道是什么 去通讯录上查,多个请用“|”区分 PostData += " "toparty":"", "; //部门代码,职员代码和部门代码不能全部为空 PostData += " "agentid":"", "; //应用代码 PostData += " "msgtype":"text", "; //消息类型 PostData += " "text":{ "; PostData += " "content":"37889" "; //消息内容 PostData += " }}";
Response.Write(PostDataGethtml(UrlUserID, PostData));
public string PostDataGetHtml(string uri, string postData) { try { byte[] data = Encoding.UTF8.GetBytes(postData); Uri uRI = new Uri(uri); HttpWebRequest req = WebRequest.Create(uRI) as HttpWebRequest; req.Method = "POST"; req.KeepAlive = true; req.ContentType = "application/json"; req.ContentLength = data.Length; req.AllowAutoRedirect = true; Stream outStream = req.GetRequestStream(); outStream.Write(data, 0, data.Length); outStream.Close(); HttpWebResponse res = req.GetResponse() as HttpWebResponse; Stream inStream = res.GetResponseStream(); StreamReader sr = new StreamReader(inStream, Encoding.UTF8); string htmlResult = sr.ReadToEnd(); return htmlResult; } catch (Exception ex) { return "网络错误:" + ex.Message.ToString(); } }
以上是关于钉钉微应用发送消息的主要内容,如果未能解决你的问题,请参考以下文章