Micro staple application sends a message

Original: staple micro application sends a message

Micro application is the site of E comes nailed application difficult to use, and the front-end UI is not very good, so tend to use the site for development

 

Copy the code
String UrlUserID = " https://oapi.dingtalk.com/message/send?access_token= " + token; // Get your own Token 



        String the PostData = " {\" TOUSER \ ": \" \ ",   " ; // employee code, I do not know what to check on the address book, multiple please use the "|" to distinguish 
        the PostData + = "      \" toparty \ ": \" \ ", " ; // department code, employee code and department code can not all empty 
        the PostData + = "           \" agentId \ ": \" \ ",    " ; // application code in 
        the PostData + = "          \" MsgType \ ": \" text \ ",   " ;// Message Type 
        the PostData + = "         \"text\":{  ";
        PostData += "             \"content\":\"37889\"  ";    //消息内容
        PostData += "       }}";

Response.Write(PostDataGetHtml(UrlUserID, PostData));
Copy the code
Copy the code
  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();

            returnhtmlResult; 
        }
        the catch (Exception EX) 
        { 
            return  " Network Error: " + ex.Message.ToString (); 
        } 
    }
Copy the code

 

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12409030.html