Beispiel #1
0
        private static string GenerateCode(string platform, string business, string uniqueKey, object extensions)
        {
            string codeKey         = $"{platform}:APP:SMSVerification:{business}:{uniqueKey}";
            string codeCacheString = RedisHelper.StringGet(Constant.REDIS_SMS_DBINDEX, codeKey);
            string code;

            if (!string.IsNullOrEmpty(codeCacheString))
            {
                CodeExtension <object> ext = JsonConvert.DeserializeObject <CodeExtension <object> >(codeCacheString);
                code = ext?.Code ?? RandomAlphaNumericGenerator.GenerateAllNumber(6);
            }
            else
            {
                code = RandomAlphaNumericGenerator.GenerateAllNumber(6);
            }

            CodeExtension <object> codeCache = new CodeExtension <object>
            {
                Code      = code,
                Extension = extensions
            };

            RedisHelper.Set(codeKey, codeCache, TimeSpan.FromMinutes(Constant.SMS_EXPIRED_TIME));
            return(code);
        }
        /// <summary>
        /// 发送原邮箱验证码 20180523
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="emailAddress"></param>
        public async Task SendVerifyOriginalEmail(Guid accountId, string emailAddress)
        {
            var dac     = new MerchantAccountDAC();
            var account = dac.GetById(accountId);

            var accountByEmail = dac.GetByEmail(emailAddress);

            if (accountByEmail != null && accountByEmail.Id != accountId)
            {
                throw new CommonException(ReasonCode.FiiiPosReasonCode.EMAIL_BINDED, "该邮箱已绑定到其他账户");
            }

            string key  = $"{RedisKeys.FiiiPOS_WEB_EmailVerification}:{accountId}";
            string code = RandomAlphaNumericGenerator.GenerateAllNumber(6);

            Dictionary <string, string> dic = new Dictionary <string, string>
            {
                { "AccountId", accountId.ToString() },
                { "EmailAddress", emailAddress },
                { "Code", code }
            };

            RedisHelper.Set(key, dic, new TimeSpan(0, Constant.EMAIL_EXPIRED_TIME, 0));

            string subject = Resources.验证码邮箱标题;
            string content = string.Format(Resources.验证码邮箱模版, code, Constant.EMAIL_EXPIRED_TIME);

            EmailAgent agent = new EmailAgent();
            await agent.SendAsync(emailAddress, subject, content, 5);
        }