zoukankan      html  css  js  c++  java
  • 基于C#的短信发送

    今天在复习ASP.NET的时候,突然想到能不能使用c#来发送短信。在网上搜索了之后发现还真有。而且一共有三种方式:(1)使用webservice接口发送手机短信,这个可以使用sina提供的webservice进行发送,但是需要进行注册;(2)使用短信mao的方式进行短信的发送,这种方式应该是比较的常用,前提是需要购买硬件设备,这个就不考虑了(3)使用中国网建提供的SMS短信平台,但是,用完几条免费的后,就要收费了。

    以下是代码实现,其实相当简单,就注册以下,连代码都有:

     1  public partial class Form1 : Form
     2     {
     3         public Form1()
     4         {
     5             InitializeComponent();
     6         }
     7 
     8         private void btnSend_Click(object sender, EventArgs e)
     9         {
    10             if (txtUserName.Text.ToString() != null || txtUserPhone.Text.ToString() != null || txtContext.Text.ToString() != null)
    11             {
    12                 string url = "http://utf8.sms.webchinese.cn/?Uid=" + txtUserName.Text + "&Key=rubbit12138&smsMob=" + txtUserPhone.Text + "&smsText=" + txtContext;
    13                 string result = GetHtmlFromUrl(url);
    14                 MessageBox.Show(result);
    15             }
    16         }
    17 
    18         public string GetHtmlFromUrl(string url)
    19         {
    20             string strRet = null;
    21             if (url == null || url.Trim().ToString() == "")
    22             {
    23                 return strRet;
    24             }
    25             string targeturl = url.Trim().ToString();
    26             try
    27             {
    28                 HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(targeturl);
    29                 hr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
    30                 hr.Method = "GET";
    31                 hr.Timeout = 30 * 60 * 1000;
    32                 WebResponse hs = hr.GetResponse();
    33                 Stream sr = hs.GetResponseStream();
    34                 StreamReader ser = new StreamReader(sr, Encoding.Default);
    35                 strRet = ser.ReadToEnd();
    36             }
    37             catch (Exception ex)
    38             {
    39                 strRet = null;
    40             }
    41             return strRet;
    42         }
    43     }
  • 相关阅读:
    数据库插入
    c#里面调用python
    抓取最好大学网
    selenium抓取慕课课程
    excel合并
    网页抓取
    pyinstaller打包报错
    获取微信联系人
    c#部分类
    C#只读属性
  • 原文地址:https://www.cnblogs.com/pushudepu/p/6067669.html
Copyright © 2011-2022 走看看