您目前尚未登陆,请选择【登陆】或【注册
首页->行政办公->星幻短信群发平台Web源码>>SMS_SendGroup.aspx.cs>>代码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:星幻短信群发平台Web源码


当前文件路径:XingHuanWebSms/SMS_SendGroup.aspx.cs 文件类型
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11using DBLibrary; 12using SMS_Lib; 13using System.Text; 14using System.Text.RegularExpressions; 15public partial class SMS_SMS_SendGroup : SMS_PageBase 16{ 17 private DBLibrary.DBClass db = new DBClass(); 18 protected void Page_Load(object sender, EventArgs e) 19 { 20 if (Page.IsPostBack) 21 { 22 SendGroup(); 23 } 24 } 25 26 private bool IsRegEx(string regExValue, string itemValue) 27 { 28 29 try 30 { 31 Regex regex = new System.Text.RegularExpressions.Regex(regExValue); 32 if (regex.IsMatch(itemValue)) 33 { 34 return true; 35 } 36 else 37 { 38 return false; 39 } 40 } 41 catch (Exception) 42 { 43 return false; 44 } 45 finally 46 { 47 } 48 } 49 50 private void SendGroup() 51 { 52 string memo = ""; 53 string flag = "0"; 54 string nRet=""; 55 if (Request["smemo"] != null && Request["smemo"].ToString().Trim()!="") 56 { 57 memo =Request["smemo"].ToString().Trim(); 58 } 59 if(Request["stype"] !=null && Request["stype"].ToString().Trim() !="") 60 { 61 flag = Request["stype"].ToString().Trim(); 62 } 63 if (memo.Trim().Length <= 0) 64 { 65 Response.Write(JSAlert("发送的内容不能为空!")); 66 return; 67 } 68 69 StringBuilder sb = new StringBuilder(); 70 string filename = Up_Txt(); 71 if (filename == null || filename == "") 72 { 73 Response.Write(JSAlert("上传失败,必须是TXT文件!")); 74 return; 75 } 76 System.IO.StreamReader sr = new System.IO.StreamReader(filename); 77 string receive = ""; 78 int Fail = 0; 79 int Success = 0; 80 int nMobile = 0; 81 int nUNiom = 0; 82 int nCNC = 0; 83 while((receive = sr.ReadLine())!=null) 84 { 85 //号码验证 86 if (!NString.ChcekStr(receive, "0123456789")) 87 { 88 Fail++; 89 continue; 90 } 91 //正则验证,暂时关闭发送小灵通 92 //不符合号码格式过滤 移动 93 if (receive.ToString().Trim().StartsWith("1")) 94 { 95 if (IsRegEx("(^15[8|9]{1}[0-9]{8}$)|(^13[4-9]{1}[0-9]{8}$)", receive.ToString().Trim())) 96 { 97 nMobile++; 98 } 99 else 100 { 101 if (IsRegEx("(^153[0-9]{8}$)|(^13[0-3]{1}[0-9]{8}$)", receive.ToString().Trim())) 102 { 103 nUNiom++; 104 } 105 else 106 { 107 Fail++; 108 continue; 109 } 110 } 111 } 112 else if (receive.ToString().Trim().StartsWith("0")) //小灵通 113 { 114 if (IsRegEx("^0[0-9]{10,11}$", receive.ToString().Trim())) 115 { 116 nCNC++; 117 } 118 else 119 { 120 Fail++; 121 continue; 122 } 123 124 } 125 else 126 { 127 Fail++; 128 continue; 129 } 130 131 //成功号码累计 132 Success++; 133 sb.Append(receive); 134 sb.Append("|"); 135 136 } 137 sr.Close(); 138 try 139 { 140 if (sb.Length <= 0) 141 { 142 //删除无效上传文件 143 System.IO.File.Delete(filename); 144 Response.Write(JSAlert("发送失败,没有找到有效号码!")); 145 return; 146 } 147 } 148 catch 149 { 150 Response.Write(JSAlert("删除文件时,出现异常,稍后再试!")); 151 return; 152 } 153 //-写入历史记录------------------------------------------------------------------------------ 154 int g_id = 0; 155 int total_send = 0; 156 if (memo.Length <= 70) 157 { 158 total_send = Success; 159 } 160 else 161 { 162 if (memo.Length % 70 == 0) 163 { 164 total_send = (memo.Length / 70) * Success; 165 } 166 else 167 { 168 total_send = (memo.Length / 70+1) * Success; 169 } 170 } 171 System.Data.SqlClient.SqlParameter[] pam = 172 { 173 db.MakeInputParameter("@sms_id",SqlDbType.BigInt,8,this.sms_id), 174 db.MakeInputParameter("@sms_memo",SqlDbType.NVarChar,1500,memo), 175 db.MakeInputParameter("@sms_count",SqlDbType.BigInt,8,total_send) 176 }; 177 try 178 { 179 g_id = db.RunProcedureForInt("SMS_Web_AddGroupSMS", pam); 180 } 181 catch 182 { 183 Response.Write(JSAlert("出现异常,稍后再试!")); 184 return; 185 } 186 187 //------------------------------------------------------------------------------------------- 188 string sendmsg = ""; 189 int sended = 0; 190 string []re_list =sb.ToString().Trim().Split('|'); 191 for (int j = 0; j < re_list.Length; j++) //手机号数组 192 { 193 if(re_list[j].Trim().Length<=0) 194 { 195 continue; 196 } 197 for (int i = 0; i < memo.Length; i += 70) //内容拆分 198 { 199 if (memo.Length > 70) 200 { 201 if ((memo.Length - i) < 70) 202 { 203 sendmsg = memo.Substring(i, memo.Length - i); 204 } 205 else 206 { 207 sendmsg = memo.Substring(i, 70); 208 } 209 } 210 else 211 { 212 sendmsg = memo; 213 } 214 if (sendmsg.Trim().Length <= 0) 215 { 216 continue; 217 } 218 sended++; 219 //发送到网关 220 System.Data.SqlClient.SqlParameter[] para = 221 { 222 db.MakeInputParameter("@smsid",SqlDbType.BigInt,8,this.sms_id), 223 db.MakeInputParameter("@receiver",SqlDbType.NVarChar,50,re_list[j].Trim()), 224 db.MakeInputParameter("@flag",SqlDbType.Int,4,flag), 225 db.MakeInputParameter("@memo",SqlDbType.NVarChar,200,sendmsg.Trim()), 226 db.MakeInputParameter("@remark",SqlDbType.NVarChar,100,this.sms_id+"_1_"+g_id.ToString()) 227 }; 228 try 229 { 230 // int snRet = 0; 231 int snRet = db.RunProcedureForInt("SMS_Web_AddNewSMS", para); 232 if (snRet == 10) 233 { 234 nRet = "发送终止,余额不足。已处理:" + sended.ToString() + "条,已过滤无效号码:" + Fail.ToString() + "条!"; 235 Response.Write(JSAlert(nRet)); 236 return ; 237 } 238 239 } 240 catch 241 { 242 nRet = "发送错误,出现异常。已处理:" + sended.ToString() + "条,已过滤无效号码:" + Fail.ToString() + "条!"; 243 Response.Write(JSAlert(nRet)); 244 return ; 245 246 } 247 248 } 249 250 } 251 nRet = @"操作已成功。已处理有效总数:" + sended.ToString() + "条,其中\\r"; 252 nRet += @"移动号码:" + nMobile.ToString() + "个.\\r"; 253 nRet += @"联通号码:" + nUNiom.ToString()+ "个.\\r"; 254 nRet += @"小灵通号码:" + nCNC.ToString() + "个.\\r"; 255 nRet += @"提取无效号码:" + Fail.ToString() + ""; 256 //string putjs = "<script>alert('" + nRet + "');"; 257 Response.Write(JSAlert(nRet,"SMS_SendGroup.aspx")); 258 } 259 260 private string Up_Txt() 261 { 262 HttpFileCollection files = HttpContext.Current.Request.Files; 263 System.Text.StringBuilder strMsg = new System.Text.StringBuilder(); 264 string[] file_name = new string[files.Count]; 265 string NewPath_Name=""; 266 strMsg.Append("上传的文件分别是:<hr color=red>"); 267 try 268 { 269 HttpPostedFile postedFile = files[0]; 270 string fileName, fileExtension; 271 fileName = System.IO.Path.GetFileName(postedFile.FileName); 272 if (fileName != "") 273