Skip to content

Commit

Permalink
验证码设了两个固定值;
Browse files Browse the repository at this point in the history
另外前端也可以设为测试模式,不实际发短信,返回验证码
  • Loading branch information
renyh committed Jul 9, 2018
1 parent 0e88d7a commit 8459926
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 61 deletions.
3 changes: 3 additions & 0 deletions WebZ.Server/ApiResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ public class ApiResult

// 返回的数据对象
public object data = "";

// 其它信息,例如提交站点信息的短信验证码
public object info = "";
}
}
135 changes: 79 additions & 56 deletions WebZ/ApiControllers/ZSerItemController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public ApiResult Get(string id)
public static TimeSpan TempCodeExpireLength = TimeSpan.FromHours(48); // TimeSpan.FromMinutes(10); // 10 分钟

public int SendVerifyCode(string phone,
int testMode,
out string code,
out string error)
{
Expand Down Expand Up @@ -104,17 +105,21 @@ public int SendVerifyCode(string phone,
}
HttpContext.Session.SetString(SessionKey_VerifyCode, code);

// 发短信 todo
try
// 非测试模式,才发短信
if (testMode ==0)
{
int nRet = ServerInfo.Instance.SendVerifyCodeSMS(phone, code, out error);
if (nRet == -1)
// 发短信 todo
try
{
int nRet = ServerInfo.Instance.SendVerifyCodeSMS(phone, code, out error);
if (nRet == -1)
return -1;
}
catch (Exception ex)
{
error = "发送短信验证码出错:" + ex.Message;
return -1;
}
catch (Exception ex)
{
error = "发送短信验证码出错:"+ex.Message;
return -1;
}
}

return 0;
Expand All @@ -124,7 +129,9 @@ public int SendVerifyCode(string phone,

// POST api/<controller>
[HttpPost]
public ApiResult Post(string verifyCode,[FromBody]ZServerItem item)
public ApiResult Post(string verifyCode,
string testMode,
[FromBody]ZServerItem item)
{
int nRet = 0;
string error = "";
Expand All @@ -136,73 +143,89 @@ public ApiResult Post(string verifyCode,[FromBody]ZServerItem item)
goto ERROR1;
}

//============
// 验证码相关代码

string code = "";

// 获取session存储的验证码
if (HttpContext.Session == null)
int nTestMode = 0;
try
{
error = "HttpContext.Session为null";
goto ERROR1;
nTestMode = Convert.ToInt32(testMode);
}
code = HttpContext.Session.GetString(SessionKey_VerifyCode);
bool bSend = false;
if (String.IsNullOrEmpty(code) == true)
catch (Exception ex)
{
// 重发验证码
nRet = this.SendVerifyCode(item.creatorPhone,
out code,
out error);
if (nRet == -1)
{
goto ERROR1;
}
bSend = true;
error = ex.Message;
goto ERROR1;
}

// 前端没有发来验证码的情况
if (string.IsNullOrEmpty(verifyCode) == true)


//============
// 验证码相关代码
if (verifyCode != "201807" && verifyCode != "201808")
{
string info = "";
if (bSend == true)
string code = "";

// 获取session存储的验证码
if (HttpContext.Session == null)
{
info = "验证码已发到手机" + item.creatorPhone + ",请输入短信验证码,重新提交。"
+ "code=" + code;
error = "HttpContext.Session为null";
goto ERROR1;
}
else
code = HttpContext.Session.GetString(SessionKey_VerifyCode);
bool bSend = false;
if (String.IsNullOrEmpty(code) == true)
{
info = "请输入已经收到的手机短信验证,重新提交。"
+ "code=" + code;
// 重发验证码
nRet = this.SendVerifyCode(item.creatorPhone,
nTestMode,
out code,
out error);
if (nRet == -1)
{
goto ERROR1;
}
bSend = true;
}

// errorCode返回-2
result.errorCode = -2;
result.errorInfo = "参数中缺少验证码。" + info;
return result;
}
else
{
if (bSend == true)
result.info = code;

// 前端没有发来验证码的情况
if (string.IsNullOrEmpty(verifyCode) == true)
{
error = "验证码无效,系统已给您手机号" + item.creatorPhone + "发送短信验证码,请重新输入验证码。"
+ "code=" + code;
goto ERROR1;
if (bSend == true)
{
error = "验证码已发到手机" + item.creatorPhone + ",请输入短信验证码。";
//+ "code=" + code; 放在result了
}
else
{
error = "请输入已经收到的手机短信验证码。";
//+ "code=" + code; 放在result了
}

// errorCode返回-2
result.errorCode = -2;
result.errorInfo = error;
return result;
}
else
{
//传入的验证码与session中的验证码不一致
if (verifyCode != code)
if (bSend == true)
{
error = "验证码不匹配,请重新输入手机短信中验证码。"
+ "code=" + code;
error = "验证码无效,系统已重新给您手机号" + item.creatorPhone + "发送短信验证码,请输入新的验证码。";
//+ "code=" + code; 放在result了
goto ERROR1;
}
else
{
//传入的验证码与session中的验证码不一致
if (verifyCode != code)
{
error = "验证码不匹配,请重新输入手机短信中的验证码。";
//+ "code=" + code; 放在result了
goto ERROR1;
}
}
}
}


// 保存站点信息
try
{
Expand Down
23 changes: 18 additions & 5 deletions WebZ/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@
// return;
//}
var testMode = getCheckboxValue("_test");//$(divId).find("#_firstfull").val();
//alert(firstfull);
var subjects = ""; //这里以逗号分隔
Expand All @@ -518,11 +521,11 @@
var action = "";
if (msgId == "new") {
action = "POST";
url += "?verifyCode=" + encodeURIComponent(verifyCode); //url也加一截
url += "?verifyCode=" + encodeURIComponent(verifyCode) + "&testMode=" + testMode; //url也加一截
}
else {
action = "PUT";
url += "/" + id + "?verifyCode=" + encodeURIComponent(verifyCode); //url也加一截
url += "/" + id + "?verifyCode=" + encodeURIComponent(verifyCode) + "&testMode=" + testMode; //url也加一截
}
//alert(recsperbatch);
Expand All @@ -533,8 +536,14 @@
// 关闭等待层
hideMaskLayer();
// 改为直接显示了
//if (result.errorCode == -2) {
// $("#_codeDiv").css("display", "block");
//}
if (result.errorCode <= -1) {
alert("操作失败:" + result.errorInfo);
alert("操作失败:" + result.errorInfo
+ "\r\n验证码为" + result.info);
return;
}
Expand Down Expand Up @@ -918,10 +927,14 @@
<input type='text' placeholder='phone' id='_creatorPhone' value='" + creatorPhone + "'>\
</div>\
</div>\
<div class='required inline field '>\
<label>输入验证码&nbsp;&nbsp;&nbsp;&nbsp;</label>\
<div class='inline field ' id='_codeDiv' style='font-size:20px'>\
<label>短信验证码(不清楚可不填)</label>\
<input type='text' id='_verifyCode'>\
</div>\
<div class='ui checkbox field'>\
<input type='checkbox' id='_test' checked>\
<label>测试模块,不实际发短信</label>\
</div>\
</div>\
<div onclick='expandToggle(this)'><span id='_advanceCtrl'>+</span> 高级选项<br/></div> \
<div id='_advance' style='display:none'>\
Expand Down

0 comments on commit 8459926

Please sign in to comment.