Files
KJD_WebService/TEMUKJD/StartUp.cs
T

509 lines
24 KiB
C#

using AllBase;
using AllBase.Extension;
using AllBase.Helper;
using AllBase.Model.Param.CollectManage;
using AllBase.Model.Param.ProductManage;
using AllBase.Model.Param.ShopManage;
using AllBase.Model.Result;
using TemuKJD.KJDForms.BaseForms;
using TemuKJD.KJDForms.ProductForms;
using NaiBa.Util;
using NaiBa.Util.Extension;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Work;
using Work.DouyinApiClass;
using AllBase.Model.Param.TemuProductManage;
using TemuKJD.KJDForms.ShopForms;
namespace TemuKJD
{
public class StartUp
{
public static bool IsShopInit = false;
public static void Init()
{
InitOem();
InitProxy();
GlobalConfig.ProductWords = NaiBa.Util.Helper.ConfigHelper.LoadConfig<TemuProductWords>("product_words");
if (GlobalConfig.ProductWords == null)
GlobalConfig.ProductWords = new TemuProductWords();
#region 抖音账号登录信息
try { GlobalConfig.DouUserCookies = NaiBa.Util.Helper.FileHelper.ReadAllText("data\\config\\dou_user_cookies")?.Trim('\"'); } catch { }
if (GlobalConfig.DouUserCookies == null)
GlobalConfig.DouUserCookies = "";
try { GlobalConfig.DouBuyinCookies = NaiBa.Util.Helper.FileHelper.ReadAllText("data\\config\\dou_buyin_cookies")?.Trim('\"'); } catch { }
if (GlobalConfig.DouBuyinCookies == null)
GlobalConfig.DouBuyinCookies = "";
GlobalConfig.dicLocalStorage = NaiBa.Util.Helper.ConfigHelper.LoadConfig<IDictionary<string, object>>("dou_local_Storage");
if (GlobalConfig.dicLocalStorage == null)
GlobalConfig.dicLocalStorage = new Dictionary<string, object>();
#endregion
#region 获取抖音类目
DyCategoryParam.DyCategorys = Properties.Resources.DyCategorys;
#endregion
#region 读取上传违规词
//FilterForm.LoadFilterWord();
#endregion
#region 数据净化参数
GlobalConfig.FissionSettingParam = NaiBa.Util.Helper.ConfigHelper.LoadConfig<FissionSettingParam>("fission_setting_param");
if (GlobalConfig.FissionSettingParam == null)
{
GlobalConfig.FissionSettingParam = new FissionSettingParam();
}
#endregion
#region 店铺登录信息
Task.Run((Action)(() =>
{
//while (string.IsNullOrEmpty(BaseClass.CompanyName))
while (!BaseClass.IsLoginSuccess)
Thread.Sleep(100);
KJDForms.ShopForms.ShopListForm.UpdateShop();
IsShopInit = true;
//while (true)
//{
// var needRefresh = GlobalConfig.DouShopLoginList.Where(s => s.LastRefreshDate != DateTime.Now.ToString("yyyyMMdd"));
// if (LittleRabbitForms.ShopForms.ShopListForm.Instance == null)
// LittleRabbitForms.ShopForms.ShopListForm.Instance = new LittleRabbitForms.ShopForms.ShopListForm();
// LittleRabbitForms.ShopForms.ShopListForm.Instance.CheckShopListLogin(needRefresh.Select(r => r.ShopAccount).ToArray(), false);
// IsShopInit = true;
// Thread.Sleep(1000 * 3600 * 24); // 每天刷新下验证,如果没关闭软件的话
//}
}));
#endregion
#region 店铺设置参数
GlobalConfig.DouShopSettingParam = NaiBa.Util.Helper.ConfigHelper.LoadConfig<DouShopSettingParam>("dou_shop_setting_param");
if (GlobalConfig.DouShopSettingParam == null)
{
GlobalConfig.DouShopSettingParam = new DouShopSettingParam
{
IsAutoDragLogin = false,
};
}
#endregion
#region 读取违规规则列表
var violateRuleNameSelectList = NaiBa.Util.Helper.ConfigHelper.LoadConfig<List<string>>("violate_rule_name_select");
if (violateRuleNameSelectList != null)
ViolateRuleParam.LstViolateRuleNameSelect = violateRuleNameSelectList;
#endregion
#region 旧店铺商品数据本地缓存 供重复铺货检测使用
GlobalConfig.SameProductCheckParamList = NaiBa.Util.Helper.ConfigHelper.LoadConfig<List<SameProductCheckParam>>("same_product_check_list");
if (GlobalConfig.SameProductCheckParamList == null)
GlobalConfig.SameProductCheckParamList = new List<SameProductCheckParam>();
#endregion
#region 读取店铺历史铺货
Task.Run(() =>
{
while (!IsShopInit)
{
Thread.Sleep(100);
}
//List<Task> tList = new List<Task>();
//var tick = BaseClass.DateTimeToTimestampSeconds(new DateTime(2022, 4, 25));
//while (true)
//{
// if (GlobalConfig.ShopLoginList.All(shop => shop.ApiAuthStatus != "授权成功"
// || GlobalConfig.SameProductCheckParamList.Any(sp => sp.ShopId == shop.ShopId && sp.IsGetSuccess)))
// {
// Thread.Sleep(1000);
// continue;
// }
//
// tList.Clear();
// foreach (var shop in GlobalConfig.ShopLoginList)
// {
// if (GlobalConfig.SameProductCheckParamList.Any(sp => sp.ShopId == shop.ShopId && sp.IsGetSuccess))
// continue;
//
// if (shop.ApiAuthStatus != "授权成功")
// continue;
//
// var t = Task.Run(() =>
// {
// var shopTemp = shop;
// try
// {
// var sameProductCheckParam = GlobalConfig.SameProductCheckParamList.FirstOrDefault(sp => sp.ShopId == shop.ShopId);
// if (sameProductCheckParam == null)
// {
// sameProductCheckParam = new SameProductCheckParam()
// {
// ShopId = shopTemp.ShopId,
// ShopName = shopTemp.ShopAccount,
// ShopSamePrpductItemList = new List<ShopOurterProductItemParam>(),
// };
// }
// for (int i = 1; i <= 500; i++)
// {
// if (sameProductCheckParam.ShopSamePrpductItemList != null && sameProductCheckParam.ShopSamePrpductItemList.Count > 0)
// tick = sameProductCheckParam.ShopSamePrpductItemList.Min(it => it.create_time).ParseToInt() - 1;
//
// DouyinApi douApi = new DouyinApi(shopTemp);
// douApi.JsonData["page"] = "1";
// douApi.JsonData["size"] = "100";
// douApi.JsonData["end_time"] = tick.ToString();
// // check_status 指定审核状态返回商品列表:1未提审 2审核中 3审核通过 4审核驳回 5封禁 7审核通过,待上架状态
// //douApi.JsonData["check_status"] = "3";
// //douApi.JsonData["check_status"] = "1";
// //douApi.JsonData["status"] = "0";
// var resultOnline = douApi.GetProductList();
// if (resultOnline.Contains("已过期"))
// {
// shopTemp.ApiAuthStatus = "未授权";
// return;
// }
// while (!resultOnline.Contains("\"code\":10000"))
// {
// Thread.Sleep(Randomx.GetId(500, 1000) * tList.Count);
// resultOnline = douApi.GetProductList();
// }
// if (resultOnline != null && resultOnline.Contains("\"data\":[]"))
// {
// sameProductCheckParam.IsGetSuccess = true;
// break;
// }
//
// Newtonsoft.Json.Linq.JObject jObj = JsonHelper.JObjectParse(resultOnline);
// var itemList = JsonHelper.DeserializeJsonToList<ShopOurterProductItemParam>(jObj["data"]?["data"]?.ToString());
// sameProductCheckParam.ShopSamePrpductItemList.AddRange(itemList);
//
// if (i % 10 == 9)
// {
// if (!GlobalConfig.SameProductCheckParamList.Contains(sameProductCheckParam))
// GlobalConfig.SameProductCheckParamList.Add(sameProductCheckParam);
// sameProductCheckParam.ShopSamePrpductItemList = sameProductCheckParam.ShopSamePrpductItemList.DistinctBy(it => it.product_id).ToList();
// NaiBa.Util.Helper.ConfigHelper.SaveConfig<List<SameProductCheckParam>>("same_product_check_list", GlobalConfig.SameProductCheckParamList);
// }
//
// Thread.Sleep(Randomx.GetId(500, 1000) * tList.Count);
// }
// if (!GlobalConfig.SameProductCheckParamList.Contains(sameProductCheckParam))
// GlobalConfig.SameProductCheckParamList.Add(sameProductCheckParam);
// sameProductCheckParam.ShopSamePrpductItemList = sameProductCheckParam.ShopSamePrpductItemList.DistinctBy(it => it.product_id).ToList();
// NaiBa.Util.Helper.ConfigHelper.SaveConfig<List<SameProductCheckParam>>("same_product_check_list", GlobalConfig.SameProductCheckParamList);
// }
// catch (Exception ex)
// {
// }
// });
// tList.Add(t);
// }
// Task.WaitAll(tList.ToArray());
//
// Thread.Sleep(10000);
//}
});
#endregion
#region 读取库存信息
Task.Run(() =>
{
while (!IsShopInit)
{
Thread.Sleep(100);
}
ReturnPackageDetailForm retrunPackageForm = new ReturnPackageDetailForm(null);
retrunPackageForm.Show();
retrunPackageForm.Hide();
Dictionary<ShopLoginInfo, string> dicUpReturn = new Dictionary<ShopLoginInfo, string>();
while(true)
{
foreach(var shop in GlobalConfig.ShopLoginList)
{
if (string.IsNullOrEmpty(shop.ShopId))
continue;
if (dicUpReturn.Keys.Contains(shop) && dicUpReturn[shop] == DateTime.Now.ToString("yyyyMMdd")) //今日已获取过
continue;
var rst = retrunPackageForm.GetReturnPackage(shop, true); // 后台读取退货信息
if (rst == false && shop.LoginStatus == "登录成功" && shop.LoginStatus2 == "国际版在线")
{
dicUpReturn[shop] = DateTime.Now.ToString("yyyyMMdd");
}
}
for (int i = 0; i< 3600; i++)
{
Thread.Sleep(1000);
}
}
});
#endregion
}
public static void InitProxy()
{
GetProxyHtml.txtUrl = GetProxyHtml.orderId = "";
if (FileBase.Exists("temp/proxy.txt"))
{
string sAgentIpKey = FileBase.ReadAllText("temp/proxy.txt").Trim();
KJDForms.ToolForms.ProxyForm.InitProxyIp(sAgentIpKey, false);
}
}
/// <summary>
/// 贴牌管理
/// </summary>
public static void InitOem()
{
#region 代理版本获取代理码
if (FileBase.Exists("locales/ig.pak"))
{
BaseClass.AgentCode = FileBase.ReadAllText("locales/ig.pak");
string agTxt = "";
string agVersion = "";
if (FileBase.Exists("locales/igx.pak"))
{
var agTxtArr = FileBase.ReadAllText("locales/igx.pak").Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
agTxt = BaseEncrypt.EncryptDecode(agTxtArr[0], "asdf1357", "vbnm2468");
if (agTxtArr.Length >= 2)
agVersion = BaseEncrypt.EncryptDecode(agTxtArr[1], "asdf1357", "vbnm2468");
}
if (!agTxt.Contains("oem_title")
|| !agTxt.Contains("oem_register")
|| !agTxt.Contains("oem_reset")
|| !agTxt.Contains("oem_notice")
|| !agTxt.Contains("oem_video")
|| !agTxt.Contains("oem_logo_link")
|| !agTxt.Contains("oem_icon_link"))
{
agTxt = "";
agVersion = "";
}
// 获取贴牌版本号
string url = BaseClass.BuildObjString("oem_config&act=get_version");
string data = UserLogin.GetSignaturex("", "") + "&agent_code=" + BaseClass.AgentCode;
string html = GetHtml.PostUtf8(url, data);
if (!string.IsNullOrEmpty(html) && html != agVersion)
{
agTxt = "";
agVersion = html;
}
if (!html.Contains("\"code\":200"))
{
var msg = BaseRegex.GetStringJson(ref html, "msg");
//BaseMsgForm.ShowError("获取版本信息失败,请检查电脑时间!");
BaseMsgForm.ShowError(msg);
Process.GetCurrentProcess().Kill();
return;
}
if (string.IsNullOrEmpty(agTxt))
{
// 根据代理码给贴牌信息赋值
url = BaseClass.BuildObjString("oem_config&act=get_config_info");
data = UserLogin.GetSignaturex("", "") + "&agent_code=" + BaseClass.AgentCode;
agTxt = GetHtml.PostUtf8(url, data);
if (!agTxt.Contains("\"code\":200"))
{
var msg = BaseRegex.GetStringJson(ref html, "msg");
BaseMsgForm.ShowError(msg);
Process.GetCurrentProcess().Kill();
return;
}
File.WriteAllText("locales/igx.pak",
BaseEncrypt.EncryptEncode(agTxt, "asdf1357", "vbnm2468") + "\r\n" + BaseEncrypt.EncryptEncode(agVersion, "asdf1357", "vbnm2468"));
}
if (!string.IsNullOrEmpty(agTxt) && agTxt.Contains("获取配置信息成功"))
{
var oem_title = BaseRegex.GetStringJson(ref agTxt, "oem_title");
var oem_register = BaseRegex.GetStringJson(ref agTxt, "oem_register");
var oem_reset = BaseRegex.GetStringJson(ref agTxt, "oem_reset");
var oem_notice = BaseRegex.GetStringJson(ref agTxt, "oem_notice");
var oem_video = BaseRegex.GetStringJson(ref agTxt, "oem_video");
var oem_pay = BaseRegex.GetStringJson(ref agTxt, "oem_pay");
var oem_pay_ip = BaseRegex.GetStringJson(ref agTxt, "oem_pay_ip");
var oem_logo_link = BaseRegex.GetStringJson(ref agTxt, "oem_logo_link");
var oem_icon_link = BaseRegex.GetStringJson(ref agTxt, "oem_icon_link");
var oem_mobile = BaseRegex.GetStringJson(ref agTxt, "oem_mobile");
var oem_open = BaseRegex.GetStringJson(ref agTxt, "oem_open");
var oem_header_name = BaseRegex.GetStringJson(ref agTxt, "oem_header_name");
var oem_qq = BaseRegex.GetStringJson(ref agTxt, "oem_qq");
// 软件标题
if (!string.IsNullOrEmpty(oem_title))
{
BaseClass.ToolName = oem_title;
}
// 开放注册
if (!string.IsNullOrEmpty(oem_register))
{
BaseClass.IsShowRegister = oem_register == "1";
}
// 开户续费
if (!string.IsNullOrEmpty(oem_open))
{
BaseClass.IsShowOpenAccount = oem_open == "1";
}
//// 找回密码
//if (!string.IsNullOrEmpty(oem_reset))
//{
// BaseClass.IsShowForgetPwd = oem_reset == "1";
//}
//// 公告显示
//if (!string.IsNullOrEmpty(oem_notice))
//{
// BaseClass.IsHideAnnounce = oem_notice == "0";
//}
//// 视频显示
//if (!string.IsNullOrEmpty(oem_video))
//{
// BaseClass.IsShowGuidance = oem_video == "1";
//}
//// 充值元宝
//if (!string.IsNullOrEmpty(oem_pay))
//{
// BaseClass.IsShowRecharge = oem_pay == "1";
//}
//// 代理ip
//if (!string.IsNullOrEmpty(oem_pay_ip))
//{
// BaseClass.IsShowBuyProxyIp = oem_pay_ip == "1";
//}
// logo图片地址
if (!string.IsNullOrEmpty(oem_logo_link))
{
try
{
var bitmapBG = (Bitmap)Properties.Resources.ResourceManager.GetObject("login_bg_agent");
var img = GetHtml.LoadImage(oem_logo_link);
Graphics g = Graphics.FromImage(bitmapBG);
g.DrawImage(img, new Rectangle(bitmapBG.Width / 2 - img.Width / 2, bitmapBG.Height / 2 - img.Height / 2, img.Width, img.Height));
var imgBytes = ImageBuild.BitmapToBytes(bitmapBG);
img.Dispose();
g.Dispose();
GetHtml.LoadImage(oem_logo_link);
// 登录窗口图标
BaseClass.LoginImage = ImageBuild.BytesToImage(imgBytes);
// 主窗体图标
BaseClass.LogoImage = GetHtml.LoadImage(oem_logo_link);
}
catch
{
}
if (BaseClass.LoginImage == null || BaseClass.LogoImage == null)
{
BaseMsgForm.ShowError("获取版本信息失败,请检查电脑联网状态或电脑时间!");
Process.GetCurrentProcess().Kill();
return;
}
}
// icon图片地址
if (!string.IsNullOrEmpty(oem_icon_link))
{
BaseClass.Ico = GetHtml.LoadIcon(oem_icon_link);
if (BaseClass.Ico == null)
{
BaseMsgForm.ShowError("获取版本信息失败,请检查电脑联网状态或电脑时间!");
Process.GetCurrentProcess().Kill();
return;
}
}
// 客服QQ(或电话)
if (!string.IsNullOrEmpty(oem_qq))
{
BaseClass.ServiceQQ = oem_qq;
}
//if (!string.IsNullOrEmpty(oem_header_name))
//{
// BaseClass.oem_header = oem_header_name;
//}
}
}
#endregion
}
public static void SaveFissionSettingParam()
{
NaiBa.Util.Helper.ConfigHelper.SaveConfig("fission_setting_param", GlobalConfig.FissionSettingParam);
}
public static void SaveLocalShopLoginInfo()
{
ConcurrentList<ShopLoginInfo> shopLoginListCopy =
JsonHelper.DeserializeJsonToObject<ConcurrentList<ShopLoginInfo>>(JsonHelper.SerializeObject(GlobalConfig.ShopLoginList));
shopLoginListCopy.AddRange(GlobalConfig.DouShopLoginOtherUserShopList);
// 替换掉密码,cookie等敏感参数
foreach (var shop in shopLoginListCopy)
{
shop.Password = "";
shop.Cookies = "";
}
NaiBa.Util.Helper.ConfigHelper.SaveConfig("dou_shop_login", shopLoginListCopy);
}
public static void SaveDouShopSettingParam()
{
NaiBa.Util.Helper.ConfigHelper.SaveConfig("dou_shop_setting_param", GlobalConfig.DouShopSettingParam);
}
/// <summary>
/// 保存抖音采集用户cookie
/// </summary>
public static void SaveDouUserCookies()
{
NaiBa.Util.Helper.ConfigHelper.SaveConfig("dou_user_cookies", GlobalConfig.DouUserCookies);
}
public static void SaveDouBuyinCookies()
{
NaiBa.Util.Helper.ConfigHelper.SaveConfig("dou_buyin_cookies", GlobalConfig.DouBuyinCookies);
}
public static void SaveDouLocalStorage()
{
if (GlobalConfig.dicLocalStorage != null)
NaiBa.Util.Helper.ConfigHelper.SaveConfig<IDictionary<string, object>>("dou_local_Storage", GlobalConfig.dicLocalStorage);
}
public static void SaveDouLocalDetailStorage()
{
if (GlobalConfig.dicLocalDetailStorage != null)
NaiBa.Util.Helper.ConfigHelper.SaveConfig<IDictionary<string, object>>("dou_local_detail_Storage", GlobalConfig.dicLocalDetailStorage);
}
public static void SaveViolateRuleNameSelectList()
{
if (ViolateRuleParam.LstViolateRuleNameSelect != null)
NaiBa.Util.Helper.ConfigHelper.SaveConfig<List<string>>("violate_rule_name_select", ViolateRuleParam.LstViolateRuleNameSelect);
}
public static void SaveProductWords()
{
NaiBa.Util.Helper.ConfigHelper.SaveConfig("product_words", GlobalConfig.ProductWords);
}
}
}