Browse Source

网页抓经营模式

liangku_skuoptimazation
shanji 1 year ago
parent
commit
89b9d5306b
  1. 6
      BBWYB.PurchaserCapture/BBWYB.PurchaserCapture.csproj
  2. 83
      BBWYB.PurchaserCapture/EncryptionExtension.cs
  3. 9
      BBWYB.PurchaserCapture/MainWindow.xaml
  4. 110
      BBWYB.PurchaserCapture/MainWindow.xaml.cs
  5. 113
      BBWYB.PurchaserCapture/Model/Db/Purchaser.cs
  6. 53
      BBWYB.PurchaserCapture/Model/Db/Purchaseschemeproduct.cs
  7. 359
      BBWYB.PurchaserCapture/Model/Enums.cs

6
BBWYB.PurchaserCapture/BBWYB.PurchaserCapture.csproj

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
@ -9,9 +9,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0" />
<PackageReference Include="FreeSql" Version="3.2.690" />
<PackageReference Include="FreeSql.Provider.MySql" Version="3.2.690" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.2-mauipre.1.22102.15" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.2-mauipre.1.22102.15" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2210.55" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>

83
BBWYB.PurchaserCapture/EncryptionExtension.cs

@ -0,0 +1,83 @@
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace BBWYB.Common.Extensions
{
public static class EncryptionExtension
{
public static string Md5Encrypt(this string originStr)
{
using (var md5 = MD5.Create())
{
return string.Join(string.Empty, md5.ComputeHash(Encoding.UTF8.GetBytes(originStr)).Select(x => x.ToString("x2")));
}
}
//AES加密 传入,要加密的串和, 解密key
public static string AESEncrypt(this string input)
{
var key = "dataplatform2019";
var ivStr = "1012132405963708";
var encryptKey = Encoding.UTF8.GetBytes(key);
var iv = Encoding.UTF8.GetBytes(ivStr); //偏移量,最小为16
using (var aesAlg = Aes.Create())
{
using (var encryptor = aesAlg.CreateEncryptor(encryptKey, iv))
{
using (var msEncrypt = new MemoryStream())
{
using (var csEncrypt = new CryptoStream(msEncrypt, encryptor,
CryptoStreamMode.Write))
using (var swEncrypt = new StreamWriter(csEncrypt))
{
swEncrypt.Write(input);
}
var decryptedContent = msEncrypt.ToArray();
return Convert.ToBase64String(decryptedContent);
}
}
}
}
public static string AESDecrypt(this string cipherText)
{
var fullCipher = Convert.FromBase64String(cipherText);
var ivStr = "1012132405963708";
var key = "dataplatform2019";
var iv = Encoding.UTF8.GetBytes(ivStr);
var decryptKey = Encoding.UTF8.GetBytes(key);
using (var aesAlg = Aes.Create())
{
using (var decryptor = aesAlg.CreateDecryptor(decryptKey, iv))
{
string result;
using (var msDecrypt = new MemoryStream(fullCipher))
{
using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
using (var srDecrypt = new StreamReader(csDecrypt))
{
result = srDecrypt.ReadToEnd();
}
}
}
return result;
}
}
}
public static string Base64Encrypt(this string originStr)
{
return Convert.ToBase64String(Encoding.UTF8.GetBytes(originStr));
}
}
}

9
BBWYB.PurchaserCapture/MainWindow.xaml

@ -6,7 +6,12 @@
xmlns:local="clr-namespace:BBWYB.PurchaserCapture"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid x:Name="grid">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<TextBlock x:Name="txtInfo" Text="" Grid.Row="1" VerticalAlignment="Center" Margin="5,0,0,0" HorizontalAlignment="Left"/>
<Button x:Name="btn_start" Grid.Row="1" Width="80" Content="开始" Height="25" Click="btn_start_Click"/>
</Grid>
</Window>

110
BBWYB.PurchaserCapture/MainWindow.xaml.cs

@ -1,13 +1,11 @@
using System.Text;
using BBWYB.Common.Extensions;
using BBWYB.Server.Model.Db;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.Wpf;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using io = System.IO;
namespace BBWYB.PurchaserCapture
{
@ -16,9 +14,103 @@ namespace BBWYB.PurchaserCapture
/// </summary>
public partial class MainWindow : Window
{
private IFreeSql fsql;
private WebView2 wb2;
public MainWindow()
{
InitializeComponent();
fsql = new FreeSql.FreeSqlBuilder().UseConnectionString(FreeSql.DataType.MySql, "data source=rm-bp1508okrh23710yfao.mysql.rds.aliyuncs.com;port=3306;user id=qyroot;password=kaicn1132+-;initial catalog=bbwyb;charset=utf8;sslmode=none;").Build();
this.Loaded += MainWindow_Loaded;
}
private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
wb2 = new WebView2();
grid.Children.Add(wb2);
var wb2Setting = CoreWebView2Environment.CreateAsync(userDataFolder: io.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "AdvUnion.Capturer")).Result;
wb2.CoreWebView2InitializationCompleted += Wb2_CoreWebView2InitializationCompleted;
await wb2.EnsureCoreWebView2Async(wb2Setting);
wb2.CoreWebView2.AddWebResourceRequestedFilter("*", CoreWebView2WebResourceContext.All);
wb2.CoreWebView2.WebResourceResponseReceived += CoreWebView2_WebResourceResponseReceived;
wb2.CoreWebView2.WebResourceRequested += CoreWebView2_WebResourceRequested;
}
private async void CoreWebView2_WebResourceResponseReceived(object? sender, CoreWebView2WebResourceResponseReceivedEventArgs e)
{
if (e.Request.Method.ToUpper() != "GET" ||
!e.Request.Uri.StartsWith("https://h5api.m.1688.com/h5/mtop.alibaba.alisite.cbu.server.moduleasyncservice") ||
!e.Request.Uri.Contains("wp_pc_common_header"))
{
Console.WriteLine($"不满足URL规则,已忽略 {e.Request.Uri}");
return;
}
if (e.Response.StatusCode != 200)
{
Console.WriteLine($"HttpCode {e.Response.StatusCode},已忽略 {e.Request.Uri}");
return;
}
var stream = await e.Response.GetContentAsync();
var sr = new StreamReader(stream);
var content = sr.ReadToEnd();
sr.Dispose();
var match = Regex.Match(content, "\"bizTypeName\":\\s?\"(.+)\",");
if (!match.Success)
{
Console.WriteLine($"bizTypeName解析失败,已忽略 {e.Request.Uri}");
return;
}
var bizTypeName = match.Groups[1].Value;
Console.WriteLine(bizTypeName);
}
private void CoreWebView2_WebResourceRequested(object? sender, CoreWebView2WebResourceRequestedEventArgs e)
{
}
private void Wb2_CoreWebView2InitializationCompleted(object? sender, CoreWebView2InitializationCompletedEventArgs e)
{
}
private void SetInfo(string msg)
{
this.Dispatcher.Invoke(() => txtInfo.Text = msg);
}
private void Navigate(string url)
{
this.Dispatcher.Invoke(() => wb2.CoreWebView2.Navigate(url));
}
private void btn_start_Click(object sender, RoutedEventArgs e)
{
Task.Factory.StartNew(() =>
{
var sk = "order";
//var sk = "consign";
var pspList = fsql.Select<PurchaseSchemeProduct, Purchaser>()
.InnerJoin((psp2, p) => psp2.PurchaserId == p.Id)
.Where((psp2, p) => string.IsNullOrEmpty(p.ManagmentMode))
.GroupBy((psp2, p) => psp2.PurchaserId)
.WithTempQuery(g => new { MaxId = g.Max(g.Value.Item1.Id), PurchaserId = g.Key })
.From<PurchaseSchemeProduct>()
.InnerJoin((psp2, psp1) => psp2.MaxId == psp1.Id)
.OrderByDescending((psp2, psp1) => psp1.Id)
.ToList((psp2, psp1) => psp1);
for (var i = 0; i < pspList.Count; i++)
{
SetInfo($"{i + 1}/{pspList.Count}");
var url = $"https://detail.1688.com/offer/{pspList[i].PurchaseProductId}.html?clickid={Guid.NewGuid().ToString().Md5Encrypt()}&sessionid={Guid.NewGuid().ToString().Md5Encrypt()}&sk={sk}";
Navigate(url);
Thread.Sleep(60000);
}
});
}
}
}

113
BBWYB.PurchaserCapture/Model/Db/Purchaser.cs

@ -0,0 +1,113 @@
using FreeSql.DataAnnotations;
namespace BBWYB.Server.Model.Db
{
/// <summary>
/// 采购商表
/// </summary>
[Table(Name = "purchaser", DisableSyncStructure = true)]
public partial class Purchaser
{
/// <summary>
/// 采购商Id (1688 SellerUserId)
/// </summary>
[Column(StringLength = 20, IsPrimary = true, IsNullable = false)]
public string Id { get; set; }
/// <summary>
/// 采购商Id2 (1688 SellerLoginId)
/// </summary>
[Column(StringLength = 50)]
public string Id2 { get; set; }
/// <summary>
/// 发货地(产地)
/// </summary>
[Column(StringLength = 50)]
public string Location { get; set; }
/// <summary>
/// 经营模式
/// </summary>
[Column(StringLength = 50)]
public string ManagmentMode { get; set; }
[Column(StringLength = 50)]
public string MemberId { get; set; }
/// <summary>
/// 采购商名称
/// </summary>
[Column(StringLength = 50)]
public string Name { get; set; }
/// <summary>
/// 采购平台
/// </summary>
[Column(MapType = typeof(int?))]
public Enums.Platform? Platform { get; set; }
/// <summary>
/// 商家标签 (超级工厂/实力工厂/实力供应商),可空
/// </summary>
[Column(StringLength = 20)]
public string Tag { get; set; }
/// <summary>
/// 绑定SPU数
/// </summary>
[Column(DbType = "bigint")]
public long? BindingSpuCount { get; set; } = 0;
/// <summary>
/// 采购SPU数
/// </summary>
[Column(DbType = "bigint")]
public long? PurchasedSpuCount { get; set; } = 0;
/// <summary>
/// 绑定SKU数
/// </summary>
[Column(DbType = "bigint")]
public long? BindingSkuCount { get; set; } = 0;
/// <summary>
/// 采购SKU数
/// </summary>
[Column(DbType = "bigint")]
public long? PurchasedSkuCount { get; set; } = 0;
/// <summary>
/// 采购次数/采购订单数
/// </summary>
[Column(DbType = "bigint")]
public long? PurchasedCount { get; set; } = 0;
/// <summary>
/// 采购金额
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? PurchasedAmount { get; set; } = 0.00M;
/// <summary>
/// 上次采购时间
/// </summary>
[Column(DbType = "datetime")]
public DateTime? LastPurchasedTime { get; set; }
/// <summary>
/// 最近90天采购金额
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? Recent90dPurchasedAmount { get; set; } = 0.00M;
/// <summary>
/// 最近90天采购次数
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? Recent90dPurchasedCount { get; set; } = 0.00M;
}
}

53
BBWYB.PurchaserCapture/Model/Db/Purchaseschemeproduct.cs

@ -0,0 +1,53 @@
using FreeSql.DataAnnotations;
namespace BBWYB.Server.Model.Db
{
/// <summary>
/// 采购方案商品表
/// </summary>
[Table(Name = "purchaseschemeproduct", DisableSyncStructure = true)]
public partial class PurchaseSchemeProduct
{
/// <summary>
/// 采购商品和采购方案的关系Id
/// </summary>
[Column(IsPrimary = true)]
public long Id { get; set; }
[Column(DbType = "datetime")]
public DateTime? CreateTime { get; set; }
[Column(StringLength = 50, IsNullable = false)]
public string ProductId { get; set; }
/// <summary>
/// 采购商品Id
/// </summary>
[Column(StringLength = 50, IsNullable = false)]
public string PurchaseProductId { get; set; }
/// <summary>
/// 采购商品链接
/// </summary>
[Column(StringLength = 100)]
public string PurchaseUrl { get; set; }
[Column(StringLength = 50, IsNullable = false)]
public string SkuId { get; set; }
/// <summary>
/// Sku采购方案Id
/// </summary>
public long SkuPurchaseSchemeId { get; set; }
/// <summary>
/// 采购商Id
/// </summary>
[Column(StringLength = 20)]
public string PurchaserId { get; set; }
}
}

359
BBWYB.PurchaserCapture/Model/Enums.cs

@ -0,0 +1,359 @@
namespace BBWYB.Server.Model
{
public class Enums
{
/// <summary>
/// 电商平台 淘宝 = 0,京东 = 1,阿里巴巴 = 2,拼多多 = 3,微信 = 4,拳探 = 10,抖音 = 11
/// </summary>
public enum Platform
{
= 0,
= 1,
= 2,
= 3,
= 4,
= 10,
= 11
}
/// <summary>
/// 采购方式 线上采购 = 0,关联外部单 = 1,手动下单 = 2
/// </summary>
public enum PurchaseMethod
{
线 = 0,
= 1,
= 2
}
/// <summary>
/// 采购单模式 批发 = 0,代发 = 1
/// </summary>
public enum PurchaseOrderMode
{
= 0,
= 1
}
/// <summary>
/// 仓储类型
/// </summary>
public enum StorageType
{
= 0,
= 1,
= 2,
= 3,
SD = 4
}
/// <summary>
/// 订单类型
/// </summary>
public enum OrderType
{
#region JD订单类型
SOP = 22,
LOC = 75,
FBP = 21
#endregion
}
/// <summary>
/// 支付方式
/// </summary>
public enum PayType
{
= 1,
= 2,
= 3,
线 = 4,
= 5,
= 6
}
/// <summary>
/// 订单状态
/// <para>待付款 = 0</para>
/// <para>等待采购 = 1, 部分采购 = 110</para>
/// <para>待发货 = 2, 部分发货 = 120</para>
/// <para>待收货 = 3, 部分收货 = 130</para>
/// <para>已完成 = 4</para>
/// <para>已取消 = 6</para>
/// <para>待验收 = 140</para>
/// <para>待核算 = 150</para>
/// </summary>
public enum OrderState
{
= 0,
= 1,
= 110,
= 2,
= 120,
= 3,
= 130,
= 4,
= 6,
= 140,
= 150
}
/// <summary>
/// 采购单状态 待发货 = 0, 部分发货=1, 待收货 = 10, 部分收货=11, 已签收 = 20, 已取消 = 100
/// </summary>
public enum PurchaseOrderState
{
= 0,
= 1,
= 10,
= 11,
= 20,
= 100
}
/// <summary>
/// 刷单类型
/// </summary>
public enum SDType
{
= 0,
= 1,
= 2,
= 3
}
/// <summary>
/// 订单同步任务状态
/// </summary>
public enum OrderSyncState
{
Running = 0,
End = 1
}
public enum PayChannelType
{
= 0,
= 1,
= 2
}
/// <summary>
/// 服务单处理结果
/// </summary>
public enum ServiceResult
{
退 = 0,
= 1,
= 2,
线 = 3,
= 4,
= 5,
退 = 6,
SD退货 = 7
}
/// <summary>
/// 商品处理方式
/// </summary>
public enum ProductResult
{
_退 = 0,
退 = 1,
退 = 2,
退 = 3,
退 = 4
}
/// <summary>
/// 商品情况
/// </summary>
public enum ProductHealth
{
= 0,
_ = 1,
退退 = 2,
退 = 3,
= 4
}
/// <summary>
/// 排序时间类型 ModifyTime = 0, StartTime = 1
/// </summary>
public enum SortTimeType
{
ModifyTime = 0, StartTime = 1
}
/// <summary>
/// 支付账单类型
/// </summary>
public enum PayBillType
{
= 0,
= 1,
= 2
}
/// <summary>
/// 资金类型
/// </summary>
public enum AuditCapitalType
{
= 0,
退 = 1,
= 2,
退 = 3,
= 4,
= 5,
= 6,
= 7,
= 8,
= 9,
e赊还款 = 10,
= 11,
= 12,
= 13,
= 14,
= 15,
= 16,
= 17,
= 18,
= 19
}
/// <summary>
/// 京东仓库类型 1商家仓 2京东仓
/// </summary>
public enum StockType
{
= 1, = 2
}
/// <summary>
/// 仓库状态 0暂停,1使用
/// </summary>
public enum StockStatus
{
= 0, 使 = 1
}
/// <summary>
/// SKU库存周期 暂无周期=0,增长期=1,稳定期=2,衰退期=3
/// </summary>
public enum SkuStockNumCycleType
{
= 0,
= 1,
= 2,
退 = 3
}
/// <summary>
/// 司南周期 暂无周期 = -1,成长加速期 = 0,成熟利润期 = 1,稳定日销期 = 2,策马奔腾期 = 3
/// </summary>
public enum SiNanCycleType
{
= -1,
= 0,
= 1,
= 2,
= 3
}
/// <summary>
/// 促销任务状态 等待 = 0,进行中 = 1,已完成 = 2, 已停止 = 3
/// </summary>
public enum PromitionTaskStatus
{
= 0,
= 1,
= 2,
= 3
}
/// <summary>
/// AppKey类型 全类型 = 0, 订单管理 = 1, 商品管理 = 2
/// </summary>
public enum AppKeyType
{
= 0, = 1, = 2
}
/// <summary>
/// 采购商品API模式 Spider = 0,OneBound = 1
/// </summary>
public enum PurchaseProductAPIMode
{
Spider = 0,
OneBound = 1
}
/// <summary>
/// 打包配置状态 待配置 = 0,已配置 = 1,需修改 = 2
/// </summary>
public enum PackConfigState
{
= 0,
= 1,
= 2
}
/// <summary>
/// 入仓类型 (发回齐越 = 0, 厂商代发入仓 = 1,其他仓不包装 = 2)
/// </summary>
public enum IntoStoreType
{
= 0, = 1, = 2
}
/// <summary>
/// 限时任务类型 采购任务 = 0, 合格证拟定任务 = 10, 合格证补充任务 = 11, 待核算任务 = 20, 待议价任务 = 30
/// </summary>
public enum TimeLimitTaskType
{
= 0, = 10, = 11, = 20, = 30
}
/// <summary>
/// 平价状态 未平价=0 已平价=1 部分平价=2
/// </summary>
public enum AutoEditOrderPriceType
{
= 0, = 1, = 2
}
/// <summary>
/// 触发优化原因 首次采购 = 0, 首次优化 = 1, 再次优化 = 2
/// </summary>
public enum TriggerOptimizationReason
{
= 0, = 1, = 2
}
/// <summary>
/// 厂家经营模式 贸易 = 0, 厂家 = 1
/// </summary>
public enum ManagmentMode
{
= 0, = 1
}
/// <summary>
/// 厂家扩展信息类型 主营类目 = 0, 标签 = 1
/// </summary>
public enum PurchaserBasicInfoType
{
= 0, = 1
}
/// <summary>
/// 比较运算符 大于 = 0, 小于 = 1, 等于 = 2, 介于 = 3
/// </summary>
public enum ComparisonOperator
{
= 0, = 1, = 2, = 3
}
}
}
Loading…
Cancel
Save