c# 調用短信平台接口,給手機發送短信


項目上要做個發手機短信的功能。網上找找了,用的微米的短信接口。

注冊后,獲得UID和UID key,C#代碼中需要這個

調用代碼很簡單

  string mobile = "12345678",
            con = "【微米】您的驗證碼是:610912,3分鍾內有效。如非您本人操作,可忽略本消息。",
            uid = "xxx",
            pas = "xxx",
            url = "http://api.weimi.cc/2/sms/send.html";
            byte[] byteArray = Encoding.UTF8.GetBytes("mob=" + mobile + "&con=" + con + "&uid=" + uid + "&pas=" + pas + "&type=json");
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
            webRequest.Method = "POST";
            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.ContentLength = byteArray.Length;
            Stream newStream = webRequest.GetRequestStream();
            newStream.Write(byteArray, 0, byteArray.Length);
            newStream.Close();
            HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
            StreamReader php = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string Message = php.ReadToEnd();
            System.Console.Write(Message);
            System.Console.Read();

后台的短信平台上可以看到發的記錄

手機上

手機上收到短信的效果如下:

 


免責聲明!

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



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