Files
KJD_WebService/KJD_WebService/BLL/KJD/UpdateManage.cs
T
2026-08-26 15:46:32 +08:00

271 lines
15 KiB
C#

using KJD_Web.Utils;
using NaiBa.Util.Extension;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
namespace KJD_Web.BLL
{
public class UpdateManage
{
public string GetUpdate(string inputData)
{
//string time1 = Encryption(time);
//return "time=" + time + "&code=" + time1 + "&NbCodeVersion=1" + "&version=" + BaseClass.VersionCount
if (!string.IsNullOrEmpty(inputData))
{
var time = 0;
int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time);
string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
if (time1 != EncrypUtil.Encryption(time))
return "{\"code\":50000,\"msg\":\"校验失败\"}";
var version = RegexUtils.GetStringQuery(ref inputData, "version").ParseToInt();
var serverVersion = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateVersion"].ConnectionString;
var UpdateFiles = ""; //System.Configuration.ConfigurationManager.ConnectionStrings["UpdateFiles"].ConnectionString;
var UpdateExe = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateExe"].ConnectionString;
var UpdateExeChk = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateExeChk"].ConnectionString;
var LowVersion = System.Configuration.ConfigurationManager.ConnectionStrings["LowVersion"].ConnectionString;
serverVersion = "1115";
UpdateFiles = "http://weidian.e57.cn/kjd_update/Update1115.zip";
if (version > LowVersion.ParseToInt())
{
return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk +
"\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + UpdateFiles + "\"}";
}
else if (version > 0)
{
return "{\"code\":501,\"msg\":\"版本过低已无法直接升级,请联系管理员获取最新安装包\"}";
}
else
{
return "{\"code\":502,\"msg\":\"get update version failed\"}";
}
}
return "{\"code\":19999,\"msg\":\"未知错误\"}";
}
public string GetUpdateNew(string inputData)
{
//string time1 = Encryption(time);
//return "time=" + time + "&code=" + time1 + "&NbCodeVersion=1" + "&version=" + BaseClass.VersionCount
if (!string.IsNullOrEmpty(inputData))
{
var time = 0;
int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time);
string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
if (time1 != EncrypUtil.Encryption(time))
return "{\"code\":50000,\"msg\":\"校验失败\"}";
var path = RegexUtils.GetStringQuery(ref inputData, "path");
var version = RegexUtils.GetStringQuery(ref inputData, "version").ParseToInt();
var serverVersion = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateVersion"].ConnectionString;
var UpdateNewUrl = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateNewUrl"].ConnectionString;
var UpdateExe = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateExe"].ConnectionString;
var UpdateExeChk = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateExeChk"].ConnectionString;
var LowVersion = System.Configuration.ConfigurationManager.ConnectionStrings["LowVersion"].ConnectionString;
int MaxVersion = 999999;
if (version <= 1200)
MaxVersion = 1200;
if (version <= 1159)
MaxVersion = 1159;
if (version > LowVersion.ParseToInt())
{
if (path != null)
{
try
{
var fileDir = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateFileDir"].ConnectionString;
if (path == "29wx")
{
var versionTmp = 0;
//var file = Directory.GetFiles(fileDir);
//foreach (var f in file)
//{
// var v = Path.GetFileName(f).Replace("Update29wx", "").Replace(".zip", "").ParseToInt();
// if (v > versionTmp && v <= serverVersion.ParseToInt() && v <= MaxVersion)
// {
// versionTmp = v;
// }
//}
var f = GetVersionCodeAndFileFromE57();
var v = Path.GetFileName(f).Replace("Update29wx", "").Replace(".zip", "").ParseToInt();
if (v > versionTmp && v <= serverVersion.ParseToInt() && v <= MaxVersion)
{
versionTmp = v;
}
if (versionTmp > 0)
{
serverVersion = versionTmp.ToString();
//return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk +
// "\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + UpdateNewUrl + "Update" + serverVersion + ".zip\"}";
return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk +
"\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + f.Replace("29wx" + serverVersion, serverVersion) + "\"}";
}
}
if (path == "29pdd")
{
var file = Directory.GetFiles(fileDir);
var versionTmp = 0;
foreach (var f in file)
{
var v = Path.GetFileName(f).Replace("Update29pdd", "").Replace(".zip", "").ParseToInt();
if (v > versionTmp && v <= serverVersion.ParseToInt() && v <= MaxVersion)
{
versionTmp = v;
}
}
if (versionTmp > 0)
{
serverVersion = versionTmp.ToString();
return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk +
"\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + UpdateNewUrl + "Update" + serverVersion + ".zip\"}";
}
}
}
catch (Exception ex)
{
//return "{\"code\":500,\"msg\":\"升级文件查询失败\"}";
}
}
if (serverVersion.ParseToInt() > MaxVersion)
serverVersion = MaxVersion.ParseToString();
return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk +
"\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + UpdateNewUrl + "Update" + serverVersion + ".zip\"}";
}
else if (version > 0)
{
return "{\"code\":501,\"msg\":\"版本过低已无法直接升级,请联系管理员获取最新安装包\"}";
}
else
{
return "{\"code\":502,\"msg\":\"get update version failed\"}";
}
}
return "{\"code\":19999,\"msg\":\"未知错误\"}";
}
public string GetVersionCodeAndFileFromE57()
{
var url = "https://update.e57.cn/api/latest?channel=stable";
var versionRst = HttpUtils.e57GetResponse(url, "");
var json = JsonUtils.JObjectParse(versionRst);
var data = json.GetValue("data") as Newtonsoft.Json.Linq.JObject;
string sha256 = (data["package"]?["sha256"]).ParseToString();
string latestVersion = data.GetValue("version").ParseToString();
string downloadUrl = (data["package"]?["downloadUrl"]).ParseToString();
return downloadUrl;
}
public string GetWxFindOrderUpdate(string inputData)
{
//string time1 = Encryption(time);
//return "time=" + time + "&code=" + time1 + "&NbCodeVersion=1" + "&version=" + BaseClass.VersionCount
if (!string.IsNullOrEmpty(inputData))
{
var time = 0;
int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time);
string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
if (time1 != EncrypUtil.Encryption(time))
return "{\"code\":50000,\"msg\":\"校验失败\"}";
var path = RegexUtils.GetStringQuery(ref inputData, "path");
var version = RegexUtils.GetStringQuery(ref inputData, "version").ParseToInt();
var serverVersion = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateVersion"].ConnectionString;
var UpdateFileNewUrl = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateWxFindOrderUrl"].ConnectionString;
var UpdateExe = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateExe"].ConnectionString;
var UpdateExeChk = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateExeChk"].ConnectionString;
var LowVersion = System.Configuration.ConfigurationManager.ConnectionStrings["WxFindOrderLowVersion"].ConnectionString;
if (version > LowVersion.ParseToInt())
{
//if (path != null)
{
try
{
var fileDir = System.Configuration.ConfigurationManager.ConnectionStrings["UpdateWxFindOrderFileDir"].ConnectionString;
//if (path == "29wx")
{
var versionTmp = 0;
//var file = Directory.GetFiles(fileDir);
//foreach (var f in file)
//{
// var v = Path.GetFileName(f).Replace("WxFindOrderUpdate", "").Replace(".zip", "").ParseToInt();
// if (v > versionTmp && v <= serverVersion.ParseToInt())
// {
// versionTmp = v;
// }
//}
var f = GetWxOrderVersionCodeAndFileFromE57();
var v = Path.GetFileName(f).Replace("WxFindOrderUpdate", "").Replace(".zip", "").ParseToInt();
if (v > versionTmp && v <= serverVersion.ParseToInt())
{
versionTmp = v;
}
if (versionTmp > 0)
{
serverVersion = versionTmp.ToString();
//return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk +
// "\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + UpdateFileNewUrl + "WxFindOrderUpdate" + serverVersion + ".zip\"}";
return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk +
"\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + f + "\"}";
}
}
}
catch (Exception ex)
{
return "{\"code\":500,\"msg\":\"升级文件查询失败\"}";
}
}
//if (serverVersion.ParseToInt() > 1159)
// serverVersion = 1159.ToString();
//return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk +
// "\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + UpdateFileNewUrl + "WxFindOrderUpdate" + serverVersion + ".zip\"}";
}
else if (version > 0)
{
return "{\"code\":501,\"msg\":\"版本过低已无法直接升级,请联系管理员获取最新安装包\"}";
}
else
{
return "{\"code\":502,\"msg\":\"get update version failed\"}";
}
}
return "{\"code\":19999,\"msg\":\"未知错误\"}";
}
public string GetWxOrderVersionCodeAndFileFromE57()
{
var url = "https://update-wx-order.e57.cn/api/latest?channel=stable";
var versionRst = HttpUtils.e57GetResponse(url, "");
var json = JsonUtils.JObjectParse(versionRst);
var data = json.GetValue("data") as Newtonsoft.Json.Linq.JObject;
string sha256 = (data["package"]?["sha256"]).ParseToString();
string latestVersion = data.GetValue("version").ParseToString();
string downloadUrl = (data["package"]?["downloadUrl"]).ParseToString();
return downloadUrl;
}
}
}