C# 发送手机短信

 

由于使用 收费 第三方 屏蔽   可能有 免费 第三方。

private const string Cdkey = "8S*********************";密钥id
private const string Password = "151515******";密钥密码
private const string BaseUrl = "http://hprpt******地址*";
/// <summary>
/// 发送及时短信
/// </summary>
/// <param name="phone"></param>
/// <param name="content"></param>
/// <returns></returns>
public string SendSms(string phone, string content)
{
//UTF-8
string Content = HttpUtility.UrlEncode(content.Trim(), System.Text.Encoding.GetEncoding("UTF-8"));
phone = phone.Replace("\r\n", "").Trim();
string sendurl = BaseUrl + "/sdkproxy/sendsms.action?cdkey=" + Cdkey + "&password=" + Password + "&phone=" + phone + "&message=" + Content;
var resultstr = string.Empty;
try
{

var rst = (HttpWebRequest)WebRequest.Create(sendurl); //主要第一步
using (var stream = rst.GetResponse().GetResponseStream())//第二步
{
if (stream != null)
{
using (var reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))//3
{
resultstr = reader.ReadToEnd();//4

}
}
}
}
catch (Exception ex)
{
throw;
}
return resultstr;
}

posted @ 2018-03-20 16:12  GOGOGO陈  阅读(824)  评论(2编辑  收藏  举报