码迷,mamicode.com
首页 > 其他好文 > 详细

钉钉微应用发送消息

时间:2020-03-04 14:46:14      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:color   access   类型   his   span   adt   click   class   ESS   

原文:钉钉微应用发送消息

微应用就是网站,钉钉自带的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();
        }
    }
技术图片

 

钉钉微应用发送消息

标签:color   access   类型   his   span   adt   click   class   ESS   

原文地址:https://www.cnblogs.com/lonelyxmas/p/12409030.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!