public ActionResult GetValidateCode() { string code = PropertyUtils.CreateValidateCode(5); Session["ValidateCode"] = code; byte[] bytes = this.CreateValidateGraphic(code); return(File(bytes, @"image/jpeg")); }
public JsonResult FileUpload() { //获取请求中所有的文件 foreach (var fileKey in Request.Files.AllKeys) { var file = Request.Files[fileKey]; try { if (file != null) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName); //文件保存 file.SaveAs(path); var thumpPath = Path.Combine(Server.MapPath("~/App_Data/uploads"), DateTime.Now.Millisecond + PropertyUtils.CreateValidateCode(4) + ".jpg"); PropertyUtils.getThumImage(path, 18, 3, thumpPath); } } catch { return(Json(new { Message = "文件上传失败" })); } } return(Json(new { Message = "文件上传成功" })); }
public JsonResult GetValidateCode(string phoneNum, int actionCode) { JsonModel jm = new JsonModel(); try { //如果是注册(设置手机号)操作获取验证码 if (actionCode == 0) { IUserBLL ownerBll = BLLFactory <IUserBLL> .GetBLL("UserBLL"); //如果手机号已存在 if (ownerBll.Exist(o => o.Phone == phoneNum && o.DelFlag == ConstantParam.DEL_FLAG_DEFAULT)) { jm.Msg = APIMessage.PHONE_EXIST; return(Json(jm, JsonRequestBehavior.AllowGet)); } } else if (actionCode == 1) { IUserBLL ownerBll = BLLFactory <IUserBLL> .GetBLL("UserBLL"); //如果手机号对应用户不存在 if (!ownerBll.Exist(o => o.Phone == phoneNum && o.DelFlag == ConstantParam.DEL_FLAG_DEFAULT)) { jm.Msg = APIMessage.PHONE_NO_EXIST; return(Json(jm, JsonRequestBehavior.AllowGet)); } } string code = PropertyUtils.CreateValidateCode(6); string msg = "感谢使用【Ai我家】微信公众号,验证码为:" + code + ",请在页面输入完成验证,如非本人操作请忽略"; //如果短信发送成功 if (PropertyUtils.SendSMS(phoneNum, msg, null)) { IPhoneValidateBLL phoneValidateBll = BLLFactory <IPhoneValidateBLL> .GetBLL("PhoneValidateBLL"); var phoneValidate = phoneValidateBll.GetEntity(v => v.PhoneNum == phoneNum && v.ActionCode == actionCode); //如果该手机号在相同操作中不存在 if (phoneValidate == null) { T_PhoneValidate v = new T_PhoneValidate() { PhoneNum = phoneNum, ValidateCode = code, InvalidTime = DateTime.Now.AddMinutes(Convert.ToInt32(PropertyUtils.GetConfigParamValue("ValidateCodeInvalid"))), ActionCode = actionCode }; phoneValidateBll.Save(v); } else { phoneValidate.ValidateCode = code; phoneValidate.InvalidTime = DateTime.Now.AddMinutes(Convert.ToInt32(PropertyUtils.GetConfigParamValue("ValidateCodeInvalid"))); phoneValidateBll.Update(phoneValidate); } } else { jm.Msg = APIMessage.VALDATE_GET_FAIL; } } catch { jm.Msg = APIMessage.REQUEST_EXCEPTION; } return(Json(jm, JsonRequestBehavior.AllowGet)); }