/// <summary> /// 设置验证码失效 /// </summary> /// <param name="mobile"></param> /// <param name="verifyCode"></param> /// <returns></returns> public static bool UpdateVerifyCodeInvalid(string mobile, string verifyCode) { using (var dal = FactoryDispatcher.SmsFactory()) { return(dal.UpdateVerifyCodeInvalid(verifyCode, mobile)); } }
/// <summary> /// 判断验证码是否有效 /// </summary> /// <param name="mobile"></param> /// <param name="verifyCode"></param> /// <returns></returns> public static bool IsPassVerify(string mobile, string verifyCode) { using (var dal = FactoryDispatcher.SmsFactory()) { return(dal.IsPassVerify(verifyCode, mobile)); } }
/// <summary> /// 发送短信 /// </summary> /// <param name="customerid"></param> /// <param name="type">1普通短信 2语音短信</param> /// <param name="mobile"></param> /// <param name="AppCode"></param> /// <returns></returns> public static bool SendSms(int type, string mobile, out ApiStatusCode AppCode) { int customerid = ConstConfig.storeId; try { using (var dal = FactoryDispatcher.SmsFactory()) { if (!dal.Sendable(mobile, customerid)) { LogHelper.Log("操作太频繁,请稍后再试!", LogHelperTag.INFO, WebConfig.debugMode()); AppCode = ApiStatusCode.INVALID_OPTION_CODE; return(false); } string verificationNum = StringHelper.GetRandomNumber(100000, 999999).ToString(); while (dal.Exists(verificationNum)) { verificationNum = StringHelper.GetRandomNumber(100000, 999999).ToString(); } using (TransactionScope scope = new TransactionScope()) { SwtSmsVerificationModel model = new SwtSmsVerificationModel(); model.SSV_Verification = verificationNum; model.SSV_AddTime = DateTime.Now; model.SSV_IsInvalid = 0; model.SSV_Phone = mobile; model.SSV_CustomerId = customerid; string content = string.Empty; string msg = ""; if (dal.Edit(model)) { if (type == 1) { content = string.Format("您的验证码为:{0} ,有效期10分钟,祝您生活愉快!", verificationNum); } else { content = string.Format("您的验证码是{0}", verificationNum); } if (send(type, mobile, content, out msg)) { AppCode = ApiStatusCode.OK; LogHelper.Log(content, LogHelperTag.INFO, WebConfig.debugMode()); scope.Complete(); return(true); } AppCode = ApiStatusCode.APP_SEND_CODE; LogHelper.Log(string.Format("mobile:{0}, content:{1}, result:{2}", mobile, verificationNum, "发送失败 " + msg), LogHelperTag.INFO, WebConfig.debugMode()); } else { AppCode = ApiStatusCode.APP_SEND_CODE; LogHelper.Log(string.Format("mobile:{0}, content:{1}, result:{2}", mobile, verificationNum, "发送失败"), LogHelperTag.INFO, WebConfig.debugMode()); return(false); } } } } catch (Exception ex) { AppCode = ApiStatusCode.APP_SEND_CODE; LogHelper.Log(string.Format("mobile:{0}, Message:{1}, StackTrace:{2}", mobile, ex.Message, ex.StackTrace), LogHelperTag.ERROR); } return(false); }