Esempio n. 1
0
 private string CreateFileName(string fileName)
 {
     try
     {
         string timeStr       = DateTime.Now.ToString("yyyyMMddHHmmss");
         string guidInt       = GeneralCodeHelper.GuidTo16String();
         string fileExtension = System.IO.Path.GetExtension(fileName).ToLower();
         return(string.Format("{0}_{1}{2}", timeStr, guidInt, fileExtension));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Esempio n. 2
0
 private string CreateToken()
 {
     try
     {
         string strGuid   = GeneralCodeHelper.GetGuid(GeneralCodeHelper.GuIdFormat.N);
         string intGuid   = GeneralCodeHelper.GuidTo16String().PadLeft(16, '0');
         string randomStr = GeneralCodeHelper.RandomString(16);
         return(string.Format("{0}{1}{2}", strGuid, intGuid, randomStr));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Esempio n. 3
0
 public IActionResult Index()
 {
     try
     {
         string randomCode  = GeneralCodeHelper.GetRandomString(5);
         string encryptCode = DESEncryptHelper.EncryptDES(randomCode);
         WebHelper.WriteCookie("VerifyCode", encryptCode, 30);
         var imageByte = VerifyCodeHelper.Create(randomCode);
         return(File(imageByte, @"image/png"));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Esempio n. 4
0
 private string CreateToken(int getNum)
 {
     try
     {
         int    randomLength = 47 - getNum.ToString().Length;
         string strGuid      = GeneralCodeHelper.GetGuid(GeneralCodeHelper.GuIdFormat.N);
         string intGuid      = GeneralCodeHelper.GuidTo16String().PadLeft(16, '0');
         string aRandomStr   = GeneralCodeHelper.RandomString(randomLength, true, true, true, true);
         string bRandomStr   = GeneralCodeHelper.RandomString(32, true, true, true, true);
         return(string.Format("{0}_{1}{2}{3}{4}", getNum, aRandomStr, strGuid, intGuid, bRandomStr));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Esempio n. 5
0
        public IActionResult SaveImageCode(string access_token)
        {
            try
            {
                int systemId = SystemID;
                if (!IsAccessToken(access_token))
                {
                    return(Error("验证token失败!"));
                }
                var entity = AccountService.GetAccountByAccessTokenPro(systemId, access_token);
                if (entity == null)
                {
                    return(Error("验证会员资料失败!"));
                }
                if (string.IsNullOrEmpty(entity.CompanyID))
                {
                    return(Error("验证会员资料失败!"));
                }
                string companyId = entity.CompanyID;
                string memberId  = entity.MemberID;

                string base64String = Accessor.HttpContext.Request.GetInputStream();
                string imageCode    = ImageHelper.GetImageCode(base64String);
                long   fileSize     = imageCode.Length;
                string fileName     = string.Format("{0}.{1}", GeneralCodeHelper.GetRandomInt(8), ImageHelper.GetImageExtension(base64String));
                string uploadPath   = CreateUploadPath(systemId, companyId, fileName);
                string newFileName  = CreateFileName(fileName);
                var    filePath     = string.Format("{0}\\{1}", uploadPath, newFileName);
                string src          = ToRelativePath(filePath);
                string url          = ToAbsoluteUri(filePath);
                string mediaId      = PrimaryKeyHelper.MakePrimaryKey(PrimaryKeyHelper.PrimaryKeyType.BasicsMedia);
                var    media        = new Ld_Basics_Media()
                {
                    SystemID      = systemId,
                    CompanyID     = companyId,
                    MediaID       = mediaId,
                    FileName      = fileName,
                    FileExtension = Path.GetExtension(fileName).ToLower(),
                    FileSize      = fileSize,
                    Url           = url,
                    Src           = src,
                };
                var data = new { mediaid = mediaId, name = fileName, size = fileSize, url, src };
                if (fileSize > 0)
                {
                    string savePath = ImageHelper.Base64StringToImage(filePath, base64String);
                }
                int result = MediaService.SaveMediaMember(memberId, media);
                if (result > 0)
                {
                    return(Success("ok", new { count = 1, size = fileSize, file = data }));
                }
                else
                {
                    return(Error("upload fail!"));
                }
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }