1、获取配置文件设置。
static readonly string sMsgAccount = ReadConfig.ReadAppSetting("account");
static readonly string sMsgPassword = ReadConfig.ReadAppSetting("password");
static readonly string sMsgMD5key = ReadConfig.ReadAppSetting("MD5key");
2、 发送代码
public static bool SendPhoneMsg(string sMobile, string sMsg)
{
#region 发送短信
bool bResult = false;
#region 处理电话号码 --duncan
//try
//{
// sMobile = sMobile.Trim();
// if (string.IsNullOrEmpty(sMobile))
// return bResult;
// if (sMobile.First() == ',')
// sMobile = sMobile.Remove(0, 1);//替换第一个,
// if (sMobile.Length > 0 && sMobile.Last() == ',')
// sMobile = sMobile.Remove(sMobile.Length - 1, 1);//替换最后一个,
// string[] sArrPhoneNO = sMobile.Split(',').Distinct().ToArray();
// sMobile = string.Empty;
// foreach (string sPhoneNO in sArrPhoneNO)
// {
// if (string.IsNullOrEmpty(sPhoneNO))//空字符串不执行处理
// continue;
// //if (RequestControl.CheckCanBeSend(sPhoneNO))
// //{//如果是被限制发送的,则移除该号码
// // sMobile = sMobile + sPhoneNO + ",";
// //}
// //else
// //{
// // return false;
// //}
// }
// if (sMobile.Length > 0 && sMobile.Last() == ',')//移除最后一个逗号
// sMobile = sMobile.Remove(sMobile.Length - 1, 1);
//}
//catch (Exception ex)
//{
// throw new Exception(ex.Message);
//}
#endregion
string sContent = System.Web.HttpUtility.UrlEncode(Encoding.GetEncoding("utf-8").GetBytes(sMsg));
string sUrl = "http://IP/msg/HttpBatchSendSM" +
"?account="+sMsgAccount+"&pswd="+sMsgPassword+"&mobile="+ sMobile + "&msg=" +sContent+ "&needstatus=true";
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(sUrl);
webRequest.Method = "GET";
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
int iResult = Convert.ToInt32(webResponse.StatusCode);
if (iResult == 200)
bResult = true;
return bResult;
#endregion
}