当前位置:首页 > Windows程序 > 正文

c#群发短信

2021-03-28 Windows程序

在编写发送短信的程序中,我们 在代码编辑区,加using System.Net;命名空间。

   private string url = "http://utf8.sms.webchinese.cn/?";         //private string URL = "http://utf8.sms.webchinese.cn/?Uid=xiaokai&Key=&smsMob=手机号码&smsText=短信内容";         private string strUid = "Uid=";         //private string strKey = "&Key=8df38a399aa3bb8f632f";         private string strKey = "&Key=";         private string strMob = "&smsMob=";         private string strContent = "&smsText=";    /// <summary>         /// 群发消息         /// </summary>         /// <param name="url">         /// 给定明确的一个地址(包括电话,用户名,秘钥)         /// </param>         /// <returns>         /// 返回值用于确定是否发送成功         /// </returns>         public string GetHtmlFromUrl(string url)         {             string strRet = null;             if (url == null || url.Trim().ToString() == "")             {                 return strRet;             }             string targeturl = url.Trim().ToString();             try             {                 HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(targeturl);                 hr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";                 hr.Method = "GET";                 hr.Timeout = 30 * 60 * 1000;                 WebResponse hs = hr.GetResponse();                 Stream sr = hs.GetResponseStream();                 StreamReader ser = new StreamReader(sr, Encoding.Default);                 strRet = ser.ReadToEnd();             }             catch (Exception ex)             {                 strRet = null;                 MessageBox.Show(ex.Message);             }             return strRet;         }                         /// <summary>         /// 发送短信         /// </summary>         /// <param name="sender"></param>         /// <param name="e"></param>         private void btn_send_Click(object sender, EventArgs e)         {             if (txt_username.Text.ToString().Trim() != "" && textBox4.Text.ToString().Trim() != "" && textBox2.Text.ToString() != null)             {                 url = url + strUid + txt_username.Text + strKey + txt_key.Text + strMob + textBox4.Text + strContent + textBox2.Text;                 string Result = GetHtmlFromUrl(url);                 MessageBox.Show(Result);             }             else             {                 MessageBox.Show("请填写完整,,不要空!");             }         }

上述发送短信的过程都是利用的中国网建提供的api来使用的。参考如下:

中国网建,短信群发平台

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/68913.html