Exemple #1
0
        public void DownloadImage()
        {
            string uuid = MethodsHelper.HeadImageSaveFile(DirectoryDefine.HeaderImagePath, DisplayNameDef);

            if (File.Exists(Environment.CurrentDirectory + "\\" + DirectoryDefine.HeaderImagePath + "\\" + MethodsHelper.EncryptWithMD5(CommonDefine.BaseContact.User.NickName) + uuid + ".jpg"))
            {
                HeadUrlDef = Environment.CurrentDirectory + "\\" + DirectoryDefine.HeaderImagePath + "\\" + MethodsHelper.EncryptWithMD5(CommonDefine.BaseContact.User.NickName) + uuid + ".jpg";
                return;
            }
            if (string.IsNullOrWhiteSpace(HeadUrlDef))
            {
                HttpHelper.HttpMethods.GetFile(UrlDefine.RootUrl + HeadImgUrl, Environment.CurrentDirectory + "\\" + DirectoryDefine.HeaderImagePath + "\\" + MethodsHelper.EncryptWithMD5(CommonDefine.BaseContact.User.NickName) + uuid + ".jpg", CommonDefine.Cookies);
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    FileInfo fileInfo = new FileInfo(Environment.CurrentDirectory + "\\" + DirectoryDefine.HeaderImagePath + "\\" + MethodsHelper.EncryptWithMD5(CommonDefine.BaseContact.User.NickName) + uuid + ".jpg");
                    if (fileInfo.Length == 0)
                    {
                        HeadUrlDef = "pack://application:,,,/WeChatCore;component/Resource/DefultHeader.png";
                    }
                    else
                    {
                        HeadUrlDef = Environment.CurrentDirectory + "\\" + DirectoryDefine.HeaderImagePath + "\\" + MethodsHelper.EncryptWithMD5(CommonDefine.BaseContact.User.NickName) + uuid + ".jpg";
                    }
                }));
            }
            else
            {
                LogWriter.Write(string.Format("当前人员{0}已有头像", DisplayNameDef), LogPathDefine.WeChatLogPath);
            }
        }