Commit 36ad5bcd authored by Damon's avatar Damon

修改接口

parent e8774519
using System.Data; using Dqkj.Setup;
using System.Collections.Generic;
using System.Data;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
...@@ -8,18 +10,51 @@ namespace Setup.Common ...@@ -8,18 +10,51 @@ namespace Setup.Common
{ {
internal class ApiHelper internal class ApiHelper
{ {
private const string _url = "https://b.dqukj.com/api/client/product/list?productId=P00687"; //private const string _url = "https://b.dqukj.com/api/client/product/list?productId=P00687";
private static readonly string _ossRequestHost = "https://http-2023.oss-cn-shenzhen.aliyuncs.com/crm";
private static readonly HttpClient _httpClient = new HttpClient(); private static readonly HttpClient _httpClient = new HttpClient();
public static string AppLauncherName { get; private set; }
public static async Task<string> CheckAsync() private static async Task<List<string>> GetOssIps()
{ {
var ret = await _httpClient.GetAsync(_url); HttpResponseMessage response = await _httpClient.GetAsync(_ossRequestHost);
ret.EnsureSuccessStatusCode();
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var data = await response.Content.ReadAsStringAsync();
if (!string.IsNullOrEmpty(data))
{
return data.TrimStart('[').TrimEnd(']').Split(',').Select(x => x.Trim('"')).ToList();
}
}
return null;
}
var response = await ret.Content.ReadAsStringAsync();
var lastFile = GetValue(response, "lastFile"); public static async Task<string> CheckAsync()
return lastFile; {
string _tempIp = Utils.ArrayRandomItem(await GetOssIps());
if (string.IsNullOrEmpty(_tempIp)) return default;
int i = 20;
while (i > 0)
{
var ret = await _httpClient.GetAsync($@"http://{_tempIp}/client/product/list?productId=P00687");
if (ret.StatusCode == System.Net.HttpStatusCode.OK)
{
var response = await ret.Content.ReadAsStringAsync();
var lastFile = GetValue(response, "lastFile");
AppLauncherName = new Regex(@"(?<=\""launcherName\"":\"")[^\""]+(?=\"")").Match(response)?.Value;
return lastFile;
}
else
{
_tempIp = Utils.ArrayRandomItem(await GetOssIps());
i--;
continue;
}
}
return null;
} }
private static string GetValue(string input, string key) private static string GetValue(string input, string key)
......
...@@ -28,7 +28,7 @@ namespace Dqkj.Setup.Common ...@@ -28,7 +28,7 @@ namespace Dqkj.Setup.Common
{ {
if (process.ProcessName.ToLower() == name.ToLower()) if (process.ProcessName.ToLower() == name.ToLower())
{ {
MessageBox.Show(process.ProcessName); //MessageBox.Show(process.ProcessName);
return true; return true;
} }
} }
......
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -132,5 +134,23 @@ namespace Dqkj.Setup ...@@ -132,5 +134,23 @@ namespace Dqkj.Setup
return flag; return flag;
} }
public static T ArrayRandomItem<T>(List<T> sources)
{
if (sources == null) return default;
Random rd = new Random();
T temp;
for (int i = 0; i < sources.Count; i++)
{
int index = rd.Next(0, sources.Count - 1);
if (index != i)
{
temp = sources[i];
sources[i] = sources[index];
sources[index] = temp;
}
}
return sources.FirstOrDefault();
}
} }
} }
...@@ -50,5 +50,5 @@ using System.Windows; ...@@ -50,5 +50,5 @@ using System.Windows;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示: //通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.0.5")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.5")]
...@@ -46,7 +46,7 @@ namespace Dqkj.Setup ...@@ -46,7 +46,7 @@ namespace Dqkj.Setup
//#endif //#endif
defaultUpdateXmlUrl = await ApiHelper.CheckAsync(); defaultUpdateXmlUrl = await ApiHelper.CheckAsync();
executeName = "电趣助手.exe"; executeName = ApiHelper.AppLauncherName ?? "DqBox.exe";
formTitle = $"电趣助手-自动更新"; formTitle = $"电趣助手-自动更新";
} }
...@@ -110,17 +110,17 @@ namespace Dqkj.Setup ...@@ -110,17 +110,17 @@ namespace Dqkj.Setup
//if (md5 == serverVersion.Md5) //if (md5 == serverVersion.Md5)
//{ //{
DecompressZip(zip_temp, _installPath); //解压升级包 DecompressZip(zip_temp, _installPath); //解压升级包
//DirectoryHelper.CopyDirectory(unzip_temp, app); //替换进app目录中 //DirectoryHelper.CopyDirectory(unzip_temp, app); //替换进app目录中
VersionInfo localVersion = new VersionInfo(); VersionInfo localVersion = new VersionInfo();
//替换新版本号 //替换新版本号
//localVersion.Version = serverVersion.Version; //localVersion.Version = serverVersion.Version;
//刷新、保存本地版本信息 //刷新、保存本地版本信息
//localVersion.Version = serverVersion.Version; //localVersion.Version = serverVersion.Version;
File.WriteAllText(Path.Combine(_installPath, "version.xml"), Encrypt.DesEncrypt(XmlHelper.Serializer<VersionInfo>(localVersion))); File.WriteAllText(Path.Combine(_installPath, "version.xml"), Encrypt.DesEncrypt(XmlHelper.Serializer<VersionInfo>(localVersion)));
Completed(); Completed();
//} //}
//else //else
//{ //{
...@@ -153,7 +153,7 @@ namespace Dqkj.Setup ...@@ -153,7 +153,7 @@ namespace Dqkj.Setup
process.StartInfo = startInfo; process.StartInfo = startInfo;
process.Start(); process.Start();
Environment.Exit(-1); Environment.Exit(-1);
} }
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment