Commit c959be65 authored by 黄奎's avatar 黄奎

新增

parent bb9ba2d7
......@@ -37,6 +37,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mall.Module.Product", "Mall
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mall.Module.MarketingCenter", "Mall.Module.MarketingCenter\Mall.Module.MarketingCenter.csproj", "{339DE5B1-FA62-4B3D-80D4-0C50398D2848}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{E56AB52A-2396-4A34-82AE-344EBF51F248}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -95,6 +97,10 @@ Global
{339DE5B1-FA62-4B3D-80D4-0C50398D2848}.Debug|Any CPU.Build.0 = Debug|Any CPU
{339DE5B1-FA62-4B3D-80D4-0C50398D2848}.Release|Any CPU.ActiveCfg = Release|Any CPU
{339DE5B1-FA62-4B3D-80D4-0C50398D2848}.Release|Any CPU.Build.0 = Release|Any CPU
{E56AB52A-2396-4A34-82AE-344EBF51F248}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E56AB52A-2396-4A34-82AE-344EBF51F248}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E56AB52A-2396-4A34-82AE-344EBF51F248}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E56AB52A-2396-4A34-82AE-344EBF51F248}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
<connectionStrings>
<add name="DefaultConnection" providerName="MySql.Data.MySqlClient" connectionString="server=192.168.2.214;user id=reborn;password=Reborn@2018;database=reborn_mall;CharSet=utf8; Convert Zero Datetime=true; " />
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data></configuration>
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test.DBHelper
{
/// <summary>
/// MySql帮助类
/// </summary>
public class MySqlHelper
{
/// <summary>
/// 默认连接字符串
/// </summary>
public static readonly string defaultConnection = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
public static object ExecuteScalar(string connectionString, CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
{
MySqlCommand cmd = new MySqlCommand();
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
}
public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
{
// Create a new MySql command
MySqlCommand cmd = new MySqlCommand();
//Create a connection
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
//Prepare the command
PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
//Execute the command
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
}
/// <summary>
/// Internal function to prepare a command for execution by the database
/// </summary>
/// <param name="cmd">Existing command object</param>
/// <param name="conn">Database connection object</param>
/// <param name="trans">Optional transaction object</param>
/// <param name="cmdType">Command type, e.g. stored procedure</param>
/// <param name="cmdText">Command test</param>
/// <param name="commandParameters">Parameters for the command</param>
private static void PrepareCommand(MySqlCommand cmd, MySqlConnection conn, MySqlTransaction trans, CommandType cmdType, string cmdText, MySqlParameter[] commandParameters)
{
//Open the connection if required
if (conn.State != ConnectionState.Open)
conn.Open();
//Set up the command
cmd.Connection = conn;
cmd.CommandText = cmdText;
cmd.CommandType = cmdType;
//Bind it to the transaction if it exists
if (trans != null)
cmd.Transaction = trans;
// Bind the parameters passed in
if (commandParameters != null)
{
foreach (MySqlParameter parm in commandParameters)
cmd.Parameters.Add(parm);
}
}
}
}
using Newtonsoft.Json.Linq;
using Test.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Text.RegularExpressions;
using Test.DBHelper;
namespace Test.Helper
{
/// <summary>
/// 商城帮助类
/// </summary>
public class MallHelper
{
/// <summary>
/// 获取数据
/// </summary>
public static void GetData()
{
string cookie = "__login_route=%2Fadmin%2Fpassport%2Flogin; __login_role=admin; search={'keyword':'','status':' - 1','sort_prop':'','sort_type':'','cats'[],'date_start':null,'date_end':null}; HJ_SESSION_ID=kmmormovvm2u9qh5drkgsbj1ta; _csrf=7a980bb65eabe0ac3d77199092030044b17ae9779de00eaed628c8095ab2fe0ca%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22rsnZWVWkZkpfvVhLBXu8sGG3px0Dgcsx%22%3B%7D";
GetGategoryImgList(cookie);
}
/// <summary>
/// 获取分类
/// </summary>
/// <param name="cookie"></param>
static void GetGategoryImgList(string cookie)
{
var CategoryList = GetCategoryList(cookie);
if (CategoryList != null && CategoryList.Count > 0)
{
var index = 1;
foreach (var item in CategoryList)
{
Console.WriteLine(index+"/"+ CategoryList.Count + item.name + "分类Start");
StringBuilder builder = new StringBuilder();
builder.AppendFormat(" INSERT INTO rb_material_group(Name,Type,Sort,Recycled,Status,TenantId,MallBaseId,CreateDate,UpdateDate)");
builder.AppendFormat(" VALUES('{0}',{1},{2},1,0,1,1,'{3}','{4}');SELECT LAST_INSERT_ID()", item.name, item.type, item.is_recycle, DateTime.Now, DateTime.Now);
int parentId = 0;
try
{
var res = MySqlHelper.ExecuteScalar(MySqlHelper.defaultConnection, System.Data.CommandType.Text, builder.ToString(), null);
if (res != null && Convert.ToInt32(res) > 0)
{
Int32.TryParse(res.ToString(), out parentId);
}
}
catch (Exception ex)
{
}
int pageIndex = 0;
int pageCount = 1;
List<CategoryImg> imgList = new List<CategoryImg>();
while (pageIndex <= pageCount)
{
var tempImgList = GetCategoryImgList(cookie, pageIndex, item.id, out pageCount);
Console.WriteLine(pageIndex + "/" + pageCount + item.name + "分类ing");
if (tempImgList != null && tempImgList.Count > 0)
{
foreach (var subItem in tempImgList)
{
CreateImage(subItem.url);
string path = "https://viitto-1301420277.cos.ap-chengdu.myqcloud.com" + GetFileUrl(subItem.url);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendFormat("INSERT INTO rb_material_info(Name,Type,GroupId,Path,Image,VideoTime,WithHeight,TenantId,MallBaseId,CreateDate,UpdateDate,Recycled,Status)");
stringBuilder.AppendFormat(" VALUES('{0}',{1},{2},'{3}','{4}',0,0,1,1,'{5}','{6}',1,0)", subItem.name, subItem.type, parentId, path, "", DateTime.Now, DateTime.Now);
try
{
var newResult = MySqlHelper.ExecuteNonQuery(MySqlHelper.defaultConnection, System.Data.CommandType.Text, stringBuilder.ToString(), null);
}
catch (Exception ex)
{
}
}
}
pageIndex++;
var ranDomNum = new Random().Next(1, 20);
Thread.Sleep(1000 * ranDomNum);
}
index++;
Console.WriteLine(index + "/" + CategoryList.Count + item.name + "分类End");
}
}
}
/// <summary>
/// 生成图片
/// </summary>
/// <param name="url"></param>
static void CreateImage(string url)
{
string tempPath = GetFileUrl(url);
string path = Environment.CurrentDirectory + tempPath;//下载到的地址+文件名 // 设置参数
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
//发送请求并获取相应回应数据
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
Stream responseStream = response.GetResponseStream();
string newFilePath = path.Substring(0, path.LastIndexOf("/"));
if (!System.IO.Directory.Exists(newFilePath))//如果不存在就创建file文件夹
{
System.IO.Directory.CreateDirectory(newFilePath);
}
//创建本地文件写入流
Stream stream = new FileStream(path, FileMode.Create);
byte[] bArr = new byte[1024];
int size = responseStream.Read(bArr, 0, (int)bArr.Length);
while (size > 0)
{
stream.Write(bArr, 0, size);
size = responseStream.Read(bArr, 0, (int)bArr.Length);
}
stream.Close();
responseStream.Close();
}
/// <summary>
/// 获取Oss文件全路径
/// </summary>
/// <param name="path">文件相对路径</param>
/// <returns></returns>
public static string GetFileUrl(string path)
{
return path.Replace("https://cdnimg.iotweixin.com", "");
}
/// <summary>
/// 获取分类图片
/// </summary>
/// <param name="cookie"></param>
/// <param name="pageIndex"></param>
/// <param name="Id">分类编号</param>
/// <param name="pageCount"></param>
/// <returns></returns>
static List<CategoryImg> GetCategoryImgList(string cookie, int pageIndex, int Id, out int pageCount)
{
pageCount = 0;
List<CategoryImg> list = new List<CategoryImg>();
string imgApi = "https://wx.weibaoge.cn/web/index.php?r=common%2Fattachment%2Flist&page={0}&attachment_group_id={1}&type=image&is_recycle=0&keyword=";
string newImaApi = string.Format(imgApi, pageIndex, Id);
cookie = "__login_route=%2Fadmin%2Fpassport%2Flogin; __login_role=admin; search={'keyword':'','status':'-1','sort_prop':'','sort_type':'','cats':[],'date_start':null,'date_end':null}; HJ_SESSION_ID=kmmormovvm2u9qh5drkgsbj1ta; _csrf=7a980bb65eabe0ac3d77199092030044b17ae9779de00eaed628c8095ab2fe0ca%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22rsnZWVWkZkpfvVhLBXu8sGG3px0Dgcsx%22%3B%7D";
string jsonData = HttpGet(newImaApi, cookie);
if (jsonData != null && !string.IsNullOrEmpty(jsonData))
{
JObject obj = JObject.Parse(jsonData);
JObject dataObj = JObject.Parse(obj["data"].ToString());
list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<CategoryImg>>(dataObj["list"].ToString());
var pageObj = JObject.Parse(dataObj["pagination"].ToString());
Int32.TryParse(pageObj["total_count"].ToString(), out pageCount);
}
return list;
}
/// <summary>
/// 获取商品分类
/// </summary>
/// <param name="cookie"></param>
/// <returns></returns>
static List<Category> GetCategoryList(string cookie)
{
List<Category> list = new List<Category>();
string ApiUrl = "https://wx.weibaoge.cn/web/index.php?r=common%2Fattachment%2Fgroup-list&is_recycle=0&type=image";
string jsonData = HttpGet(ApiUrl, cookie);
if (jsonData != null && !string.IsNullOrEmpty(jsonData))
{
JObject obj = JObject.Parse(jsonData);
JObject dataObj = JObject.Parse(obj["data"].ToString());
list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Category>>(dataObj["list"].ToString());
}
return list;
}
/// <summary>
/// Get获取数据
/// </summary>
/// <param name="url">url地址</param>
/// <param name="encode">编码方式</param>
/// <param name="Source">来源</param>
/// <returns></returns>
static string HttpGet(string url, string cookie)
{
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Headers.Add("cookie", cookie);
myRequest.Method = "GET";
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
reader.Close();
return content;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test.Model
{
/// <summary>
/// 分类实体
/// </summary>
public class Category
{
/// <summary>
/// 分类编号
/// </summary>
public int id { get; set; }
/// <summary>
/// 商城Id
/// </summary>
public int mall_id { get; set; }
public int mch_id { get; set; }
/// <summary>
/// 分类名称
/// </summary>
public string name { get; set; }
/// <summary>
/// 1-图片,2-视频
/// </summary>
public int type { get; set; }
public int is_recycle { get; set; }
}
/// <summary>
/// 分类图片实体
/// </summary>
public class CategoryImg
{
/// <summary>
/// 主键编号
/// </summary>
public int id { get; set; }
/// <summary>
/// storage_id
/// </summary>
public int storage_id { get; set; }
/// <summary>
/// 分类编号
/// </summary>
public int attachment_group_id { get; set; }
/// <summary>
/// 分类名称
/// </summary>
public string name { get; set; }
/// <summary>
/// 图片大小
/// </summary>
public int size { get; set; }
/// <summary>
/// 图片地址
/// </summary>
public string url { get; set; }
/// <summary>
/// 缩略图地址
/// </summary>
public string thumb_url { get; set; }
/// <summary>
/// 1-图片,2-视频
/// </summary>
public int type { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Start......");
Helper.MallHelper.GetData();
Console.WriteLine("End......");
Console.ReadLine();
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Test")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("e56ab52a-2396-4a34-82ae-344ebf51f248")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E56AB52A-2396-4A34-82AE-344EBF51F248}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Test</RootNamespace>
<AssemblyName>Test</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MySql.Data, Version=6.7.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.6.7.9\lib\net45\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DBHelper\MySqlHelper.cs" />
<Compile Include="Helper\MallHelper.cs" />
<Compile Include="Model\Category.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MySql.Data" version="6.7.9" targetFramework="net46" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />
</packages>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment