2023年7月31日发(作者:)
C#短信发送接⼝源码短信发送接⼝源码(注册,登录,改密)using ;using ;using ;using ;using ;using System;using c;using ent;using ;using ;using s;using rExpressions;using ;namespace ager{ /// /// 短信发送接⼝ /// type 验证码类别 1注册;2修改密码;3绑定 /// mobile ⼿机号 /// public class SMS : IHttpHandler { public void ProcessRequest(HttpContext context) { tType = "application/json"; string mobile = ing("mobile").ToLower(); int type = ("type", 1); if (type<1||type>3) { son("error", "短信类型错误"); } if (OrEmpty(mobile)) { son("error", "请输⼊⼿机号码"); } if (!new Regex(@"^d{11}$").IsMatch(mobile)) { son("error", "⼿机号码输⼊错误,请重新输⼊"); } //判断发送是否频繁 var result = IsSendCaptchaTooQuick(mobile); if (result != -1 && result < 120) { son("error", "请在" + (120 - result).ToString().Split('.')[0] + "秒后尝试"); } //验证码 string yzmNum = new Random().Next(100000, 1000000).ToString(); //发送短信 //1注册;2修改密码;3绑定 string[] templateids = { "313914", "313928", "313929" }; string res = SendSms(mobile, yzmNum, templateids[type - 1]); //记录⽇志 AddSmsLog("", mobile, "您本次的验证码为" + yzmNum + ",120秒有效", res, yzmNum); son("ok", "成功"); son("ok", "成功"); } #region 发送短信 /// /// 发送短信 /// /// The mobile. /// The content. /// public string SendSms(string mobile, string yzmNum, string templateid) { try { HttpClient hc = new HttpClient(); string str = "{"sid":"b79f05e1c8d10423df77987ee8e50f33","token":"e0a4ded4abe5fb8940b88b9773897275","appid":"d74f52d3c261475ca7c226fe2ebc19ff","templateid":" + templateid + ","param":" + yzmNum + ","mobile":"" + mobile + "","uid":"2d92c6132139467b989d087c84a365d8"}"; //必须是json格式 StringContent sc = new StringContent(str); //必须添加报⽂头ContentType tType = ("application/json"); HttpResponseMessage res = ync("/ol/sms/sendsms", sc).Result; JObject json = (JObject)alizeObject(StringAsync().Result); return json["code"].ToString(); } catch { return "发送失败"; } } /// /// 判断⼿机验证码是否发送频繁 /// /// /// protected virtual double IsSendCaptchaTooQuick(string mobile) { if (OrEmpty(mobile)) { throw new ArgumentNullException("mobile"); } string sql = @"select top 1 CreatedOn from SmsLog where smstype=0 and Reciever = @Reciever and [ReturnVal]='000000' order by CreatedOn DESC"; SQLHelper helper = new SQLHelper("QPAccountsDBConnstr"); var createdOn = eScalar(sql, new SqlParameter() { ParameterName = "@Reciever", Value = mobile }); if (createdOn != null) { var sendTime = Time(createdOn); TimeSpan ts = ct(sendTime); return econds; } return -1; } /// /// 新增短信⽇志 /// /// 没⽤ /// ⼿机号 /// 没⽤ /// 接⼝返回的数据,这个接⼝000000表⽰正确 /// 发送的验证码 private void AddSmsLog(string sender, string reciever, string content, string returnVal = null, string smsValue = null) { SqlParameter[] parameters = { new SqlParameter("@Id",d().ToString()), new SqlParameter("@Sender", sender), new SqlParameter("@Reciever",reciever), new SqlParameter("@Content", content), new SqlParameter("@ReturnVal", returnVal), new SqlParameter("@SmsValue", smsValue), new SqlParameter("@CreatedOn", )}; //默认0表⽰是没有使⽤的
var sql = @" INSERT INTO [SmsLog] (Id,[SmsType],[Sender],[Reciever],[Content],[ReturnVal],SmsValue,[CreatedOn]) VALUES (@Id,0,@Sender,@Reciever,@Content,@ReturnVal,@SmsValue,@CreatedOn)"; SQLHelper helper = new SQLHelper("QPAccountsDBConnstr"); int count = eNonQuery(sql, parameters); } #endregion #region 验证短信 private void VerificationSms(string mobile, string smscode, int type) { string sql = @"select top 1 CreatedOn from SmsLog where smstype=@type and Reciever = @Reciever and [ReturnVal]='000000' and SmsValue=@smsValue order by CreatedOn DESC"; SQLHelper helper = new SQLHelper("QPAccountsDBConnstr"); var createdOn = eScalar(sql, new SqlParameter() { ParameterName = "@Reciever", Value = mobile }, new SqlParameter() { ParameterName = "@smsValue", Value = smscode }, new SqlParameter() { ParameterName = "@type", Value = type }); if (createdOn != null) { var sendTime = Time(createdOn); TimeSpan ts = ct(sendTime); if (econds > 120) { son("error", "验证码已过期"); } else { son("ok", "成功"); } } else { son("error", "验证码错误"); } } #endregion #endregion public bool IsReusable { get { return false; } } }}
2023年7月31日发(作者:)
C#短信发送接⼝源码短信发送接⼝源码(注册,登录,改密)using ;using ;using ;using ;using ;using System;using c;using ent;using ;using ;using s;using rExpressions;using ;namespace ager{ /// /// 短信发送接⼝ /// type 验证码类别 1注册;2修改密码;3绑定 /// mobile ⼿机号 /// public class SMS : IHttpHandler { public void ProcessRequest(HttpContext context) { tType = "application/json"; string mobile = ing("mobile").ToLower(); int type = ("type", 1); if (type<1||type>3) { son("error", "短信类型错误"); } if (OrEmpty(mobile)) { son("error", "请输⼊⼿机号码"); } if (!new Regex(@"^d{11}$").IsMatch(mobile)) { son("error", "⼿机号码输⼊错误,请重新输⼊"); } //判断发送是否频繁 var result = IsSendCaptchaTooQuick(mobile); if (result != -1 && result < 120) { son("error", "请在" + (120 - result).ToString().Split('.')[0] + "秒后尝试"); } //验证码 string yzmNum = new Random().Next(100000, 1000000).ToString(); //发送短信 //1注册;2修改密码;3绑定 string[] templateids = { "313914", "313928", "313929" }; string res = SendSms(mobile, yzmNum, templateids[type - 1]); //记录⽇志 AddSmsLog("", mobile, "您本次的验证码为" + yzmNum + ",120秒有效", res, yzmNum); son("ok", "成功"); son("ok", "成功"); } #region 发送短信 /// /// 发送短信 /// /// The mobile. /// The content. /// public string SendSms(string mobile, string yzmNum, string templateid) { try { HttpClient hc = new HttpClient(); string str = "{"sid":"b79f05e1c8d10423df77987ee8e50f33","token":"e0a4ded4abe5fb8940b88b9773897275","appid":"d74f52d3c261475ca7c226fe2ebc19ff","templateid":" + templateid + ","param":" + yzmNum + ","mobile":"" + mobile + "","uid":"2d92c6132139467b989d087c84a365d8"}"; //必须是json格式 StringContent sc = new StringContent(str); //必须添加报⽂头ContentType tType = ("application/json"); HttpResponseMessage res = ync("/ol/sms/sendsms", sc).Result; JObject json = (JObject)alizeObject(StringAsync().Result); return json["code"].ToString(); } catch { return "发送失败"; } } /// /// 判断⼿机验证码是否发送频繁 /// /// /// protected virtual double IsSendCaptchaTooQuick(string mobile) { if (OrEmpty(mobile)) { throw new ArgumentNullException("mobile"); } string sql = @"select top 1 CreatedOn from SmsLog where smstype=0 and Reciever = @Reciever and [ReturnVal]='000000' order by CreatedOn DESC"; SQLHelper helper = new SQLHelper("QPAccountsDBConnstr"); var createdOn = eScalar(sql, new SqlParameter() { ParameterName = "@Reciever", Value = mobile }); if (createdOn != null) { var sendTime = Time(createdOn); TimeSpan ts = ct(sendTime); return econds; } return -1; } /// /// 新增短信⽇志 /// /// 没⽤ /// ⼿机号 /// 没⽤ /// 接⼝返回的数据,这个接⼝000000表⽰正确 /// 发送的验证码 private void AddSmsLog(string sender, string reciever, string content, string returnVal = null, string smsValue = null) { SqlParameter[] parameters = { new SqlParameter("@Id",d().ToString()), new SqlParameter("@Sender", sender), new SqlParameter("@Reciever",reciever), new SqlParameter("@Content", content), new SqlParameter("@ReturnVal", returnVal), new SqlParameter("@SmsValue", smsValue), new SqlParameter("@CreatedOn", )}; //默认0表⽰是没有使⽤的
var sql = @" INSERT INTO [SmsLog] (Id,[SmsType],[Sender],[Reciever],[Content],[ReturnVal],SmsValue,[CreatedOn]) VALUES (@Id,0,@Sender,@Reciever,@Content,@ReturnVal,@SmsValue,@CreatedOn)"; SQLHelper helper = new SQLHelper("QPAccountsDBConnstr"); int count = eNonQuery(sql, parameters); } #endregion #region 验证短信 private void VerificationSms(string mobile, string smscode, int type) { string sql = @"select top 1 CreatedOn from SmsLog where smstype=@type and Reciever = @Reciever and [ReturnVal]='000000' and SmsValue=@smsValue order by CreatedOn DESC"; SQLHelper helper = new SQLHelper("QPAccountsDBConnstr"); var createdOn = eScalar(sql, new SqlParameter() { ParameterName = "@Reciever", Value = mobile }, new SqlParameter() { ParameterName = "@smsValue", Value = smscode }, new SqlParameter() { ParameterName = "@type", Value = type }); if (createdOn != null) { var sendTime = Time(createdOn); TimeSpan ts = ct(sendTime); if (econds > 120) { son("error", "验证码已过期"); } else { son("ok", "成功"); } } else { son("error", "验证码错误"); } } #endregion #endregion public bool IsReusable { get { return false; } } }}
发布评论