/// <summary> /// 获取验证码,有效时间10分钟 /// </summary> /// <returns></returns> public JsonResult VerCodeImg() { JsonResult <VerCodePicViewModel> result = new JsonResult <VerCodePicViewModel>(); result.code = 1; result.msg = "OK"; try { //生成随机的中文验证码 string yzm = "人口手大小多少上中下男女天地会反清复明杨中科小宝双儿命名空间语现在明天来多个的我山东河北南固安北京南昌东海西安是沙河高教园学" + "木禾上下土个八入大天人火文六七儿九无口日中了子门月不开四五目耳头米见白田电也长山出飞马鸟云公车牛羊小少巾牙尺毛又心手水广升足" + "走方半巴业本平书自已东西回片皮生里果几用鱼今正雨两瓜衣来年左右万百丁齐冬说友话春朋高你绿们花红草爷亲节的岁行古处声知多忙洗真认父扫" + "母爸写全完关家看笑着兴画会妈合奶放午收女气太早去亮和李语秀千香听远唱定连向以更后意主总先起干明赶净同专工才级队蚂蚁前房空网诗黄林闭" + "童立是我朵叶美机她过他时送让吗往吧得虫很河借姐呢呀哪谁凉怕量跟最园脸因阳为光可法石找办许别那到都吓叫再做象点像照沙海桥军竹苗井面乡" + "忘想念王这从进边道贝男原爱虾跑吹乐地老快师短淡对热冷情拉活把种给吃练学习非苦常问伴间共伙汽分要没孩位选北湖南秋江只帮星请雪就球跳玩" + "桃树刚兰座各带坐急名发成动晚新有么在变什条"; Random r = new Random(); string validCode = ""; for (int i = 0; i < 4; i++) { int number = r.Next(0, yzm.Length); validCode += yzm[number]; } VerCodePicViewModel vcvm = new VerCodePicViewModel(); string sourcePic = GetVerCodePicResource(); if (sourcePic.IsNull() || !System.IO.File.Exists(sourcePic)) { sourcePic = @"D:\zm\xunguang-4.jpg"; } VerCodePic codepic = GetVerCodePic(validCode, sourcePic); vcvm.content = validCode; vcvm.MainPic = codepic.PicURL; result.Result = vcvm; PublicConfig.SetCookie("ValidateCode", validCode, 0, 30, true); string token = codepic.Font1.X + "," + codepic.Font1.Y + "," + codepic.Font2.X + "," + codepic.Font2.Y + "," + codepic.Font3.X + "," + codepic.Font3.Y + "," + codepic.Font4.X + "," + codepic.Font4.Y; PublicConfig.SetCookie("__RequestNcoSig", token, 0, 30, true); Session["codepic"] = (codepic.Font1.X + "," + codepic.Font1.Y + "," + codepic.Font2.X + "," + codepic.Font2.Y + "," + codepic.Font3.X + "," + codepic.Font3.Y + "," + codepic.Font4.X + "," + codepic.Font4.Y); Session["fontSize"] = 20; result.ResultMsg = ""; } catch (Exception ex) { result.code = -1; result.msg = "AccountController.VerCodePic发生异常:" + ex.Message; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public async Task <IHttpActionResult> VerCodePic() { JsonResult <VerCodePicViewModel> result = new JsonResult <VerCodePicViewModel>(); result.code = 1; result.msg = "OK"; await Task.Run(() => { try { ClassLoger.Info("VerCodePic", "开始获取成语"); cy_dictBll cybll = new cy_dictBll(); IList <cy_dict> cylist = cybll.GetAllcy_dict(); ClassLoger.Info("VerCodePic", cylist.Count.ToString()); int i = Utils.GetRandom(0, cylist.Count - 1); ClassLoger.Info("VerCodePic", i.ToString()); cy_dict cy = cylist[i]; ClassLoger.Info("VerCodePic成语:", cy.chengyu); VerCodePicViewModel vcvm = new VerCodePicViewModel(); string sourcePic = FileHelper.GetVerCodePicResource(); if (sourcePic.IsNull() || !File.Exists(sourcePic)) { sourcePic = @"E:\WebResources\images\VerCodePicSource\1.jpg"; } ClassLoger.Info("VerCodePic图片", sourcePic); VerCodePic codepic = FileHelper.GetVerCodePic(cy.chengyu, sourcePic); vcvm.content = cy.chengyu; vcvm.MainPic = codepic.PicURL; result.Result = vcvm; string key = cookieKey(); RedisBase.Item_Set(key, codepic); RedisBase.ExpireEntryAt(key, DateTime.Now.AddMinutes(10)); result.ResultMsg = key; } catch (Exception ex) { ClassLoger.Error("AccountController.VerCodePic", ex); result.code = -1; result.msg = "AccountController.VerCodePic发生异常:" + ex.Message; } }); return(Ok(result)); }