private void Send(out string msg) { msg = ""; string[] telArry = Tels.Split(','); if (telArry.Length == 0) { msg = "电话号码不能为空"; return; } if (telArry.Length > 2) { msg = "电话号码不能超过3个"; return; } //Regex reTel = new Regex(@"(^13[0-9]{9}$)|(^15[0-9]{9}$)|(^17[0-9]{9}$)|(^18[0-9]{9}$)|(^14[0-9]{9}$)"); foreach (string str in telArry) { if (!string.IsNullOrEmpty(str)) { if (!BLL.Util.IsHandset(str)) { msg = "电话(" + str + ")不符合规则"; return; } #region 记录发送日志 Entities.SendSMSLog smsLogModel = new Entities.SendSMSLog(); smsLogModel.CreateUserID = BLL.Util.GetLoginUserID(); smsLogModel.CustID = "无主订单"; smsLogModel.Mobile = str; smsLogModel.SendContent = SendContent; smsLogModel.SendTime = DateTime.Now; smsLogModel.TemplateID = -1; BLL.SendSMSLog.Instance.Insert(smsLogModel); #endregion //发送短信 //com.bitauto.mobile.MsgService msgService = new com.bitauto.mobile.MsgService(); //string md5 = msgService.MixMd5("6116" + str + SendContent + "Ytt1TEy3hnYIgqTOOIGEc0MFL9wrN0yJJuUUPVfjyM+dkY3ei/8WUc8L7qFqgCbp"); //int msgid = msgService.SendMsgImmediately("6116", str, SendContent, "", DateTime.Now.AddHours(1), md5); string md5 = SMSServiceHelper.Instance.MixMd5(str, SendContent); int msgid = SMSServiceHelper.Instance.SendMsgImmediately(str, SendContent, DateTime.Now.AddHours(1), md5); if (msgid > 0) { //插入发送短信记录 BLL.Util.InsertUserLog("给手机(" + str + ")发送短信成功,内容:【" + SendContent + "】"); } else { msg = BLL.Util.GetEnumOptText(typeof(Entities.SendSMSInfo), msgid); BLL.Util.InsertUserLog("给手机(" + str + ")发送短信失败【错误信息:" + msg + "】"); } } } }
/// 发送短信 /// <summary> /// 发送短信 /// </summary> /// <param name="msg"></param> public void SendSMSToPeople(out string msg) { msg = string.Empty; try { string[] telArry = Tels.Split(','); if (telArry.Length == 0) { msg = "电话号码不能为空"; msg = "{result:'false',msg:'" + msg + "'}"; return; } if (telArry.Length > 2) { msg = "电话号码不能超过3个"; msg = "{result:'false',msg:'" + msg + "'}"; return; } foreach (string str in telArry) { if (!string.IsNullOrEmpty(str)) { string telstr = str.Trim(); if (!BLL.Util.IsHandset(telstr)) { msg = "电话(" + telstr + ")不符合规则"; msg = "{result:'false',msg:'" + msg + "'}"; return; } //计算客户id string custid = CustID; if (string.IsNullOrEmpty(custid)) { custid = BLL.CustBasicInfo.Instance.GetMaxNewCustBasicInfoByTel(telstr); } //插入发送日志 Entities.SendSMSLog smsLogModel = new Entities.SendSMSLog(); smsLogModel.CreateUserID = BLL.Util.GetLoginUserID(); smsLogModel.CustID = custid; smsLogModel.Mobile = telstr; smsLogModel.SendContent = SendContent; smsLogModel.SendTime = DateTime.Now; smsLogModel.TemplateID = CommonFunction.ObjectToInteger(TemplateID, -1); BLL.SendSMSLog.Instance.Insert(smsLogModel); //发送短信 int status = -1; string md5 = SMSServiceHelper.Instance.MixMd5(telstr, SendContent); int msgid = SMSServiceHelper.Instance.SendMsgImmediately(telstr, SendContent, DateTime.Now.AddHours(1), md5); if (msgid > 0) { //插入发送短信记录 status = 0; BLL.Util.InsertUserLog("给手机(" + telstr + ")发送短信成功"); msg = "{result:'true',msg:''}"; } else { msg = BLL.Util.GetEnumOptText(typeof(Entities.SendSMSInfo), msgid); BLL.Util.InsertUserLog("给手机(" + telstr + ")发送短信失败【错误信息:" + msg + "】"); msg = "{result:'false',msg:'" + msg + "'}"; } //插入发送短信记录 Entities.SMSSendHistory smssendhistory = new Entities.SMSSendHistory(); smssendhistory.CreateUserID = BLL.Util.GetLoginUserID(); smssendhistory.CustID = custid; smssendhistory.CRMCustID = CRMCustID; Entities.EmployeeAgent agent = new Entities.EmployeeAgent(); agent = BLL.EmployeeAgent.Instance.GetEmployeeAgentByUserID(Convert.ToInt32(smssendhistory.CreateUserID)); if (agent != null && agent.BGID > 0) { smssendhistory.BGID = agent.BGID; } smssendhistory.TemplateID = CommonFunction.ObjectToInteger(TemplateID, -1); smssendhistory.TaskType = CommonFunction.ObjectToInteger(TaskType, -1); smssendhistory.TaskID = TaskID; smssendhistory.Phone = telstr; smssendhistory.Content = SendContent; smssendhistory.CreateTime = DateTime.Now; smssendhistory.Status = status; BLL.SMSSendHistory.Instance.Insert(smssendhistory); //成功后返回 if (status == 0) { msg = "{result:'true',msg:'',SMSSendHistoryRecID:'" + smssendhistory.RecID + "'}"; } } } } catch (Exception ex) { msg = "{result:'false',msg:'" + ex.Message + "'}"; } }