102 lines
3.8 KiB
C#
102 lines
3.8 KiB
C#
using System;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Net;
|
|
using WX.CRM.BLL.weapp;
|
|
using WX.CRM.Common;
|
|
|
|
namespace WeChatServerServices.Weapp
|
|
{
|
|
public class WxImgFlagDownLoad
|
|
{
|
|
public void Start()
|
|
{
|
|
WxDownload();
|
|
WxAppDownload();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 微信下载
|
|
/// </summary>
|
|
private void WxDownload()
|
|
{
|
|
string imgFlagPath = ConfigurationManager.AppSettings["WxImgFlagPath"] != null ? ConfigurationManager.AppSettings["WxImgFlagPath"] : "D:/web/WXFILE/flag/";
|
|
WX_UserInfo_BL nbl = new WX_UserInfo_BL();
|
|
DataTable table = nbl.Get_ImgFlagForDownLoad();
|
|
WebClient client = new WebClient();
|
|
|
|
if (!Directory.Exists(imgFlagPath))//没有文件夹就创建
|
|
{
|
|
Directory.CreateDirectory(imgFlagPath);
|
|
}
|
|
//string filePath = Path.Combine(uploadFolder, fileName);
|
|
try
|
|
{
|
|
string filename = string.Empty;
|
|
string username = string.Empty;
|
|
foreach (DataRow item in table.Rows)
|
|
{
|
|
if (item["reserved1"] == DBNull.Value)
|
|
continue;
|
|
filename = DateTime.Now.ToString("yyyyMMddHHmmssffff");
|
|
username = item["username"].ToString();
|
|
string jpgname = filename + ".jpg";
|
|
string URLAddress = item["reserved1"].ToString() + "?i=" + filename;
|
|
string NewFile = Path.Combine(imgFlagPath, jpgname);
|
|
client.DownloadFile(URLAddress, NewFile);//进行文件下载
|
|
string fileMD5 = FileUnit.GetMD5HashFromFile(NewFile);//文件MD5获取
|
|
nbl.Upadte_ImgFlag(username, fileMD5, jpgname);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error("下载头像失败:" + ex.ToString());
|
|
}
|
|
finally { client.Dispose(); }
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 公众号小程序下载
|
|
/// </summary>
|
|
private void WxAppDownload()
|
|
{
|
|
string imgFlagPath = ConfigurationManager.AppSettings["WxWeapImgFlagPath"] != null ? ConfigurationManager.AppSettings["WxWeapImgFlagPath"] : "D:/web/WXFILE/weapflag/";
|
|
WX_UserInfo_BL nbl = new WX_UserInfo_BL();
|
|
DataTable table = nbl.Get_WeapUserInfo();
|
|
WebClient client = new WebClient();
|
|
|
|
if (!Directory.Exists(imgFlagPath))//没有文件夹就创建
|
|
{
|
|
Directory.CreateDirectory(imgFlagPath);
|
|
}
|
|
//string filePath = Path.Combine(uploadFolder, fileName);
|
|
try
|
|
{
|
|
string filename = string.Empty;
|
|
string username = string.Empty;
|
|
foreach (DataRow item in table.Rows)
|
|
{
|
|
if (item["avatarurl"] == DBNull.Value)
|
|
continue;
|
|
filename = DateTime.Now.ToString("yyyyMMddHHmmssffff");
|
|
username = item["openid"].ToString();
|
|
string jpgname = filename + ".jpg";
|
|
string URLAddress = item["avatarurl"].ToString() + "?i=" + filename;
|
|
string NewFile = Path.Combine(imgFlagPath, jpgname);
|
|
client.DownloadFile(URLAddress, NewFile);//进行文件下载
|
|
string fileMD5 = FileUnit.GetMD5HashFromFile(NewFile);//文件MD5获取
|
|
nbl.Up_WeapImgFlag(username, fileMD5, jpgname);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error("下载头像失败:" + ex.ToString());
|
|
}
|
|
finally { client.Dispose(); }
|
|
|
|
}
|
|
}
|
|
}
|