📄 newsms.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBLibrary;
using SMS_Lib;
using System.Text.RegularExpressions;
using AjaxPro;
public partial class SMS_NewSms : SMS_PageBase
{
private DBLibrary.DBClass db = new DBClass();
public string RealName = "";
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(SMS_NewSms));
RealName =Session["SMS_NAME"] == null ? "" : Session["SMS_NAME"].ToString().Trim();
this.SelfName.Text = RealName;
}
private bool IsRegEx(string regExValue, string itemValue)
{
try
{
Regex regex = new System.Text.RegularExpressions.Regex(regExValue);
if (regex.IsMatch(itemValue))
{
return true;
}
else
{
return false;
}
}
catch (Exception)
{
return false;
}
finally
{
}
}
/// <summary>
/// 发送短信息,
/// </summary>
/// <param name="receive">接收者</param>
/// <param name="type">短信类型</param>
/// <param name="smemo">短信内容</param>
/// <returns>10返回失败,20,成功,30异常</returns>
[AjaxPro.AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
public string SendNewSms(string receive, string type, string smemo,string time_type,string sendtime)
{
int Fail = 0;
int snRet = 0;
int Success = 0;
string nRet = "";
string SmsRealName = Session["SMS_NAME"] == null ? "星幻短信:" : Session["SMS_NAME"].ToString().Trim()+":";
string memo = smemo.Trim();
if (smemo.IndexOf("|") > 0 && smemo.IndexOf("|") < 5)
{
SmsRealName = smemo.Substring(0, smemo.IndexOf("|")) + ":";
memo = memo.Substring(smemo.IndexOf("|")+1);
}
else
{
SmsRealName = "";
memo = memo.Substring(1);
}
if (time_type.ToString() == "1")
{
if (DateTime.Parse(sendtime) <= DateTime.Now)
{
nRet = "提交失败,定时发送日期必须大于当前时间!";
return nRet;
}
}
if (!NString.ChcekStr(receive, "0123456789;"))
{
nRet = "发送失败,接收者格式有误.请重新输入!";
return nRet;
}
string[] relist = receive.ToString().Trim().Split(';');
//if (!this.CheckMoney(relist.Length.ToString()))
//{
// nRet = "发送失败,余额不足.请充值后再发送!";
// return nRet; //金额不足
//}
string sendmsg = "";
for (int j = 0; j < relist.Length; j++) //手机号数组
{
if (relist[j].Trim().Length <= 0)
{
continue;
}
//不符合号码格式过滤 移动
if (relist[j].ToString().Trim().StartsWith("1"))
{
if (!IsRegEx("(^15[3|8|9]{1}[0-9]{8}$)|(^13[0-9]{9}$)", relist[j].ToString().Trim()))
{
nRet = "发送失败,接收者格式有误.请重新输入!";
Fail++;
continue;
}
}
else if(relist[j].ToString().Trim().StartsWith("0")) //小灵通
{
if (!IsRegEx("^0[0-9]{10,11}$", relist[j].ToString().Trim()))
{
Fail++;
nRet = "发送失败,接收者格式有误.请重新输入!";
continue;
}
}
else
{
Fail++;
nRet = "发送失败,接收者格式有误.请重新输入!";
continue;
}
for (int i = 0; i < memo.Length; i += 65) //内容拆分
{
if (memo.Length > 65)
{
if ((memo.Length - i) < 65)
{
sendmsg = memo.Substring(i, memo.Length - i);
}
else
{
sendmsg = memo.Substring(i, 65);
}
}
else
{
sendmsg = memo;
}
if (sendmsg.Trim().Length <= 0)
{
nRet = "短信内容不能为空.请重新输入!";
continue;
}
//发送到网关
Success++;
if (time_type.ToString().Trim() == "0")//立即发送
{
System.Data.SqlClient.SqlParameter[] para =
{
db.MakeInputParameter("@smsid",SqlDbType.BigInt,8,Session["SMS_ID"].ToString().Trim()),
db.MakeInputParameter("@receiver",SqlDbType.NVarChar,50,relist[j].Trim()),
db.MakeInputParameter("@flag",SqlDbType.Int,4,type),
db.MakeInputParameter("@memo",SqlDbType.NVarChar,200,SmsRealName+sendmsg.Trim()),
db.MakeInputParameter("@remark",SqlDbType.NVarChar,100,Session["SMS_ID"].ToString().Trim()+"_0")
};
try
{
snRet = db.RunProcedureForInt("SMS_Web_AddNewSMS", para);
if (snRet == 10)
{
nRet = "发送终止,余额不足。已发送:" + Success.ToString() + "条,已过滤无效号码:" + Fail.ToString() + "条!";
return nRet;
}
}
catch
{
nRet = "发送错误,出现异常。已发送:" + Success.ToString() + "条,已过滤无效号码:" + Fail.ToString() + "条!";
return nRet;
}
}
else if(time_type.ToString().Trim()=="1")
{
/*[dbo].[SMS_Web_Destine_Add] -- 功能定制 1代表成功,10失败-金币不足,11失败,天气不存在'*/
System.Data.SqlClient.SqlParameter[] para =
{
db.MakeInputParameter("@Smsid",SqlDbType.BigInt,8,Session["SMS_ID"].ToString().Trim()),
db.MakeInputParameter("@smsNo",SqlDbType.NVarChar,50,relist[j].Trim()),
db.MakeInputParameter("@SmSType",SqlDbType.Int,4,type),
db.MakeInputParameter("@SmSMemo",SqlDbType.NVarChar,200,SmsRealName+sendmsg.Trim()),
db.MakeInputParameter("@funid",SqlDbType.Int,4,"2"),
db.MakeInputParameter("@endtime",SqlDbType.DateTime,8,sendtime)
};
try
{
snRet = db.RunProcedureForInt("SMS_Web_Destine_Add", para);
if (snRet == 10)
{
nRet = "操作终止,余额不足。已提交:" + Success.ToString() + "条,已过滤无效号码:" + Fail.ToString() + "条!";
return nRet;
}
}
catch
{
nRet = "操作错误,出现异常。已提交:" + Success.ToString() + "条,已过滤无效号码:" + Fail.ToString() + "条!";
return nRet;
}
}
}
}
if (snRet == 1)
{
nRet = "操作成功。已提交:" + Success.ToString() + "条放入定时作业队列,已过滤无效号码:" + Fail.ToString() + "条!";
}
else if (snRet == 20)
{
nRet = "操作成功。已发送:" + Success.ToString() + "条,已过滤无效号码:" + Fail.ToString() + "条!";
}
return nRet;
}
[AjaxPro.AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
public DataTable GetLatelySms(int top)
{
DataTable dt = null;
System.Data.SqlClient.SqlParameter []para =
{
db.MakeInputParameter("@sid",SqlDbType.BigInt,8,Session["SMS_ID"].ToString().Trim()),
db.MakeInputParameter("@top",SqlDbType.Int,4,top)
};
try
{
dt = db.RunProcedureForDataSet("SMS_Web_GetLatelySMS", para).Tables[0];
}
catch
{
}
return dt;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -