Files
29WxOrder/29WxOrderWpf/MainWindow.xaml.cs
T
2026-07-05 22:55:04 +08:00

419 lines
16 KiB
C#

using _29WxOrderWpf.BaseWindows;
using _29WxOrderWpf.Ctrls.BuyerCtrls;
using _29WxOrderWpf.Ctrls.OrderCtrls;
using AllBase;
using AllBase.DouYinModel.Result;
using AllBase.Extension;
using AllBase.Helper;
using AllBase.Model;
using AllBase.Model.Local;
using AllBase.Model.Result;
using CefSharp;
using NaiBa.Util;
using NaiBa.Util.Extension;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml.Linq;
using Work;
using Work._29Tools.BLL;
namespace _29WxOrderWpf
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : BaseWindow
{
public static MainWindow Instance { get; private set; }
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
Instance = this;
gridUser.Visibility = Visibility.Collapsed;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ucWindowBox.SetWindowMax();
this.Title = BaseClass.ToolName;
new Thread(AutoAntiGrabbingMechanism).Start(); // 反抓包
#region 弹出登录窗口
LoginWindows.LoginWindow loginWindow = new LoginWindows.LoginWindow(App.args);
loginWindow.Owner = this;
loginWindow.ShowDialog();
#endregion
if (loginWindow.IsLogin)
{
lblVersion.Content = BaseClass.ToolName + " V" + BaseClass.Varsion + " - " + BaseClass.NickName;
//shopListCtrl.Visibility = Visibility.Visible;
orderListCtrl.Visibility = Visibility.Visible;
pddBuyerOrderReadCtrl.Visibility = Visibility.Visible;
pddBuyerSelectCtrl.Visibility = Visibility.Visible;
Task.Run(() =>
{
GetServerShop();
});
Task.Run(() =>
{
GetPddBuyer();
});
}
}
#region 反抓包功能
private void AutoAntiGrabbingMechanism()
{
while (true)
{
#if DEBUG
#else
AntiGrabbingMechanism();
#endif
try { Thread.Sleep(3000); } catch { }
}
}
[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool IsWow64Process([In] IntPtr process, [Out] out bool wow64Process);
private List<string> _AntiProcesses = "WINRAR,WIRESHARK,FIDDLER,HTTPDEBUGGERPRO,IEHTTPANALYZER,CHARLES,HTTPWATCH,SMARTSNIFF,MINISNIFFER,PROXIFIER,HTTP ANALYZER,SNIFFER,WSOCKEXPERT,IPANALYSE,ANALYZER,HTTP ANALYZER STAND-ALONE EDITION".Split(',').ToList();
private void AntiGrabbingMechanism()
{
//Gate 1 - Anti Proxy
if (IsUseSystemProxy())
{
LockUserAndKillProcess();
}
//Gate 2 - Anti Special Processes
System.Diagnostics.Process[] processList = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process process in processList)
{
try
{
if (_AntiProcesses.Contains(process.ProcessName.ToUpper()))
{
process.Kill();
LockUserAndKillProcess();
}
if (process.MainWindowTitle.Contains("正在捕获"))
{
process.Kill();
LockUserAndKillProcess();
}
if (!IsWin23App(process))
{
continue;
}
if (process.MainModule?.FileVersionInfo.FileDescription != null)
{
foreach (string antiProcess in _AntiProcesses)
{
if (process.MainModule.FileVersionInfo.FileDescription.ToUpper().Contains(antiProcess))
{
process.Kill();
LockUserAndKillProcess();
}
}
}
}
catch (Exception e)
{
}
}
}
private void LockUserAndKillProcess()
{
string url = BaseClass.BuildObjString("user&act=add_user_lock");
string data = UserLogin.GetSignaturex("", "");
string html = GetHtml.PostUtf8(url, data);
Process.GetCurrentProcess().Kill();
}
public static bool IsUseSystemProxy()
{
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
IWebProxy systemWebProxy = WebRequest.GetSystemWebProxy();
FieldInfo field1 = systemWebProxy.GetType().GetField("webProxy", bindingAttr);
if (field1 != (FieldInfo)null)
{
WebProxy webProxy = field1.GetValue((object)systemWebProxy) as WebProxy;
FieldInfo field2 = webProxy.GetType().GetField("_ProxyHostAddresses", bindingAttr);
if (field2 != (FieldInfo)null)
{
Hashtable hashtable = field2.GetValue((object)webProxy) as Hashtable;
if (hashtable != null && hashtable.Count > 0)
return true;
}
}
return false;
}
public bool IsWin23App(Process process)
{
if (Environment.Is64BitOperatingSystem)
{
IntPtr processHandle;
bool retVal;
try
{
processHandle = Process.GetProcessById(process.Id).Handle;
}
catch
{
return false;
}
return IsWow64Process(processHandle, out retVal) && retVal;
}
return true;
}
#endregion
private void BaseWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (BaseMsgWindow.ShowConfirm("是否关闭软件?", "退出微信小店订单管理").DialogResult == true)
Process.GetCurrentProcess().Kill();
else
e.Cancel = true;
}
#region 读取微信店铺
public bool isReadShop { get; set; } = false;
public bool hasReadShop { get; set; } = false;
public void GetServerShop()
{
if (isReadShop)
return;
var tList = new List<Task>();
var cList = new List<int>();
List<ShopLoginInfo> list = new List<ShopLoginInfo>();
Dispatcher.Invoke(new Action(() =>
{
}));
isReadShop = true;
int page = 0;
while (true)
{
page++;
var url = BaseClass.Build29WxObjString("shop/get_shop_list");
var data = UserLogin.GetSignaturex() + "&page=" + page;
data += "&is_get_erp_shop_id=true";
var html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html)
|| !html.Contains("shop_id") || !html.Contains("shop_account") || !html.Contains("login_pass"))
{
break;
}
var jArr = JObject.Parse(html)["data"];
if (jArr.Count() == 0)
break;
foreach (JObject jObj in jArr)
{
var shop = ShopBLL.DeserializationShop(jObj);
var shopExist = list.LastOrDefault(l => l.ShopId == shop.ShopId);
while (shopExist != null)
{
shop.Is29Supplier = shopExist.Is29Supplier;
shop.IsSelect = shopExist.IsSelect;
shop.IsFilter = shopExist.IsFilter;
list.Remove(shopExist);
}
// 更新店铺 // 代发管理中更新
//foreach (var order in GlobalConfig.lstFilterOrder.Where(o => o.shop_id.ParseToString() == shop.ErpShopId).ToList())
//{
// foreach (var orderItem in order.orderItems)
// orderItem.Shop = shop;
//}
list.Add(shop);
if (!GlobalConfig.ShopLoginList.Any(s => s.ShopId == shop.ShopId && !shop.is_point_shop_expire))
{
Dispatcher.Invoke(new Action(() =>
{
GlobalConfig.ShopLoginList.Add(shop);
}));
var t = Task.Run(() =>
{
while (cList.Count > 20) { Thread.Sleep(100); }
cList.Add(1);
try
{
if (shop.LoginStatus == "登录成功")
{
var is29SupplierRst = WxOrderSupplierBLL.GetWxSupplierList(shop);
if (!is29SupplierRst.Contains("\"code\":0"))
is29SupplierRst = WxOrderSupplierBLL.GetWxSupplierList(shop);
if (is29SupplierRst.Contains("\"code\":0") && is29SupplierRst.Contains("\"name\":\"29供货商\""))
{
shop.Is29Supplier = true;
}
else
{
ShopBLL.CheckShopLogin(shop);
shop.Is29Supplier = false;
}
foreach (var order in GlobalConfig.lstFilterOrder.Where(o => o.shop_id.ParseToString() == shop.ErpShopId).ToList())
{
// 更新代发管理情况
foreach (var orderItem in order.orderItems)
Dispatcher.Invoke(new Action(() => { orderItem.UpdateOrderItemBuyButton(); }));
}
}
}
catch
{
}
if (cList.Count > 0)
cList.RemoveAt(0);
});
tList.Add(t);
}
}
}
Dispatcher.Invoke(new Action(() =>
{
foreach (var shop in GlobalConfig.ShopLoginList.Where(s => !list.Any(ss => ss.ShopId == s.ShopId)).ToList())
{
GlobalConfig.ShopLoginList.Remove(shop);
}
foreach (var shop in GlobalConfig.ShopLoginList.Where(s => s.is_point_shop_expire).ToList())
{
GlobalConfig.ShopLoginList.Remove(shop);
}
}));
isReadShop = false;
hasReadShop = true;
while (tList.Where(ta => !ta.IsFaulted && !ta.IsCompleted).Count() >= 1) { tList.RemoveAll(ta => ta.IsFaulted || ta.IsCompleted || ta.IsCanceled); Thread.Sleep(100); }
}
#endregion
#region 读取拼多多买手号
public bool isGetPddBuyer = false;
public bool hasGetPddBuyer = false;
/// <summary>
/// 读取拼多多买手
/// </summary>
public void GetPddBuyer()
{
if (isGetPddBuyer)
return;
isGetPddBuyer = true;
//var ids = dgvBuyer.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colSelect"].Value.ParseToBool() == true).Select(s => s.Cells["colBuyerId"].Value.ParseToString()).ToList();
//Invoke(new Action(() => { pbLoading.Visible = true; }));
try
{
var url = BaseClass.Build29PDDObjString("user/get_buyer");
var data = UserLogin.GetSignaturex();
data += "&page_size=200";
var result = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(result) || !result.Contains("\"code\":200"))
result = GetHtml.PostUtf8(url, data);
if (result.Contains("\"code\":200"))
{
List<BuyerLoginInfo> loginInfoLst = JsonHelper.DeserializeJsonToList<BuyerLoginInfo>(JsonHelper.JObjectParse(result)["data"].ParseToString());
foreach (var buyer in GlobalConfig.PDDBuyerLoginList.Where(bu => !loginInfoLst.Any(b => b.buyer_id == bu.buyer_id)).ToList())
{
Dispatcher.Invoke(new Action(() => { GlobalConfig.PDDBuyerLoginList.Remove(buyer); }));
}
foreach (var b in loginInfoLst)
{
Dispatcher.Invoke(new Action(() =>
{
var buyer = GlobalConfig.PDDBuyerLoginList.FirstOrDefault(bu => bu.buyer_id == b.buyer_id);
if (buyer == null)
GlobalConfig.PDDBuyerLoginList.Add(b);
else
{
buyer.add_time = b.add_time;
buyer.buyer_id = b.buyer_id;
buyer.buyer_name = b.buyer_name;
buyer.buyer_nick = b.buyer_nick;
buyer.cookie = b.cookie;
buyer.mdy_time = b.mdy_time;
buyer.notes = b.notes;
buyer.status = b.status;
buyer.user_name = b.user_name;
}
}));
}
//Invoke(new Action(() =>
//{
//dgvBuyer.Rows.Clear();
//cmbBuyer.Items.Clear();
//}));
foreach (var buyer in GlobalConfig.PDDBuyerLoginList)
{
//Invoke(new Action(() =>
//{
//BindBuyer(buyer, "", ids);
//cmbBuyer.Items.Add(buyer.buyer_nick);
//}));
}
}
}
catch
{
}
//Invoke(new Action(() =>
//{
// pbLoading.Visible = false;
//}));
isGetPddBuyer = false;
hasGetPddBuyer = true;
}
#endregion
}
}