其他分享
首页 > 其他分享> > 钉钉微应用发送消息

钉钉微应用发送消息

作者:互联网

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

微应用就是网站,钉钉自带的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();
        }
    }
复制代码

 

标签:string,PostData,代码,req,outStream,发送,消息,应用,data
来源: https://www.cnblogs.com/lonelyxmas/p/12409030.html