From 8efbccf871a40b67d68b22e887a6e398ec057266 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 14:56:30 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtoken=E8=8E=B7=E5=8F=96?=
=?UTF-8?q?=E9=94=99=E8=AF=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
JdShopListener/JdShopListener/ApiHelper.cs | 12 ++++++++++--
.../JdShopListener/MainWindowViewModel.cs | 10 +++++++---
JdShopListener/JdShopListener/MemoryHelper.cs | 18 ++++++------------
.../PublishProfiles/FolderProfile.pubxml.user | 2 +-
4 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/JdShopListener/JdShopListener/ApiHelper.cs b/JdShopListener/JdShopListener/ApiHelper.cs
index 85fd8e7..635ce96 100644
--- a/JdShopListener/JdShopListener/ApiHelper.cs
+++ b/JdShopListener/JdShopListener/ApiHelper.cs
@@ -1,6 +1,7 @@
using JdShopListener.Models;
using System;
using System.Collections.Generic;
+using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading;
@@ -79,6 +80,7 @@ namespace Utils
HttpClient http = new HttpClient();
http.Timeout = new TimeSpan(0, 0, 35);
http.DefaultRequestHeaders.Add("Authorization", "Bearer " + JwtToken);
+
if (postData!=null)
{
StringContent content = new StringContent(postData);
@@ -100,10 +102,11 @@ namespace Utils
//服务器挂掉
if (res.StatusCode != System.Net.HttpStatusCode.OK)
{
+ MessageBox.Show("非错误:" + res.StatusCode);
if (isAgain)
return null;
- Thread.Sleep(60000);
+ Thread.Sleep(10000);
return Http(api, postData, true);
}
return res.Content.ReadAsStringAsync().Result;
@@ -112,13 +115,18 @@ namespace Utils
}
catch (HttpRequestException ex)
{
+ MessageBox.Show("错误:"+ex.Message);
+
if (isAgain)
return null;
- Thread.Sleep(60000);
+
+ Thread.Sleep(20000);
return Http(api, postData, true);
}
catch (Exception ex)
{
+ MessageBox.Show("出错:"+ex.Message);
+
return null;
}
}
diff --git a/JdShopListener/JdShopListener/MainWindowViewModel.cs b/JdShopListener/JdShopListener/MainWindowViewModel.cs
index 929d593..cbf108f 100644
--- a/JdShopListener/JdShopListener/MainWindowViewModel.cs
+++ b/JdShopListener/JdShopListener/MainWindowViewModel.cs
@@ -161,9 +161,13 @@ namespace JdShopListener
{
IsInitLoding = true;
var result = ApiHelper.GetLabelByItemIds();
-
- AddLog($"检测到{result.datas.Count}个慧眼竞品添加!");
-
+ if (result.isOk)
+ {
+ AddLog($"检测到{result.datas.Count}个慧眼竞品添加!");
+ }
+ else {
+ AddLog($"获取慧眼竞品数据失败!{ApiHelper.JwtToken}");
+ }
result.datas.ForEach(item =>
{
diff --git a/JdShopListener/JdShopListener/MemoryHelper.cs b/JdShopListener/JdShopListener/MemoryHelper.cs
index f540f22..9044700 100644
--- a/JdShopListener/JdShopListener/MemoryHelper.cs
+++ b/JdShopListener/JdShopListener/MemoryHelper.cs
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.IO.MemoryMappedFiles;
using System.Text;
using System.Threading;
+using System.Windows;
namespace Utils
{
@@ -78,24 +80,16 @@ namespace Utils
/// 读取映射文件
///
///
- public static (bool isOk,string content) ReadMMF(string mapname)
+ public static (bool isOk, string content) ReadMMF(string mapname)
{
try
{
MemoryMappedFile mmf = MemoryMappedFile.OpenExisting(mapname);
using (var mmfStream = mmf.CreateViewStream(0, 1000, MemoryMappedFileAccess.ReadWrite))
{
- byte[] buffer = new byte[1000];
- int nLength = 0;
- StringBuilder sb = new StringBuilder();
- do
- {
- nLength = mmfStream.Read(buffer, 0, 1000);
- sb.AppendLine(System.Text.ASCIIEncoding.Default.GetString(buffer));
-
- } while (nLength > 0);
-
- return (true, sb.ToString().Replace("\0", null).TrimEnd());
+ StreamReader reader = new StreamReader(mmfStream);
+ string jwt = reader.ReadToEnd().Trim().Replace("\0","");
+ return (true, jwt);
}
}
catch (Exception ex)
diff --git a/JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user b/JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user
index 272558e..afa15f9 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-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;
+ True|2021-11-13T06:54:09.0591524Z;True|2021-11-13T14:52:48.4056995+08:00;True|2021-11-13T14:51:49.0309726+08:00;True|2021-11-13T14:48:43.2272103+08:00;True|2021-11-13T14:47:27.9721804+08:00;True|2021-11-13T14:45:09.2474573+08:00;True|2021-11-13T14:41:32.7950744+08:00;True|2021-11-13T14:36:57.1688384+08:00;True|2021-11-13T14:34:06.7538906+08:00;True|2021-11-13T11:23:58.1124027+08:00;False|2021-11-13T11:23:39.3148111+08:00;False|2021-11-13T11:22:51.2298917+08:00;True|2021-11-13T10:44:44.3567647+08:00;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