.NET MVC中如何使用手机验证码注册登陆
2018-09-18 06:55:04来源:博客园 阅读 ()
#region 手机验证码
/// <summary>
///
/// </summary>
/// <param name="Yonghushouji">验证码的手机号</param>
/// <returns></returns>
public ActionResult Fayzm(string Yonghushouji)
{
//产生随机验证码
Random r = new Random();
string temMsg = string.Empty;
for (int i = 0; i < 6; i++)
{
temMsg += r.Next(0, 9);
}
//保存随机码
Dq.Bll.SendYzmBll senbll = new Dq.Bll.SendYzmBll();
Dq.Model.SendYzm smodel = new Dq.Model.SendYzm();
smodel.shouji = Yonghushouji;
smodel.yzm = temMsg;
smodel.GuoqiTime = DateTime.Now.AddMinutes(5);
senbll.Add(smodel);
//post
string uid = "你所用的ID";
string auth = "密匙";
string mobile = "" + Yonghushouji + "";
string url = "测试开发商的网址?uid=" + uid + "&auth=" + auth + "&mobile=" + mobile + "&expid=0&msg=";
string content = "本次验证码为:" + temMsg + ""; //发送验证码的消息提示语句
System.Text.Encoding encode = System.Text.Encoding.GetEncoding("GBK");
content = HttpUtility.UrlEncode(content, encode);
url += content;
Console.WriteLine("GET提交消息url:" + url);
string resp = CreateGetHttpResponse(url);
Console.WriteLine("响应:" + HttpUtility.UrlDecode(resp, encode));
//Console.ReadLine();
return Content("ok");
}
//验证输入的验证码
public ActionResult CheckYzm(string shuyzm, string yonghuShouji)
{
Dq.Bll.PersonBll mbll = new Dq.Bll.PersonBll();
//先去数据库取数据
Dq.Bll.SendYzmBll senbll = new Dq.Bll.SendYzmBll();
var sylist = senbll.GetList(d => d.shouji == yonghuShouji && d.GuoqiTime > DateTime.Now).ToList().OrderByDescending(d => d.id).ToList();
var yzm = sylist[0].yzm;
//var dianpId = sylist[0].DianpuId;
if (!string.IsNullOrEmpty(yzm))
{
if (yzm == shuyzm)
{
var mlist = mbll.GetList(d => d.Shoujihao == yonghuShouji).ToList();
var dianpId = mlist[0].ID;
return Content("ok," + dianpId + "");
}
else
{
return Content("验证码不正确");
}
}
else
{
return Content("验证码失效请重新获取");
}
}
public static string CreateGetHttpResponse(string url)
{
string strRet = null;
if (url == null || url.Trim().ToString() == "")
{
return strRet;
}
string targeturl = url.Trim().ToString();
try
{
HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(targeturl);
hr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
hr.Method = "GET";
hr.Timeout = 30 * 60 * 1000;
WebResponse hs = hr.GetResponse();
Stream sr = hs.GetResponseStream();
StreamReader ser = new StreamReader(sr, System.Text.Encoding.Default);
strRet = ser.ReadToEnd();
Console.WriteLine("<br/>get resp=" + strRet);
}
catch (Exception ex)
{
strRet = null;
}
return strRet;
}
#endregion
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- asp.net源程序编译为dll文件并调用的实现过程 2020-03-29
- Asp.net MVC SignalR来做实时Web聊天实例代码 2020-03-29
- ASP.NET MVC中jQuery与angularjs混合应用传参并绑定数据 2020-03-29
- Asp.Net中WebForm的生命周期 2020-03-29
- ASP.NET使用Ajax返回Json对象的方法 2020-03-23
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash