Browse Source

修复token获取错误

master
С·æ 4 years ago
parent
commit
8efbccf871
  1. 12
      JdShopListener/JdShopListener/ApiHelper.cs
  2. 10
      JdShopListener/JdShopListener/MainWindowViewModel.cs
  3. 18
      JdShopListener/JdShopListener/MemoryHelper.cs
  4. 2
      JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user

12
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;
}
}

10
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 =>
{

18
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
/// 读取映射文件
/// </summary>
/// <param name="mapname"></param>
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)

2
JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user

@ -4,6 +4,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<History>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;</History>
<History>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;</History>
</PropertyGroup>
</Project>
Loading…
Cancel
Save