/// <summary> /// 创建DataRow并赋值 /// </summary> /// <param name="dt"></param> /// <param name="moblie"></param> /// <param name="info"></param> /// <returns></returns> public DataTable CreateRow(DataTable dt, string[] moblie, SmsInfo info) { for (int i = 0; i < moblie.Length; i++) { DataRow dr = dt.NewRow(); dr["mobile"] = moblie[i]; dr["msg"] = info.msg; dr["creatorId"] = info.creatorId; dr["creator"] = info.creator; dr["c_time"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); dr["sendFlag"] = ((int)SendFlag.未发送).ToString(); dr["sendTime"] = info.sendTime; dr["stype"] = info.stype; dr["pipeId"] = info.pipeId; dr["levelNum"] = info.levelNum; dr["sysPlatform"] = info.sysPlatform; dt.Rows.Add(dr); } return(dt); }
public string SmsSend(string mobiles, string msg, int?creatorId, string creator, DateTime?sendTime, int?sysPlatform = (int)Platform.网站系统, int?stype = (int)SendType.一般短信, int?levelNum = 0) { SmsError se = new SmsError(); JavaScriptSerializer serializer = new JavaScriptSerializer(); if (!myHeader.CheckLogin()) { se.errorNum = "010"; se.errosMsg = "身份认证不通过!"; var emsg = serializer.Serialize(se); return(emsg); } string filterstr = string.Empty; if (KeysFilter(msg, ref filterstr)) { se.errorNum = "007"; se.errosMsg = "内容包括非法字符!非法字符:" + filterstr; var emsg = serializer.Serialize(se); return(emsg); } try { string error = string.Empty; SmsInfo info = new SmsInfo() { creator = creator, creatorId = creatorId, levelNum = levelNum, mobile = mobiles, msg = msg, pipeId = _pipeId, sendTime = sendTime, stype = stype, sysPlatform = sysPlatform }; if (validate(info, ref se)) { string[] arrys = info.mobile.Replace(';', ';').Replace(',', ';').Split(';'); DataTable dt = CreateTable(); dt = CreateRow(dt, arrys, info); bool result = innserMsg(dt, _tableName, ref se); var emsg = serializer.Serialize(se); LogHelper.Info("系统异常error :" + emsg); return(emsg); } else { var emsg = serializer.Serialize(se); LogHelper.Info("参数丢失error :" + emsg); return(emsg); } } catch (Exception ex) { LogHelper.Error(ex); se = new SmsError() { errorNum = "006", errosMsg = ex.Message }; var emsg = serializer.Serialize(se); return(emsg); } }
/// <summary> /// 参数验证和填充表数据 /// </summary> /// <param name="info"></param> /// <param name="se"></param> /// <returns></returns> public bool validate(SmsInfo info, ref SmsError se) { //SmsError se = new SmsError(); if (string.IsNullOrWhiteSpace(info.mobile)) { se.errosMsg = "客户手机号码为空!"; se.errorNum = "001"; return(false); } if (!string.IsNullOrWhiteSpace(info.mobile)) { string[] arrys = info.mobile.Replace(';', ';').Replace(',', ';').Split(';'); if (arrys.Length > 100) { se.errosMsg = "手机号最多选中100个!"; se.errorNum = "009"; return(false); } } if (string.IsNullOrWhiteSpace(info.msg)) { se.errosMsg = "发送消息内容为空!"; se.errorNum = "002"; return(false); } if (!string.IsNullOrWhiteSpace(info.msg) && info.msg.Length >= 70) { se.errosMsg = "发送消息内容长度小于70个字符!"; se.errorNum = "008"; return(false); } if (info.creatorId == null) { info.creatorId = 0; //se.errosMsg = "发送消息人ID值为空!"; //se.errorNum = "003"; //return false; } if (string.IsNullOrWhiteSpace(info.creator)) { info.creator = "0"; //se.errosMsg = "发送消息人名字为空!"; //se.errorNum = "004"; //return false; } if (info.stype == null) { info.stype = (int)SendType.一般短信;//默认为一般短信 } if (info.sendTime == null) { info.sendTime = DateTime.Now; } if (info.levelNum == null) { info.levelNum = 0; } if (info.sysPlatform == null) { info.sysPlatform = (int)Platform.网站系统; } info.msg = _autograph + info.msg; return(true); }