/// <summary> /// 检查账户信息是否正确 /// </summary> /// <returns></returns> public static bool Exists() { siteconfig siteConfig = ConfigLoader.loadSiteConfig(); //获得站点配置信息 if (string.IsNullOrEmpty(siteConfig.smsapiurl) || string.IsNullOrEmpty(siteConfig.smsusername) || string.IsNullOrEmpty(siteConfig.smspassword)) { return(false); } return(true); }
/// <summary> /// 发送短信验证码,九维接口 /// </summary> /// <param name="mobiles"></param> /// <param name="content"></param> /// <param name="msg"></param> /// <returns></returns> public static bool SendSmsCode(string mobile, string content, out string msg) { siteconfig siteConfig = ConfigLoader.loadSiteConfig(); //获得站点配置信息 //检测号码,忽略不合格的 Regex r = new Regex(@"^1\d{10}$", RegexOptions.IgnoreCase); if (r.Match(mobile).Success) { //发送短信 try { string result = Utils.HttpPost(siteConfig.smsapiurl, "productid=936245&username="******"&password="******"&mobile=" + mobile + "&content=" + Utils.UrlEncode(content)); string[] strArr = result.Split(new string[] { "," }, StringSplitOptions.None); if (strArr[0] != "1") { msg = GetJwErrorType(strArr[0]); return(false); } else { msg = "发送短信验证码成功!"; return(true); } } catch (Exception ex) { msg = "发送短信验证码失败:" + ex.Message; return(false); } } else { msg = "发送短信验证码失败:短信号码错误!"; return(false); } }
/// <summary> /// 发送营销短信 九维天地接口 /// </summary> /// <param name="mobiles">手机号码,以英文“,”逗号分隔开</param> /// <param name="content">短信内容</param> /// <param name="pass">短信通道1验证码通道2广告通道 暂无用</param> /// <param name="msg">返回提示信息</param> /// <returns>bool</returns> public static bool Send(string mobiles, string content, int pass, out string msg) { siteconfig siteConfig = ConfigLoader.loadSiteConfig(); //获得站点配置信息 //检查是否设置好短信账号 if (!Exists()) { msg = "短信配置参数有误,请完善后再提交!"; return(false); } //检查手机号码,如果超过2000则分批发送 int sucCount = 0; //成功提交数量 string errorMsg = string.Empty; //错误消息 string[] oldMobileArr = mobiles.Split(','); int batch = oldMobileArr.Length / 2000 + 1; //2000条为一批,求出分多少批 for (int i = 0; i < batch; i++) { StringBuilder sb = new StringBuilder(); int sendCount = 0; //发送数量 int maxLenght = (i + 1) * 2000; //循环最大的数 //检测号码,忽略不合格的,重新组合 for (int j = 0; j < oldMobileArr.Length && j < maxLenght; j++) { int arrNum = j + (i * 2000); string pattern = @"^1\d{10}$"; string mobile = oldMobileArr[arrNum].Trim(); if (mobile.Length != 11) { continue; } Regex r = new Regex(pattern, RegexOptions.IgnoreCase); //正则表达式实例,不区分大小写 if (r.Match(mobile).Success) { sendCount++; sb.Append(mobile + ","); } } //发送短信 if (sb.ToString().Length > 0) { try { string result = Utils.HttpPost(siteConfig.smsapiurl, "productid=936245&username="******"&password="******"&mobile=" + Utils.DelLastComma(sb.ToString()) + "&content=" + Utils.UrlEncode(content)); string[] strArr = result.Split(new string[] { "," }, StringSplitOptions.None); if (strArr[0] != "1") { errorMsg = "提交失败," + GetJwErrorType(strArr[0]); continue; } sucCount += sendCount; //成功数量 } catch { //没有动作 } } } //返回状态 if (sucCount > 0) { msg = "成功提交" + sucCount + "条,失败" + (oldMobileArr.Length - sucCount) + "条"; return(true); } msg = errorMsg; return(false); }