asp.net 短信群发

寻技术 ASP.NET编程 / 其他编程 2023年07月11日 111
 protected void Btn_Save_Click(object sender, EventArgs e)
    {
        string Contents = this.Txt_SmsContents.Text.Trim();
        if (Request["ckEmployee"] != null)
        {
            DataTable Dt = new DataTable();
            Dt.Columns.Add("Contents", typeof(string));
            Dt.Columns.Add("ReceiveMan", typeof(Guid));
            Dt.Columns.Add("ReceiveManCode", typeof(string));
            Dt.Columns.Add("ReceiveManName", typeof(string));
            Dt.Columns.Add("SendMan", typeof(Guid));
            Dt.Columns.Add("SendManCode", typeof(string));
            Dt.Columns.Add("SendManName", typeof(string));
            Dt.Columns.Add("TaskNo", typeof(Guid));
            Dt.Columns.Add("CompanyID", typeof(Guid));

            ArrayList Al_PhoneNumbers = new ArrayList();//接收短信的手机号码
            string StrEmployee = "";//手机号码未设置的员工
            string ckEmployee = Request["ckEmployee"].ToString();
            string[] ckArr = ckEmployee.Split(',');//得到员工信息ID@ENumber@Name@Phone
            Guid TaskNo = Guid.NewGuid();//短信发送任务编号
            for (int i = 0; i < ckArr.Length; i++)
            {
                string[] EmployeeArr = ckArr[i].Split('@');
                Guid ID = Guid.Parse(EmployeeArr[0].Trim());//员工ID
                string ENumber = EmployeeArr[1].Trim();//员工工号
                string Phone = EmployeeArr[2].Trim();//员工手机号码
                string RealName = EmployeeArr[3].Trim();//员工姓名
                if (Phone.Equals(""))
                {
                    StrEmployee += RealName + "(" + ENumber + ")<br/>";
                }
                else
                {
                    if (!Al_PhoneNumbers.Contains(Phone))
                    {
                        Al_PhoneNumbers.Add(Phone);
                        object[] EmployeeRow = { Contents, ID, ENumber, RealName, SendMan, SendManCode, SendManName, TaskNo, CompanyID };
                        Dt.Rows.Add(EmployeeRow);
                    }
                }
            }
            string[] Mobiles = (string[])Al_PhoneNumbers.ToArray(typeof(string));
            //开始发送短信
            opa_sysinfo = OPA_SysInfo.GetSmsAccountInfo();
            if (!opa_sysinfo.ID.Equals(Guid.Empty))
            {
                int smspriority = 1;
                if (!Request["sel_smspriority"].ToString().Equals(""))
                {
                    smspriority = int.Parse(Request["sel_smspriority"].ToString());
                }
                string srcCharset = "GBK";
                if (!Request["sel_srcCharset"].ToString().Equals(""))
                {
                    srcCharset = Request["sel_srcCharset"].ToString();
                }
                emaysms.softwareSerialNo = opa_sysinfo.SoftwareSerialNo;
                emaysms.key = opa_sysinfo.RegKey;
                emaysms.sendTime = DateTime.Now.ToString();
                emaysms.Mobiles = Mobiles;
                emaysms.StrContent = this.Txt_SmsContents.Text.Trim();
                emaysms.addserial = "";
                emaysms.srcCharset = srcCharset;
                emaysms.smspriority = smspriority;
                emaysms.smsID = new Random().Next(1, 1000);// long.Parse(Guid.NewGuid().ToString());
                emaysms = EmaySMS.SendSMS(emaysms);
                if (emaysms.ReturnCode.Equals(0))//短信发送成功,将短信记录写入数据库
                {
                    bool Result = OPA_SmsRecord.InsertSendSmsRecord(Dt);
                    if (Result)
                    {
                        Function.AlertMsg("短信发送成功!");
                    }
                    else
                    {
                        Function.AlertMsg("短信发送成功,短信记录写入失败,请联系管理员!", "SendSms.aspx");
                    }
                    if (StrEmployee.Trim() != "")
                    {
                        this.lab_Msg.Text = "<font style=\"color:red;font-weight:bold;\">未设置手机号码的接收者:<font/>" + StrEmployee;
                    }
                }
                else
                {
                    if (StrEmployee.Trim() != "")
                    {
                        this.lab_Msg.Text = "短信发送失败!" + emaysms.ReturnMsg + " <font style=\"color:red;font-weight:bold;\">未设置手机号码的接收者:<font/>" + StrEmployee;
                    }
                    else
                    {
                        this.lab_Msg.Text = "短信发送失败!" + emaysms.ReturnMsg;
                    }
                }
            }
            else
            {
                this.lab_Msg.Text = "请先设置好亿美短信平台账号,并激活账号!";
            }
        }
    }

 

关闭

用微信“扫一扫”