/// <summary>
        /// 设置缓存
        /// </summary>
        /// <param name="user_account"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private static ReturnResult SendVerifyCodeToEmail(UserAccount account)
        {
            var vCode = new Random().Next(100000, 999999).ToString();

            MeCache <string> .AddOrUpdate(string.Format(MeCacheKey.EmailVerifyCode, account), vCode, DateTime.Now.AddMinutes(5));

            Vsan.Common.EmailHelper.SendMailb("*****@*****.**", "邮箱验证码", "gzxixoaaerawbgfj", account.Account, "你的邮箱验证码为:【" + vCode + "】 5分钟内有效.", vCode, "smtp.qq.com", false);

            return(new ReturnResult(0, "验证码已发送至你的邮箱,请查收"));
        }
        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <param name="user_account"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private static UserInfo SetCache(user_account user_account, string token)
        {
            var userInfo = new UserInfo
            {
                Id   = user_account.Id,
                Logo = user_account.HeadPortrait,
                Name = user_account.Nickname,
            };

            MeCache <UserInfo> .AddOrUpdate(token, userInfo, DateTime.Now.AddDays(7));

            return(userInfo);
        }
Beispiel #3
0
        /// <summary>
        /// 发送邮箱验证码
        /// </summary>
        /// <param name="user_account"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private static ReturnResult SendVerifyCodeToEmail(UserAccount account, string functionName = "")
        {
            try
            {
                var key  = string.Format(MeCacheKey.EmailVerifyCode, account.Account) + functionName;
                var data = MeCache <string> .Get(key);

                if (string.IsNullOrWhiteSpace(data))
                {
                    var vCode = new Random().Next(100000, 999999).ToString();

                    var param = new Dictionary <string, string> {
                        { "Recipient", account.Account },
                        { "Content", "<p>您" + functionName + "的邮箱验证码为:<h1 style=\"color:red;\">" + vCode + "</h1></p>" },
                        { "CName", "【工务园系统】" }
                    };

                    using (var http = new HttpClient())
                    {
                        var response = http.PostAsJsonAsync("http://111.231.116.56:8080/api/email/send", param).Result;
                        if (!response.IsSuccessStatusCode)
                        {
                            var content = "无内容";
                            try
                            {
                                content = response.Content.ReadAsStringAsync().Result;
                            }
                            catch (Exception)
                            {
                            }
                            return(new ReturnResult(0, $"邮件发送服务异常. (错误代码:{response.StatusCode},响应内容:{content})"));
                        }
                    }
                    //Vsan.Common.EmailHelper.SendMailb("*****@*****.**", "邮箱验证码", "gzxixoaaerawbgfj", account.Account, "你的邮箱验证码为:【" + vCode + "】 5分钟内有效.", vCode, "smtp.qq.com", false);
                    MeCache <string> .AddOrUpdate(key, vCode, DateTime.Now.AddMinutes(5));
                }
                return(new ReturnResult(0, "验证码已发送至你的邮箱,请查收"));
            }
            catch (Exception ex)
            {
                return(new ReturnResult(2, ex.Message + ex.InnerException?.Message + ex.InnerException?.InnerException?.Message));
            }
        }