一直都用這個平臺發(fā)手機短信的公壤,今天做新項目的時候用到了暮刃,但是上來博客搜索不到融师,只好翻以前的源代碼翻了好久才找到了翔试,先記下來轻要,以作備用:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
namespace Niunan.CardShop.Web.Code
{
public class SendMobile
{
/// <summary>返回發(fā)送短信的狀態(tài)說明
///
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string GetMobileMSMStatus(string str)
{
string s = "";
switch (str)
{
case "-1":
s = "沒有該用戶賬戶";
break;
case "-2":
s = "密鑰不正確(不是用戶密碼)";
break;
case "-3":
s = "短信數量不足";
break;
case "-11":
s = "該用戶被禁用";
break;
case "-14":
s = "短信內容出現非法字符";
break;
case "-4":
s = "手機號格式不正確";
break;
case "-41":
s = "手機號碼為空";
break;
case "-42":
s = "短信內容為空";
break;
default:
s = "成功發(fā)送" + str + "條短信";
break;
}
return s;
}
/// <summary>發(fā)送手機短信
///
/// </summary>
/// <param name="mobile">手機號碼,多個手機號以,號相隔</param>
/// <param name="body">短信內容</param>
public static string SendMobileMSM(string mobile, string body)
{
string url = "http://utf8.sms.webchinese.cn/?Uid=xxxxxx&Key=xxxxxx&smsMob=" + mobile + "&smsText=" + body;
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);
return GetMobileMSMStatus(ser.ReadToEnd());
}
catch (Exception ex)
{
throw ex;
}
}
}
}