From 31a13baea3379c04df3d493b12dd8f2efe365e8b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A1=C2=B7=C3=A6?= <279202647@qq.com>
Date: Sat, 13 Nov 2021 10:45:58 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96=E5=86=85?=
=?UTF-8?q?=E5=AD=98=E5=85=B1=E4=BA=ABkey=E7=9A=84=E6=B5=81=E7=A8=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../JdShopListener/MainWindowViewModel.cs | 66 ++++++++++++-------
JdShopListener/JdShopListener/MemoryHelper.cs | 25 ++++++-
.../PublishProfiles/FolderProfile.pubxml.user | 2 +-
3 files changed, 64 insertions(+), 29 deletions(-)
diff --git a/JdShopListener/JdShopListener/MainWindowViewModel.cs b/JdShopListener/JdShopListener/MainWindowViewModel.cs
index 658b6c3..929d593 100644
--- a/JdShopListener/JdShopListener/MainWindowViewModel.cs
+++ b/JdShopListener/JdShopListener/MainWindowViewModel.cs
@@ -128,7 +128,6 @@ namespace JdShopListener
webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted;
webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
webClient.DownloadFileTaskAsync("https://qymds.oss-cn-hangzhou.aliyuncs.com/chromium/.local-chromium.zip", System.Environment.CurrentDirectory+"\\tempZip.zip").Wait();
-
}
private void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
@@ -163,7 +162,10 @@ namespace JdShopListener
IsInitLoding = true;
var result = ApiHelper.GetLabelByItemIds();
- result.datas.ForEach(item => {
+ AddLog($"检测到{result.datas.Count}个慧眼竞品添加!");
+
+ result.datas.ForEach(item =>
+ {
var last = skuList.FirstOrDefault(c => c.SkuId == item.GoodsId);
if (last != null)
@@ -175,17 +177,24 @@ namespace JdShopListener
}
}
//新增
- else {
- Application.Current.Dispatcher.Invoke(() => {
+ else
+ {
+ Application.Current.Dispatcher.Invoke(() =>
+ {
InitText = $"正在添加【{item.GoodsId}】...";
});
- AddSku(item.GoodsId);
+ AddSku(item.GoodsId, "慧眼竞品添加");
}
//
});
}
- finally {
+ catch(Exception ex)
+ {
+ AddLog($"慧眼添加异常{ex.Message}\r\n{ex.StackTrace}!");
+ }
+ finally
+ {
IsInitLoding = false;
}
});
@@ -417,7 +426,7 @@ namespace JdShopListener
}
- private void AddSku(string newSku)
+ private void AddSku(string newSku,string desc=null)
{
if (string.IsNullOrEmpty(JDCookie))
{
@@ -446,7 +455,7 @@ namespace JdShopListener
{
SkuModel model = new SkuModel()
{
- Desc = Desc,
+ Desc = desc??Desc,
SkuId = sku["skuId"].ToString(),
SpuId = spuId
};
@@ -1216,30 +1225,37 @@ namespace JdShopListener
// 下载浏览器执行程序
// var fetcher= new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision).Result;
+
+ string url = "https://passport.jd.com/uc/login";
+ // 创建一个浏览器执行实例
+ using var browser = Puppeteer.LaunchAsync(new LaunchOptions
+ {
+ Headless = true,
- string url = "https://passport.jd.com/uc/login";
- // 创建一个浏览器执行实例
- using var browser = Puppeteer.LaunchAsync(new LaunchOptions
+ //Args = new string[] { "--no-sandbox" }
+ }).Result;
+ try
{
- Headless = true,
-
- //Args = new string[] { "--no-sandbox" }
- }).Result;
- // 打开一个页面
- var page = browser.NewPageAsync().Result;
-
+ // 打开一个页面
+ var page = browser.NewPageAsync().Result;
+
var a = page.GoToAsync(url, WaitUntilNavigation.Networkidle0).Result;
- var content = page.GetContentAsync().Result;
- page.DeleteCookieAsync().Wait();
- var cookies = page.GetCookiesAsync().Result;
+ var content = page.GetContentAsync().Result;
+ page.DeleteCookieAsync().Wait();
+ var cookies = page.GetCookiesAsync().Result;
- JDCookie = string.Empty;
+ JDCookie = string.Empty;
- cookies.ToList().ForEach(c =>
+ cookies.ToList().ForEach(c =>
+ {
+ JDCookie += $"{c.Name}={c.Value};";
+ });
+ }
+ catch (Exception ex)
{
- JDCookie += $"{c.Name}={c.Value};";
- });
+ WpfNoticeMsg.NoticeMessage.Show("初始化内核失败,请尝试关闭跟屁虫重新启动!", "错误");
+ }
AddLog("获取到Cookie" + JDCookie);
}
diff --git a/JdShopListener/JdShopListener/MemoryHelper.cs b/JdShopListener/JdShopListener/MemoryHelper.cs
index 567d477..f540f22 100644
--- a/JdShopListener/JdShopListener/MemoryHelper.cs
+++ b/JdShopListener/JdShopListener/MemoryHelper.cs
@@ -2,11 +2,15 @@
using System.Collections.Generic;
using System.IO.MemoryMappedFiles;
using System.Text;
+using System.Threading;
namespace Utils
{
public class MemoryHelper
{
+
+ static int getTokentCount = 0;
+
public static string GetMemoryToken()
{
string memoryName = string.Empty;
@@ -23,15 +27,30 @@ namespace Utils
if (result.isOk)
{
+ if (string.IsNullOrEmpty(result.content))
+ {
+ getTokentCount = getTokentCount + 1;
+ if (getTokentCount <= 3)
+ {
+ Thread.Sleep(300);
+ return GetMemoryToken();
+ }
+ }
return result.content;
}
else
{
+ getTokentCount = getTokentCount + 1;
+ if (getTokentCount <= 3)
+ {
+ Thread.Sleep(300);
+ return GetMemoryToken();
+ }
+
System.Environment.Exit(0);
return string.Empty;
}
}
-
///
/// 写入映射文件
///
@@ -66,12 +85,12 @@ namespace Utils
MemoryMappedFile mmf = MemoryMappedFile.OpenExisting(mapname);
using (var mmfStream = mmf.CreateViewStream(0, 1000, MemoryMappedFileAccess.ReadWrite))
{
- byte[] buffer = new byte[128];
+ byte[] buffer = new byte[1000];
int nLength = 0;
StringBuilder sb = new StringBuilder();
do
{
- nLength = mmfStream.Read(buffer, 0, 128);
+ nLength = mmfStream.Read(buffer, 0, 1000);
sb.AppendLine(System.Text.ASCIIEncoding.Default.GetString(buffer));
} while (nLength > 0);
diff --git a/JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user b/JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user
index 4266d66..272558e 100644
--- a/JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user
+++ b/JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user
@@ -4,6 +4,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
- True|2021-11-12T07:27:50.0418057Z;True|2021-11-12T15:06:23.1220477+08:00;True|2021-11-11T18:06:38.5161322+08:00;True|2021-11-11T17:53:13.2835443+08:00;True|2021-11-11T17:52:00.9170918+08:00;True|2021-11-11T17:51:37.4852682+08:00;True|2021-11-11T17:49:30.9386192+08:00;True|2021-11-11T17:44:28.5146341+08:00;True|2021-11-11T17:42:26.8480671+08:00;True|2021-11-11T17:37:14.4108790+08:00;True|2021-11-11T17:30:25.4460722+08:00;
+ True|2021-11-13T02:44:44.3567647Z;True|2021-11-13T10:42:01.8636514+08:00;True|2021-11-13T10:38:36.0623458+08:00;True|2021-11-13T10:20:29.4761762+08:00;True|2021-11-13T10:08:51.4924474+08:00;True|2021-11-12T15:27:50.0418057+08:00;True|2021-11-12T15:06:23.1220477+08:00;True|2021-11-11T18:06:38.5161322+08:00;True|2021-11-11T17:53:13.2835443+08:00;True|2021-11-11T17:52:00.9170918+08:00;True|2021-11-11T17:51:37.4852682+08:00;True|2021-11-11T17:49:30.9386192+08:00;True|2021-11-11T17:44:28.5146341+08:00;True|2021-11-11T17:42:26.8480671+08:00;True|2021-11-11T17:37:14.4108790+08:00;True|2021-11-11T17:30:25.4460722+08:00;
\ No newline at end of file