Пример #1
0
        public int DetectAuthenticInfo(AuthUser operatorUser, int userID, out List <string> photos)
        {
            photos = null;

            if (operatorUser.UserID <= 0)
            {
                ThrowError(new NotLoginError());
                return(4);
            }

            if (!CanRealnameCheck(operatorUser))
            {
                ThrowError(new NoPermissionRealnameCheckError());
                return(4);
            }

            AuthenticUser userInfo = GetAuthenticUserInfo(operatorUser, userID);

            if (userInfo == null)
            {
                ThrowError(new CustomError("没有该用户提交的实名认证材料"));
                return(4);
            }
            List <byte[]> photoData;
            int           state = DetectAuthenticInfo(userInfo.Realname, userInfo.IDNumber, out photoData);

            if (state == 0)
            {
                photos = new List <string>();
                if (photoData != null)
                {
                    string photoString = "";
                    string temp;
                    string photoDirName = "Photos";
                    string photoPath    = Globals.GetPath(SystemDirecotry.Upload_IDCard, photoDirName);
                    string virtualPath  = Globals.GetVirtualPath(SystemDirecotry.Upload_IDCard, photoDirName);

                    if (!Directory.Exists(photoPath))
                    {
                        Directory.CreateDirectory(photoPath);
                    }

                    for (int i = 0; i < photoData.Count; i++)
                    {
                        string fileName = string.Format("{0}_{1}.jpg", userInfo.IDNumber, i);

                        if (photoString.Length > 0)
                        {
                            photoString += "|";
                        }

                        temp         = UrlUtil.JoinUrl(virtualPath, fileName);
                        photoString += temp;

                        photos.Add(temp);

                        fileName = IOUtil.JoinPath(photoPath, fileName);
                        if (!File.Exists(fileName))
                        {
                            File.WriteAllBytes(fileName, photoData[i]);
                        }

                        if (photos.Count > 1) //多余的照片不要, 只要最多两张
                        {
                            break;
                        }
                    }

                    UserDao.Instance.UpdateAuthenticUserPhoto(userID, photoString, state);
                }
            }

            return(state);
        }
Пример #2
0
        public EmoticonSaveStatus SaveEmoticonFile(int userID, byte[] fileData, string md5, string fileName, out string relativeUrl)
        {
            Size thumbSize = new Size(AllSettings.Current.EmoticonSettings.ThumbImageWidth,
                                      AllSettings.Current.EmoticonSettings.ThumbImageHeight);

            relativeUrl = "";

            if (fileData != null && fileData.Length > 0)
            {
                //判断文件大小是否超出限制
                if (fileData.Length > MaxEmticonFileSize(userID))
                {
                    return(EmoticonSaveStatus.FileSizeOverflow);
                }

                if (!IsAllowedFileType(fileName))
                {
                    return(EmoticonSaveStatus.Failed);
                }

                string dirLevel1, dirLevel2;


                string filePostfix = ".gif"; //Path.GetExtension(fileName);

                fileName = string.Format("{0}_{1}{2}", md5, fileData.Length, filePostfix);

                string directory = Globals.GetPath(SystemDirecotry.Upload_Emoticons);

                dirLevel1 = md5.Substring(0, 1);
                dirLevel2 = md5.Substring(1, 1);

                directory = IOUtil.JoinPath(directory, dirLevel1, dirLevel2);

                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                string filePath = IOUtil.JoinPath(directory, fileName);


                if (!File.Exists(filePath))
                {
                    using (FileStream fileStream = File.Create(filePath, fileData.Length))
                    {
                        fileStream.Write(fileData, 0, fileData.Length);
                        fileStream.Seek(0, SeekOrigin.Begin);

                        #region 生成缩略图
                        try
                        {
                            using (Bitmap bmpSource = new Bitmap(fileStream))
                            {
                                using (Bitmap bmp = new Bitmap(thumbSize.Width, thumbSize.Height))
                                {
                                    using (Graphics g = Graphics.FromImage(bmp))
                                    {
                                        g.Clear(Color.White);
                                        g.DrawImage(bmpSource, new Rectangle(0, 0, thumbSize.Width, thumbSize.Height));
                                        g.Save();
                                    }
                                    bmp.Save(GetThumbFilePath(filePath, false), ImageFormat.Png);
                                }
                            }
                        }
                        catch
                        {
                        }
                        #endregion

                        fileStream.Close();
                    }
                }
                relativeUrl = fileName;//直接返回文件名

                return(EmoticonSaveStatus.Success);
            }
            return(EmoticonSaveStatus.Failed);
        }