示例#1
0
文件: SMS.cs 项目: yzbjack/LebiShop
        //protected SMSClient smsClient;
        public static bool Send(string to, string body)
        {
            BaseConfig model       = ShopCache.GetBaseConfig();
            string     MobilePhone = to;
            string     Msg         = body;
            bool       flag;

            if (model.SMS_state == "0")
            {
                return(false);
            }
            if (MobilePhone == "")
            {
                return(false);
            }
            //if (MobilePhone.Length != 11)
            //    return false;
            body = body + model.SMS_lastmsg;
            try
            {
                if (model.SMS_server == "0")
                {
                    //时代互联通道
                    SMSClient smsClient = new SMSClient("sms.todaynic.com", Convert.ToInt32(model.SMS_serverport), model.SMS_user, model.SMS_password);
                    flag = smsClient.sendSMS(MobilePhone, Msg, model.SMS_apitype);
                    if (flag)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (model.SMS_server == "1")
                {
                    //yunsms.cn通道
                    string        pwd    = MD5(model.SMS_password); //密码MD5
                    string        uid    = model.SMS_user;          //用户名
                    StringBuilder sbTemp = new StringBuilder();
                    sbTemp.Append("uid=" + uid + "&pwd=" + pwd + "&mobile=" + to + "&content=" + body);
                    byte[] bTemp      = System.Text.Encoding.GetEncoding("GBK").GetBytes(sbTemp.ToString());
                    string postReturn = SMS.doPostRequest("http://http.yunsms.cn/tx/", bTemp);
                    if (postReturn == "100")
                    {
                        return(true);
                    }
                    return(false);
                }
                else if (model.SMS_server == "999")
                {
                    //通用接口
                    //"http://sms.soe.wang:8009/sys_port/gateway/?id=" + uid + "&pwd=" + pwd + "&to=" + mob + "&content=" + msg + "&time=";
                    string url = model.SMS_httpapi.ToLower().Replace("{$username}", model.SMS_user);
                    url = url.Replace("{$password}", model.SMS_password);
                    url = url.Replace("{$phonenumber}", MobilePhone);
                    url = url.Replace("{$content}", System.Web.HttpUtility.UrlEncode(Msg, System.Text.Encoding.GetEncoding("GB2312")));
                    url = url.Replace("{$content_utf-8}", System.Web.HttpUtility.UrlEncode(Msg, System.Text.Encoding.GetEncoding("UTF-8")));
                    string res = doGetRequest(url);
                    return(true);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }