public ApiResult Put(string id, string verifyCode, string testMode, [FromBody] ZServerItem item) { // 关于验证类等事情 ApiResult result = CheckInfo(verifyCode, testMode, item); if (result.errorCode != 0) { return(result); } try { // 创建者ip地址 item.creatorIP = Request.HttpContext.Connection.RemoteIpAddress.ToString(); result.data = ServerInfo.Instance.UpdateZServerItem(item); } catch (Exception ex) { result.errorCode = -1; result.errorInfo = ex.Message; } return(result); }
public IActionResult BatchCreate() { string error = ""; string strCount = Request.Form["_count"]; strCount = strCount.Trim(); int count = 0; try { count = Convert.ToInt32(strCount); } catch (Exception ex) { error = "输入的数量必须是数值型:" + ex.Message; goto ERROR1; } if (count <= 0) { error = "输入的数据必须大于0"; goto ERROR1; } for (int i = 0; i < count; i++) { int no = i + 1; ZServerItem item = new ZServerItem() { name = "名称" + no.ToString(), addr = "地址" + no.ToString(), port = "210", homepage = "dp2003.com", authmethod = 0, dbnames = "cnmarc", creatorPhone = "138~", creatorIP = Request.HttpContext.Connection.RemoteIpAddress.ToString() }; ServerInfo.Instance.AddZServerItem(item); } ViewBag.info = "成功创建了" + count + "条站点信息"; return(View("Tool")); ERROR1: ViewBag.error = error; return(View("Tool")); }
public ApiResult Put(string id, string verifyCode, [FromBody] ZServerItem item) { ApiResult result = new ApiResult(); try { result.data = ServerInfo.Instance.UpdateZServerItem(item); } catch (Exception ex) { result.errorCode = -1; result.errorInfo = ex.Message; } return(result); }
public ApiResult Put(string id, [FromBody] ZServerItem item) { ApiResult result = new ApiResult(); try { item.creatorIP = Request.HttpContext.Connection.RemoteIpAddress.ToString(); item.createTime = DateTimeUtil.DateTimeToString(DateTime.Now); result.data = ServerInfo.ZServerDb.Update(item).Result; } catch (Exception ex) { result.errorCode = -1; result.errorInfo = ex.Message; } return(result); }
public ApiResult Post([FromBody] ZServerItem item) { ApiResult result = new ApiResult(); if (item == null) { result.errorCode = -1; result.errorInfo = "item对象为null"; } try { item.creatorIP = Request.HttpContext.Connection.RemoteIpAddress.ToString(); result.data = ServerInfo.ZServerDb.Add(item).Result; } catch (Exception ex) { result.errorCode = -1; result.errorInfo = ex.Message; } return(result); }
// 修改 public ZServerItem UpdateZServerItem(ZServerItem item) { return(this.ZServerDb.Update(item).Result); }
// 新增 public ZServerItem AddZServerItem(ZServerItem item) { return(this.ZServerDb.Add(item).Result); }
public ApiResult CheckInfo(string verifyCode, string testMode, [FromBody] ZServerItem item) { int nRet = 0; string error = ""; ApiResult result = new ApiResult(); if (item == null) { error = "item对象为null"; goto ERROR1; } // 只有公司的人才有审核权限 if (item.state != 0 && item.creatorPhone != "13862157150") { error = "您没有修改状态的权限,状态请设置为普通。"; goto ERROR1; } int nTestMode = 0; try { nTestMode = Convert.ToInt32(testMode); } catch (Exception ex) { error = ex.Message; goto ERROR1; } //============ // 验证码相关代码 if (verifyCode != "201807" && verifyCode != "201808") { string code = ""; // 获取session存储的验证码 if (HttpContext.Session == null) { error = "HttpContext.Session为null"; goto ERROR1; } code = HttpContext.Session.GetString(SessionKey_VerifyCode); bool bSend = false; if (String.IsNullOrEmpty(code) == true) { // 重发验证码 nRet = this.SendVerifyCode(item.creatorPhone, nTestMode, out code, out error); if (nRet == -1) { goto ERROR1; } bSend = true; } result.info = code; // 前端没有发来验证码的情况 if (string.IsNullOrEmpty(verifyCode) == true) { 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 { if (bSend == true) { error = "验证码无效,系统已重新给您手机号" + item.creatorPhone + "发送短信验证码,请输入新的验证码。"; //+ "code=" + code; 放在result了 goto ERROR1; } else { //传入的验证码与session中的验证码不一致 if (verifyCode != code) { error = "验证码不匹配,请重新输入手机短信中的验证码。"; //+ "code=" + code; 放在result了 goto ERROR1; } } } } return(result); ERROR1: result.errorCode = -1; result.errorInfo = error; return(result); }
public ApiResult Post(string verifyCode, [FromBody] ZServerItem item) { ApiResult result = new ApiResult(); if (item == null) { result.errorCode = -1; result.errorInfo = "item对象为null"; return(result); } //============ // 验证码相关代码 int nRet = 0; string error = ""; string code = ""; code = HttpContext.Session.GetString(SessionKey_VerifyCode); if (string.IsNullOrEmpty(verifyCode) == true) { string info = ""; // 检查session中是否已经存在验证码 // 如果不存在,发短信,且把验证码保存在session里 if (string.IsNullOrEmpty(code) == true) { nRet = this.SendVerifyCode(item.creatorPhone, out code, out error); if (nRet == -1) { result.errorCode = -1; result.errorInfo = error; return(result); } info = "验证码已发到手机" + item.creatorPhone + ",请输入短信验证码,重新提交。" + "code=" + code; } else { info = "请输入已经收到的手机短信验证,重新提交。" + "code=" + code; } result.errorCode = -2; result.errorInfo = "参数中缺少验证码。" + info; return(result); } if (String.IsNullOrEmpty(code) == true) { // 重发验证码 nRet = this.SendVerifyCode(item.creatorPhone, out code, out error); if (nRet == -1) { result.errorCode = -1; result.errorInfo = error; return(result); } result.errorCode = -1; result.errorInfo = "系统已给您手机号" + item.creatorPhone + "发送短信验证码,请输入验证码,重新提交。" + "code=" + code; return(result); } // 比如传入的验证码与session中的验证码是否一致 if (verifyCode != code) { result.errorCode = -1; result.errorInfo = "验证码不匹配,请重新输入手机短信中验证码。" + "code=" + code; return(result); } //=================== try { // 创建者ip地址 item.creatorIP = Request.HttpContext.Connection.RemoteIpAddress.ToString(); result.data = ServerInfo.Instance.AddZServerItem(item); } catch (Exception ex) { result.errorCode = -1; result.errorInfo = ex.Message; } return(result); }