/// <summary> /// 验证验证码 10分钟有效 /// </summary> /// <param name="Row"></param> /// Mobile 手机号【必填】 /// VerifyCode 验证码【必填】 /// 返回: /// true:验证成功 /// false:错误信息 /// <returns></returns> private string CheckVerifyCode(DataRow Row) { if (Row["Mobile"] == null || Row["Mobile"].ToString() == "") { return(JSONHelper.FromString(false, "缺少参数Mobile")); } if (Row["VerifyCode"] == null || Row["VerifyCode"].ToString() == "") { return(JSONHelper.FromString(false, "缺少参数VerifyCode")); } string conStr = PubConstant.UnifiedContionString.ToString(); IDbConnection con = new SqlConnection(conStr); string sql = "select * from Tb_SendMessageRecord where Mobile=@Mobile and SendContent='您的验证码为:'+@SendContent+'【天问互联】' and SendType='忘记密码' and SendState=0 and DATEDIFF(mi,SendTime,GETDATE())<10"; Tb_SendMessageRecord model = con.Query <Tb_SendMessageRecord>(sql, new { Mobile = Row["Mobile"].ToString(), SendContent = Row["VerifyCode"] }).ToList <Tb_SendMessageRecord>().SingleOrDefault(); if (model == null) { return(JSONHelper.FromString(false, "验证失败")); } else { return(JSONHelper.FromString(true, "验证成功")); } }
/// <summary> /// 新增短信记录 /// </summary> /// <param name="Mobile">手机号</param> /// <param name="SendContent">内容</param> /// <param name="MacCode">MacCode</param> /// <param name="SendType">短信类型</param> /// <param name="SendState">发送状态</param> public Tb_SendMessageRecord Add(string Mobile, string SendContent, string MacCode, string SendType, string SendState) { MobileSoft.Model.Common.Tb_SendMessageRecord model = new Tb_SendMessageRecord(); model.Id = Guid.NewGuid().ToString(); model.Mobile = Mobile; model.SendContent = SendContent; model.MacCode = MacCode; model.SendTime = DateTime.Now; model.SendType = SendType; model.SendState = SendState; Add(model); return(model); }
private void SendMessage(int corpId, string mobile, string message) { int code = new Random(unchecked ((int)DateTime.Now.Ticks)).Next(100000, 999999); Tb_Sms_Account smsModel = SmsInfo.GetSms_Account(); Tb_SendMessageRecord m = new Tb_SendMessageRecord(); message = message + smsModel.Sign; //发送短信 //int Result = Common.Sms.Send(smsModel.SmsAccount, smsModel.SmsPwd, mobile, message, "", ""); int Result = Common.Sms.Send_v2(smsModel.SmsUserId, smsModel.SmsAccount, smsModel.SmsPwd, mobile, message, out string strErrMsg); string Resul = ""; switch (Result) { case 0: Resul = "发送成功"; try { //记录短信 m = new Bll_Tb_SendMessageRecord().Add(mobile, message, Guid.NewGuid().ToString(), "泰禾业主App邀请用户", ""); } catch (Exception) { } break; case -4: Resul = "手机号码格式不正确"; break; default: Resul = "发送失败:" + Result; break; } //修改状态 m.SendState = Result.ToString(); //重写短信记录状态 new Bll_Tb_SendMessageRecord().Update(m); }
/// <summary> /// 获取验证码 /// </summary> /// <param name="Row"></param> /// <returns></returns> private string GetVerifyCode(DataRow Row, Common.Transfer Trans) { if (Row.Table.Columns.Contains("Mobile") && !String.IsNullOrEmpty(Row["Mobile"].ToString())) { if (Row.Table.Columns.Contains("VerifyCode") && !String.IsNullOrEmpty(Row["VerifyCode"].ToString())) { // 鸿坤 单独写接口 //// 查询该手机号是否已经注册 //using (var conn = new SqlConnection(PubConstant.UnifiedContionString)) //{ // if (conn.Query(@"SELECT * FROM Tb_User WHERE Mobile=@Mobile", new { Mobile = Row["Mobile"].ToString() }).Count() > 0) // { // return JSONHelper.FromString(false, @"该手机号已注册"); // } //} //解密验证码 int code = AppGlobal.StrToInt(RSAHelper.getInstance().Decrypt(Row["VerifyCode"].ToString())); //新增4位验证码 if (code > 0 && (code.ToString().Length == 6 || code.ToString().Length == 4))//六位字验证 { //MAC验证 DataSet ds = new Bll_Tb_SendMessageRecord().GetList(" MacCode='" + Trans.Mac + "' "); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { return(JSONHelper.FromString(false, "无效操作")); } Tb_Sms_Account smsModel = SmsInfo.GetSms_Account(); string Content = "您的验证码为:" + code + "" + smsModel.Sign; Tb_SendMessageRecord m = new Tb_SendMessageRecord(); try { //记录短信 m = new Bll_Tb_SendMessageRecord().Add(Row["Mobile"].ToString(), Content, Trans.Mac, "天问验证码", ""); } catch (Exception ex) { return(JSONHelper.FromString(false, "无效操作")); } //发送短信 //int Result = Common.Sms.Send(smsModel.SmsAccount, smsModel.SmsPwd, Row["Mobile"].ToString(), Content, "", ""); int Result = Common.Sms.Send_v2(smsModel.SmsUserId, smsModel.SmsAccount, smsModel.SmsPwd, Row["Mobile"].ToString(), Content, out string strErrMsg); string Resul = ""; switch (Result) { case 0: Resul = "发送成功"; break; case -4: Resul = "手机号码格式不正确"; break; default: Resul = "发送失败:" + Result; break; } //修改状态 m.SendState = Result.ToString(); //重写短信记录状态 new Bll_Tb_SendMessageRecord().Update(m); if (Result == 0) { return(JSONHelper.FromString(true, Resul)); } else { return(JSONHelper.FromString(false, strErrMsg)); } } else { //new Bll_Tb_SendMessageRecord().Add(Row["Mobile"].ToString(), "", "", "天问验证码", ""); return(JSONHelper.FromString(false, "参数VerifyCode格式错误")); } } else { //new Bll_Tb_SendMessageRecord().Add(Row["Mobile"].ToString(), "", "", "天问验证码", ""); return(JSONHelper.FromString(false, "缺少参数VerifyCode")); } } else { return(JSONHelper.FromString(false, "缺少参数Mobile")); } }
/// <summary> /// 获取验证码 /// </summary> private string GetVerifyCode(DataRow Row, Common.Transfer Trans) { if (!Row.Table.Columns.Contains("Mobile") || string.IsNullOrEmpty(Row["Mobile"].ToString())) { return(JSONHelper.FromString(false, "缺少Mobile参数")); } string forgetPassword = null; // 忘记密码功能时传入该参数 if (Row.Table.Columns.Contains("IsForget") && !string.IsNullOrEmpty(Row["IsForget"].ToString())) { forgetPassword = Row["IsForget"].ToString(); } int code = new Random(unchecked ((int)DateTime.Now.Ticks)).Next(100000, 999999); string Content = "您的验证码为:" + code; if (forgetPassword != "1") { DataTable dTable = new DbHelperSQLP(PubConstant.UnifiedContionString.ToString()).Query("SELECT Name FROM Tb_User where Mobile='" + Row["Mobile"].ToString() + "'").Tables[0]; if (dTable.Rows.Count > 0) { return(JSONHelper.FromString(false, "此用户已存在")); } try { if (HttpContext.Current.Request.Url.Host.Contains("tahoecn")) { // 泰禾版本 string connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=10.0.102.32;initial catalog=HM_wygl_new_1970;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096"; if (HttpContext.Current.Request.Url.Host.ToLower() == "test.wyerp.tahoecndemo.com") { connString = @"Connect Timeout=100;Connection Lifetime=60;Max Pool Size=2000;Min Pool Size=0;Pooling=true;data source=(local);initial catalog=HM_wygl_new_1970;PWD=LF123SPoss;persist security info=False;user id=LFUser;packet size=4096"; } // 泰禾在此时需要验证是否是业主身份 using (IDbConnection conn = new SqlConnection(connString)) { string sql = @"SELECT * FROM Tb_HSPR_Customer x WHERE isnull(x.IsDelete,0)=0 AND x.LiveType1=1 AND x.MobilePhone LIKE @MobilePhone; SELECT * FROM Tb_HSPR_Customer x WHERE isnull(x.IsDelete,0)=0 AND x.LiveType2=2 AND x.MobilePhone LIKE @MobilePhone; SELECT * FROM Tb_HSPR_Household x WHERE isnull(x.IsDelete,0)=0 AND x.MobilePhone LIKE @MobilePhone; SELECT * FROM Tb_HSPR_Customer x WHERE isnull(x.IsDelete,0)=0 AND x.LiveType1=1 AND x.MobilePhone LIKE @MobilePhone AND (SELECT count(0) FROM Tb_HSPR_CustomerLive y WHERE x.CustID=y.CustID AND isnull(y.IsDelLive,0)=0 AND y.LiveType=1 AND CommID IN(SELECT CommID FROM Unified.dbo.Tb_Community))>0; SELECT * FROM Tb_HSPR_Customer x WHERE isnull(x.IsDelete,0)=0 AND x.LiveType2=2 AND x.MobilePhone LIKE @MobilePhone AND (SELECT count(0) FROM Tb_HSPR_CustomerLive y WHERE x.CustID=y.CustID AND isnull(y.IsDelLive,0)=0 AND y.LiveType=2 AND CommID IN(SELECT CommID FROM Unified.dbo.Tb_Community))>0; SELECT * FROM Tb_HSPR_Household x WHERE isnull(x.IsDelete,0)=0 AND x.MobilePhone LIKE @MobilePhone AND (SELECT count(0) FROM Tb_HSPR_CustomerLive y WHERE x.CustID=y.CustID AND isnull(y.IsDelLive,0)=0 AND y.LiveType=1 AND CommID IN(SELECT CommID FROM Unified.dbo.Tb_Community))>0;"; GridReader reader = conn.QueryMultiple(sql, new { MobilePhone = $"%{Row["Mobile"].ToString()}%" }); int[] counts = new int[] { reader.Read().Count(), reader.Read().Count(), reader.Read().Count(), reader.Read().Count(), reader.Read().Count(), reader.Read().Count() }; if (counts[0] + counts[1] + counts[2] + counts[3] + counts[4] + counts[5] == 0) { return(JSONHelper.FromString(false, "手机号未登记,请联系物管")); } if (counts[0] + counts[1] + counts[2] != 0 && counts[3] + counts[4] + counts[5] == 0) { return(JSONHelper.FromString(false, "此园区暂未开通,敬请期待")); } } } } catch { return(JSONHelper.FromString(false, "获取验证码失败")); } } Tb_Sms_Account smsModel = SmsInfo.GetSms_Account(); Tb_SendMessageRecord m = new Tb_SendMessageRecord(); string errorMessage = ""; int Result = 0; // 泰禾 try { if (HttpContext.Current.Request.Url.Host.ToLower().Contains("tahoecn")) { Result = SendShortMessage(Row["Mobile"].ToString(), Content, out errorMessage, 1970); } else { Result = SendShortMessage(Row["Mobile"].ToString(), Content, out errorMessage); } } catch (Exception ex) { GetLog().Info("验证码发送失败:" + ex.Message + ex.StackTrace); return(JSONHelper.FromString(false, "发送失败,请稍后重试")); } if (Result == 0) { return(JSONHelper.FromString(true, (code * 369).ToString())); } else { return(JSONHelper.FromString(false, errorMessage)); } }