由於使用 收費 第三方 屏蔽 可能有 免費 第三方。 private const string Cdkey = "8S*********************";密鑰id private const string Password = "151515******";密鑰密碼 private con ...
由於使用 收費 第三方 屏蔽 可能有 免費 第三方。
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;
}