写了一个获取短信验证码功能模块,前面三条短信能正常接收,三条过后,每获取一次要等2-4小时,怎么回事?没遇到过这种情况啊!
下面贴代码:
#region 短信
public string SendSMS(string phoneNum, string msg)
{
string bs = "yj";
string url = "http//:www.xiaodingdang.com.cn";
Dictionary<string, string> param = new Dictionary<string, string>();
param.Add("bs", bs);
param.Add("phones", phoneNum);
param.Add("msg", msg);
var result = sendPost(url, param);
return result;
}
/// <summary>
/// 发送验证码
/// </summary>
/// <param name="phone"></param>
/// <returns></returns>
public JsonResult SendMsg(string phone)
{
string yidong = @"^1[0-9]{10}$";
Regex yReg = new Regex(yidong);
if (!yReg.IsMatch(phone))
{
return Json(new { code = -1, msg = "手机号码格式错误。", yzm = "" }, JsonRequestBehavior.AllowGet);
}
Random r = new Random(System.Environment.TickCount);
int i = r.Next(100000, 999999);
var reslut =SendSMS(phone, "【小叮当】验证码:" + i);
Vcode v = new Vcode();
v.phone =phone;
v.code = i.ToString();
v.expire = DateTime.Now.AddMinutes(10);
Session.Add("Vcode", v);
Log.Debug("Vcode", i.ToString());
return Json(new { code = 1, msg = reslut }, JsonRequestBehavior.AllowGet);
}
public int CheckVcode(string phone, string code)
{
Vcode v = Session["Vcode"] as Vcode;
if (v==null)
{
return -1;
}
DateTime now = DateTime.Now;
if (now<v.expire)
{
if (v.phone==phone&&v.code==code)
{
return 1;
}
}
return -1;
}
#endregion
2. $("#hqyzm").click(function () {
if ($("#hqyzm").hasClass("login_btn_act")) {
return;
}
var phone = $("#phone").val();
var reg = /^1[0-9]{10}$/; //验证规则
var flag = reg.test(phone); //true
if (!flag) {
$.alert("手机号格式错误");
return;
}
var tt = setInterval(function () {
$("#hqyzm").addClass("login_btn_act");
$("#hqyzm").html("已发送验证码(" + t + ")");
if (t == 0) {
t = 60;
$("#hqyzm").removeClass("login_btn_act");
$("#hqyzm").html("获取验证码");
clearInterval(tt);
}
t--;
}, 1000);
ActionResult({
action: 'SendMsg',
url: /WXTest/,
sync: false,
data: { phone:phone }
}, function (data, textStatus) {
// var Json = $.parseJSON(data);
var Json = data;
if (Json.code > 0) {
$.alert("已发送验证码,10分钟内有效。");
}
});
})