標籤:msm break def throw namespace 字元 article xxxxxx 搜尋
一直都用這個平台發手機簡訊的,今天做新項目的時候用到了,但是上來部落格搜尋不到,只好翻以前的原始碼翻了好久才找到了,先記下來,以作備用:
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>返回傳送簡訊的狀態說明
///
/// </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 = "成功發送" + str + "條簡訊";
break;
}
return s;
}
/// <summary>傳送簡訊
///
/// </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;
}
}
}
}
用“網建”平台發手機簡訊的C#代碼