#region 手機驗證碼 /// <summary> /// /// </summary> /// <param name="Yonghushouji">驗證碼的手機號</param> /// <returns></returns> public ActionResult Fayzm(string ...
#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