发送短信功能

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
        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值