|
|
@ -3,6 +3,8 @@ using BBWYB.Server.Model.Db; |
|
|
|
using Microsoft.Web.WebView2.Core; |
|
|
|
using Microsoft.Web.WebView2.Wpf; |
|
|
|
using System.IO; |
|
|
|
using System.Reflection.Metadata; |
|
|
|
using System.Text; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
using System.Windows; |
|
|
|
using io = System.IO; |
|
|
@ -16,6 +18,8 @@ namespace BBWYB.PurchaserCapture |
|
|
|
{ |
|
|
|
private IFreeSql fsql; |
|
|
|
private WebView2 wb2; |
|
|
|
private string purchaserId; |
|
|
|
private string purchaserMemberId; |
|
|
|
|
|
|
|
public MainWindow() |
|
|
|
{ |
|
|
@ -35,6 +39,16 @@ namespace BBWYB.PurchaserCapture |
|
|
|
wb2.CoreWebView2.AddWebResourceRequestedFilter("*", CoreWebView2WebResourceContext.All); |
|
|
|
wb2.CoreWebView2.WebResourceResponseReceived += CoreWebView2_WebResourceResponseReceived; |
|
|
|
wb2.CoreWebView2.WebResourceRequested += CoreWebView2_WebResourceRequested; |
|
|
|
wb2.CoreWebView2.NavigationCompleted += CoreWebView2_NavigationCompleted; |
|
|
|
} |
|
|
|
|
|
|
|
private void CoreWebView2_NavigationCompleted(object? sender, CoreWebView2NavigationCompletedEventArgs e) |
|
|
|
{ |
|
|
|
var scriptBuilder = new StringBuilder(); |
|
|
|
scriptBuilder.AppendLine("var divElement = document.querySelector('div[style=\"position: relative; display: flex; flex-direction: row;\"]');"); |
|
|
|
scriptBuilder.AppendLine("var mouseeoverEvent = new MouseEvent('mouseover', {'view': window,'bubbles': true,'cancelable': false});"); |
|
|
|
scriptBuilder.AppendLine("divElement.dispatchEvent(mouseeoverEvent);"); |
|
|
|
wb2.CoreWebView2.ExecuteScriptAsync(scriptBuilder.ToString()); |
|
|
|
} |
|
|
|
|
|
|
|
private async void CoreWebView2_WebResourceResponseReceived(object? sender, CoreWebView2WebResourceResponseReceivedEventArgs e) |
|
|
@ -55,7 +69,7 @@ namespace BBWYB.PurchaserCapture |
|
|
|
var sr = new StreamReader(stream); |
|
|
|
var content = sr.ReadToEnd(); |
|
|
|
sr.Dispose(); |
|
|
|
var match = Regex.Match(content, "\"bizTypeName\":\\s?\"(.+)\","); |
|
|
|
var match = Regex.Match(content, "\"bizTypeName\":\\s?\"(.*)\",\"isShili"); |
|
|
|
if (!match.Success) |
|
|
|
{ |
|
|
|
Console.WriteLine($"bizTypeName解析失败,已忽略 {e.Request.Uri}"); |
|
|
@ -63,12 +77,25 @@ namespace BBWYB.PurchaserCapture |
|
|
|
} |
|
|
|
var bizTypeName = match.Groups[1].Value; |
|
|
|
Console.WriteLine(bizTypeName); |
|
|
|
if (!string.IsNullOrEmpty(purchaserId)) |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(purchaserMemberId)) |
|
|
|
{ |
|
|
|
if (!content.Contains(purchaserMemberId)) |
|
|
|
{ |
|
|
|
Console.WriteLine($"memberId验证失败,已忽略 {e.Request.Uri}"); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
Console.WriteLine($"更新采购商{purchaserId}"); |
|
|
|
fsql.Update<Purchaser>(purchaserId).Set(p => p.ManagmentModeText, bizTypeName).ExecuteAffrows(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void CoreWebView2_WebResourceRequested(object? sender, CoreWebView2WebResourceRequestedEventArgs e) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void Wb2_CoreWebView2InitializationCompleted(object? sender, CoreWebView2InitializationCompletedEventArgs e) |
|
|
@ -83,7 +110,11 @@ namespace BBWYB.PurchaserCapture |
|
|
|
|
|
|
|
private void Navigate(string url) |
|
|
|
{ |
|
|
|
this.Dispatcher.Invoke(() => wb2.CoreWebView2.Navigate(url)); |
|
|
|
this.Dispatcher.Invoke(() => |
|
|
|
{ |
|
|
|
txt_url.Text = url; |
|
|
|
wb2.CoreWebView2.Navigate(url); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void btn_start_Click(object sender, RoutedEventArgs e) |
|
|
@ -94,21 +125,28 @@ namespace BBWYB.PurchaserCapture |
|
|
|
//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 }) |
|
|
|
.Where((psp2, p) => string.IsNullOrEmpty(p.ManagmentModeText)) |
|
|
|
.GroupBy((psp2, p) => new { p.Id, p.MemberId }) |
|
|
|
.WithTempQuery(g => new { MaxId = g.Max(g.Value.Item1.Id), PurchaserId = g.Key.Id, MemberId = g.Key.MemberId }) |
|
|
|
.From<PurchaseSchemeProduct>() |
|
|
|
.InnerJoin((psp2, psp1) => psp2.MaxId == psp1.Id) |
|
|
|
.OrderByDescending((psp2, psp1) => psp1.Id) |
|
|
|
.ToList((psp2, psp1) => psp1); |
|
|
|
.ToList((psp2, psp1) => new |
|
|
|
{ |
|
|
|
psp1.PurchaserId, |
|
|
|
psp2.MemberId, |
|
|
|
psp1.PurchaseProductId |
|
|
|
}); |
|
|
|
|
|
|
|
for (var i = 0; i < pspList.Count; i++) |
|
|
|
{ |
|
|
|
SetInfo($"{i + 1}/{pspList.Count}"); |
|
|
|
|
|
|
|
purchaserId = pspList[i].PurchaserId; |
|
|
|
purchaserMemberId = pspList[i].MemberId; |
|
|
|
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); |
|
|
|
|
|
|
|
Thread.Sleep(10000); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|