.NET MVC中如何使用手機驗證碼註冊登錄

#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);dom

//post
string uid = "你所用的ID";
string auth = "密匙";
string mobile = "" + Yonghushouji + "";post

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;ui

Console.WriteLine("GET提交消息url:" + url);
string resp = CreateGetHttpResponse(url);
Console.WriteLine("響應:" + HttpUtility.UrlDecode(resp, encode));
//Console.ReadLine();
return Content("ok");url

}
//驗證輸入的驗證碼
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("驗證碼失效請從新獲取");
}
}code


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;
}
#endregionget

相關文章
相關標籤/搜索