示例#1
0
 public QRCodeConfig(QRCodeContent content)
 {
     background_color = content.BackColor;
     code_scale       = content.scale;
     code_version     = content.version;
     EncodeMode       = content.encode_mode;
     EncodingString   = content.encoding;
     ErrorCorrection  = content.checksum;
     fore_color       = content.ForeColor;
     logo             = content.logo;
     if (logo == null && !content.logo_base64.isNull())
     {
         logo = ImageUtil.fromBase64(content.logo_base64);
     }
     if (logo == null && !content.logo_url.isNull())
     {
         //为了支持旧版, 可以将url中放入base64结构的内容
         if (content.logo_url.StartsWith("[base64]"))
         {
             logo = ImageUtil.fromBase64(content.logo_url.Substring(8));
         }
         else
         {
             logo = ImageUtil.fromUrl(content.logo_url);
         }
     }
     logo_height = content.logo_height;
     logo_width  = content.logo_width;
 }
示例#2
0
        public async Task <TokenVm> CreateTokenByQRCodeAsync(QRCodeContent qRCodeContent,
                                                             string deviceTokenId = null,
                                                             string osName        = null,
                                                             string deviceName    = null,
                                                             string appName       = null)
        {
            byte[] sequenceHash = GetSequenceHashSha512(qRCodeContent.Sequence);
            using (MessengerDbContext context = contextFactory.Create())
            {
                var qrCode = await context.QRCodes
                             .FirstOrDefaultAsync(qr => qr.UserId == qRCodeContent.UserId && qr.SequenceHash.SequenceEqual(sequenceHash))
                             .ConfigureAwait(false);

                if (qrCode == null)
                {
                    throw new ObjectDoesNotExistsException("QR-code with the data was not found.");
                }

                Token token = new Token
                {
                    AccessToken  = RandomExtensions.NextString(64),
                    RefreshToken = RandomExtensions.NextString(64),
                    AccessTokenExpirationTime  = DateTime.UtcNow.AddHours(TokensService.ACCESS_LIFETIME_HOUR).ToUnixTime(),
                    RefreshTokenExpirationTime = DateTime.UtcNow.AddHours(TokensService.REFRESH_LIFETIME_HOUR).ToUnixTime(),
                    AppName       = appName,
                    DeviceName    = deviceName,
                    OSName        = osName,
                    DeviceTokenId = deviceTokenId,
                    UserId        = qRCodeContent.UserId
                };
                await context.Tokens.AddAsync(token).ConfigureAwait(false);

                context.QRCodes.Remove(qrCode);
                await context.SaveChangesAsync().ConfigureAwait(false);

                return(TokenConverter.GetTokenVm(token));
            }
        }
示例#3
0
 public static Image getQRCode(QRCodeContent content)
 {
     return getQRCode(content.content, new QRCodeConfig(content));
 }