/// <summary> /// 手机短信(单条发送) /// </summary> /// <param name="mobile">手机号码</param> /// <param name="content">短信内容</param> /// <param name="pass">短信通道1验证码通道2广告通道</param> /// <param name="msg">返回提示信息</param> /// <returns>bool</returns> public bool Send(string mobile, string content, int pass, out string msg) { if (string.IsNullOrEmpty(this.username) || string.IsNullOrEmpty(this.password)) { msg = "短信配置参数有误,请完善后再提交!"; return(false); } //验证手机号码 Regex r = new Regex(@"^1(3|4|5|7|8)\d{9}$", RegexOptions.IgnoreCase); if (!r.Match(mobile).Success) { msg = "手机号码格式不正确!"; return(false); } bool status = true; BLL.sms_log bll = new BLL.sms_log(); //查询是否超出平台限制 int thisSafeTotal = bll.GetCurDayCount(); if (this.safeTotal > 0 && thisSafeTotal > this.safeTotal) { msg = "对不起,平台短信发送量已超出最大限制!"; status = false; } //查询当前IP是否已经超出限制 string ip = DTRequest.GetIP(); int thisIpSendCount = bll.GetIPCount(ip); if (this.ipCount > 0 && thisIpSendCount > this.ipCount) { msg = "对不起,你的网络已经超出发送数量限制!"; status = false; } msg = string.Empty; if (status) { //发送短信 Model.sms_log model = new Model.sms_log(); model.mobile = mobile; model.content = content; model.send_time = DateTime.Now; try { string result = Utils.HttpPost(apiurl, "cmd=tx&pass="******"&uid=" + this.username + "&pwd=" + this.password + "&mobile=" + mobile + "&encode=utf8&content=" + Utils.UrlEncode(content)); string[] strArr = result.Split(new string[] { "||" }, StringSplitOptions.None); if (strArr[0] != "100") { status = false; model.status = 1; model.remark = "提交失败,错误提示:" + strArr[1]; msg = model.remark; } else { model.status = 0; model.remark = strArr[0]; msg = model.remark; } } catch (Exception ex) { status = false; model.status = 1; model.remark = "提交失败,错误提示:" + ex.Message; msg = model.remark; } bll.Add(model); } //返回状态 if (status) { msg = "发送成功!"; return(true); } return(false); }
/// <summary> /// 发送手机短信 /// </summary> /// <param name="mobile">手机号码,以英文“,”逗号分隔开</param> /// <param name="content">短信内容</param> /// <param name="pass">无作用(备用)</param> /// <param name="msg">返回提示信息</param> /// <returns>bool</returns> public bool Send(string mobile, string content, int pass, out string msg) { if (string.IsNullOrEmpty(this.username) || string.IsNullOrEmpty(this.password) || string.IsNullOrEmpty(apicode)) { msg = "短信配置参数有误,请完善后再提交!"; return(false); } //验证手机号码 Regex r = new Regex(@"^1(3|4|5|7|8)\d{9}$", RegexOptions.IgnoreCase); if (!r.Match(mobile).Success) { msg = "手机号码格式不正确!"; return(false); } bool status = true; BLL.sms_log bll = new BLL.sms_log(); //查询是否超出平台限制 int thisSafeTotal = bll.GetCurDayCount(); if (this.safeTotal > 0 && thisSafeTotal > this.safeTotal) { msg = "对不起,平台短信发送量已超出最大限制!"; status = false; } //查询当前IP是否已经超出限制 string ip = DTRequest.GetIP(); int thisIpSendCount = bll.GetIPCount(ip); if (this.ipCount > 0 && thisIpSendCount > this.ipCount) { msg = "对不起,你的网络已经超出发送数量限制!"; status = false; } msg = string.Empty; if (status) { //发送短信 Model.sms_log model = new Model.sms_log(); model.mobile = mobile; model.content = content; model.send_time = DateTime.Now; try { StringBuilder parameter = new StringBuilder(); parameter.AppendFormat("SpCode={0}&LoginName={1}&Password={2}&MessageContent={3}", this.apicode, this.username, this.password, content); parameter.AppendFormat("&UserNumber={0}&SerialNumber={1}&ScheduleTime=&ExtendAccessNum=&f=1", mobile, DateTime.Now.ToString("yyyyMMddHHmmssfff") + "001"); byte[] data = Encoding.GetEncoding("GBK").GetBytes(parameter.ToString()); HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = "http://sms.api.ums86.com:8899/sms/Api/Send.do", Encoding = Encoding.Default, Method = "POST", ContentType = "application/x-www-form-urlencoded", PostdataByte = data }; HttpResult result = http.GetHtml(item); //获取返回值 string code = QueryParameter(result.Html, "result"); //获取描述 string desc = QueryParameter(result.Html, "description"); if (string.IsNullOrEmpty(desc)) { //加载错误表 Dictionary <string, string> dic = ErrorDic(); if (dic.ContainsKey(code)) { desc = dic[code]; } } if (code == "0") { model.status = 0; model.remark = code; } else { model.status = 1; model.remark = desc; } } catch (Exception ex) { status = false; model.status = 1; model.remark = "提交失败,错误提示:" + ex.Message; msg = model.remark; } bll.Add(model); } //返回状态 if (status) { msg = "发送成功!"; return(true); } return(false); }