$.ajax({
type: "get",
url: "http://www.it.com.cn/vip/Ajax/AjaxSeneNL.aspx?jsoncallback=?",
data: { mobile: phonenumber, code: checkcode, type: 2 },
contentType: "application/x-www-form-urlencoded;charset=utf-8",
dataType: "jsonp",
success: function (result) {
if (result && result.state == "0") {
alert(result.msg);
} else {
alert("验证码已发送!");
var countdown = 120;
var obj = setInterval(function () {
if (countdown > 0) {
countdown = countdown - 1;
$(".yanzheng").html(countdown + "秒后重新获取");
} else {
clearInterval(obj);
$(".yanzheng").html("获取验证码");
}
}, 1000);
}
},
error: function (e) {
alert("短信通道拥堵请稍后再试");
return false
}
})
MVC后台
public ActionResult GetCheckCode(string textPhone,string codestr,int? type)
{
Response.AddHeader("Access-Control-Allow-Origin", "*");
var callbackName=Request["jsoncallback"];
/*验证码加密*/
var codeMd5 =IM.Common.Security.Md5.EncryptMd5(codestr + "instrument_wqooisjc$3>");
/*获取验证加密cookie值*/
var getcode = Com.IM.Utils.CurrentCookie.GetCookieByKey("getcheck");
var json = new object(); ;
if (codeMd5 == getcode)
{
VIPGetTestCode TestGetCode = new VIPGetTestCode();
TestGetCode.CookieID = IM.WAP.Common.LoginCookie.GetCookie3I();
TestGetCode.mobile = textPhone;
TestGetCode.ip = IM.Common.IMRequest.GetIP();
TestGetCode.type = Convert.ToInt32(type);
var testcode = IM.WAP.VIP.BLL.VipLogon.SearchNes(TestGetCode);
//return Json(new { IsSuccess = testcode.Header.IsSuccess, msg = testcode.Header.Messages },JsonRequestBehavior.AllowGet);
json = new { IsSuccess = testcode.Header.IsSuccess, msg = testcode.Header.Messages };
}
else
{
//return Json(new { IsSuccess = false, msg = "校验码错误", val = "cookie中的MD5:" + getcode + ",校验码MD5:" + codeMd5 },JsonRequestBehavior.AllowGet);
json = new { IsSuccess = false, msg = "校验码错误" };
}
var jsonp = callbackName + "(" + IM.Common.JsonSerialize.SerializeObject(json) + ")";
HttpContext.Response.ContentType = "application/json";
HttpContext.Response.Write(jsonp);
return null;
}
参考网址:
http://kb.cnblogs.com/page/139725/
http://www.nowamagic.net/librarys/veda/detail/224