public async Task <bool> AddSms(SMS sms) { lock (dbLock) { using (CnContextMock context = new CnContextMock()) { context.SMS.Add(sms); Package package = GetPackageByLineId(sms.LineID); PackageDetails packDet = GetPackageDetailsByPackageId(package.ID); packDet.UsedSMS++; UpdateDBPackageDetails(packDet); context.SaveChanges(); } } SMS.Add(sms); return(true); }
private void GetMailCode(string strMailType) { string randomNumber = StringUtils.GetRandomNumber(5, true); string text = string.Empty; string strSubject = string.Empty; if (strMailType == "reg") { strSubject = "注册验证码"; text = base.GetConfigValue("RegMailCheckCode").Replace("${checkcode}", randomNumber); } else if (strMailType == "findpwd") { strSubject = "找回密码验证码"; text = base.GetConfigValue("GetPwdMailCheckCode").Replace("${username}", WebUtils.GetQueryString("username")).Replace("${checkcode}", randomNumber); } else if (strMailType == "bind") { strSubject = "会员绑定验证码"; text = base.GetConfigValue("BindMailCheckCode").Replace("${username}", WebUtils.GetQueryString("username")).Replace("${checkcode}", randomNumber); } string queryString = WebUtils.GetQueryString("paramval"); string s = "{\"ret\":\"fail\",\"timeout\":0,\"msg\":\"邮箱验证码发送失败\"}"; bool flag = true; if (!string.IsNullOrEmpty(queryString)) { if ((strMailType == "reg" || strMailType == "bind") && SinGooCMS.BLL.User.IsExistsByEmail(queryString)) { s = "{\"ret\":\"exists\",\"timeout\":0,\"msg\":\"邮箱地址已存在\"}"; } else { SMSInfo lastCheckCode = SMS.GetLastCheckCode(queryString); if (lastCheckCode != null) { System.TimeSpan timeSpan = System.DateTime.Now - lastCheckCode.AutoTimeStamp; if (timeSpan.TotalSeconds < 60.0) { flag = false; s = "{\"ret\":\"fail\",\"timeout\":" + (60.0 - timeSpan.TotalSeconds).ToString("f0") + ",\"msg\":\"发送间隔太短\"}"; } } if (flag) { string empty = string.Empty; if (MsgService.SendMail(queryString, strSubject, text, out empty)) { SMSInfo entity = new SMSInfo { SMSMob = queryString, SMSText = text, SMSType = "CheckCode", ValidateCode = randomNumber, ReturnMsg = empty, Status = 1, AutoTimeStamp = System.DateTime.Now }; SMS.Add(entity); s = "{\"ret\":\"success\",\"timeout\":60,\"msg\":\"邮箱验证码发送成功,请登录邮箱查收!\"}"; } else { s = "{\"ret\":\"fail\",\"timeout\":0,\"msg\":\"" + empty + "\"}"; } } } } base.Response.Write(s); }