釘釘微應用發送消息


微應用就是網站,釘釘自帶的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();
        }
    }

 

 

釘釘視頻教程


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM