diff --git a/BBWY.Client/APIServices/ShopService.cs b/BBWY.Client/APIServices/ShopService.cs index 5091da2b..0d630ce7 100644 --- a/BBWY.Client/APIServices/ShopService.cs +++ b/BBWY.Client/APIServices/ShopService.cs @@ -77,5 +77,15 @@ namespace BBWY.Client.APIServices }, HttpMethod.Post); } + public ApiResponse> GetServiceGroupList() + { + return SendRequest>(globalContext.BBYWApiHost, "api/vender/GetServiceGroupList", new + { + globalContext.User.Shop.Platform, + globalContext.User.Shop.AppKey, + globalContext.User.Shop.AppSecret, + globalContext.User.Shop.AppToken, + }, null, HttpMethod.Post); + } } } diff --git a/BBWY.Client/App.xaml.cs b/BBWY.Client/App.xaml.cs index 19c763b4..efb3658e 100644 --- a/BBWY.Client/App.xaml.cs +++ b/BBWY.Client/App.xaml.cs @@ -11,6 +11,7 @@ using System.IO.MemoryMappedFiles; using System.Linq; using System.Net.Http; using System.Reflection; +using System.Security.Principal; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -25,8 +26,18 @@ namespace BBWY.Client public IServiceProvider ServiceProvider { get; private set; } public IConfiguration Configuration { get; private set; } + public bool IsAdministrator() + { + WindowsIdentity current = WindowsIdentity.GetCurrent(); + WindowsPrincipal windowsPrincipal = new WindowsPrincipal(current); + return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator); + } + protected override void OnStartup(StartupEventArgs e) - { + { + var isAdmin = IsAdministrator(); + Console.WriteLine($"run as admin : {isAdmin}"); + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var gl = new GlobalContext(); string userToken = string.Empty; @@ -87,7 +98,7 @@ namespace BBWY.Client { AutomaticDecompression = System.Net.DecompressionMethods.GZip }); - + serviceCollection.AddMemoryCache(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(gl); diff --git a/BBWY.Client/BBWY.Client.csproj b/BBWY.Client/BBWY.Client.csproj index 34fa3294..71580690 100644 --- a/BBWY.Client/BBWY.Client.csproj +++ b/BBWY.Client/BBWY.Client.csproj @@ -1,10 +1,11 @@  - WinExe + Exe netcoreapp3.1 true Resources\Images\bbwylogo.ico + app.manifest @@ -28,6 +29,7 @@ + @@ -55,4 +57,19 @@ + + + True + True + Settings.settings + + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + diff --git a/BBWY.Client/GlobalContext.cs b/BBWY.Client/GlobalContext.cs index f76fcbaf..2471497c 100644 --- a/BBWY.Client/GlobalContext.cs +++ b/BBWY.Client/GlobalContext.cs @@ -7,9 +7,7 @@ namespace BBWY.Client { public GlobalContext() { - DongDongServiceNameList = new List(); - - + ShopServiceGroupList = new List(); } private User user; @@ -20,7 +18,7 @@ namespace BBWY.Client public IList LogisticsResponseList { get; set; } - public IList DongDongServiceNameList { get; set; } + public IList ShopServiceGroupList { get; set; } /// /// JD客户端 diff --git a/BBWY.Client/Helpers/CSharpAPIs.cs b/BBWY.Client/Helpers/CSharpAPIs.cs new file mode 100644 index 00000000..e26ef855 --- /dev/null +++ b/BBWY.Client/Helpers/CSharpAPIs.cs @@ -0,0 +1,239 @@ + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace QYDongDongTool +{ + public class CSharpAPIs + { + private delegate bool WNDENUMPROC(IntPtr hWnd, int lParam); + [DllImport("user32.dll")] + private static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, int lParam); + //[DllImport("user32.dll")] + //private static extern IntPtr FindWindowW(string lpClassName, string lpWindowName); + [DllImport("user32.dll")] + private static extern int GetWindowTextW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpString, int nMaxCount); + [DllImport("user32.dll")] + private static extern int GetClassNameW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpString, int nMaxCount); + + + [DllImport("User32.dll", CharSet = CharSet.Auto)] + public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID); + + + [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)] + public static extern int ShowWindow(IntPtr hwnd, int nCmdShow); + + [DllImport("user32.dll")] + public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndlnsertAfter, int X, int Y, int cx, int cy, uint Flags); + + [DllImport("user32.dll", EntryPoint = "SetParent")] + public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent); + + [DllImport("user32.dll", CharSet = CharSet.Auto)] + public static extern int MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool BRePaint); + + + [DllImport("user32.dll")] + public static extern IntPtr GetTopWindow(IntPtr hWnd); + + [DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "GetWindow", SetLastError = true)] + public static extern IntPtr GetNextWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.U4)] int wFlag); + + [DllImport("user32.dll", EntryPoint = "GetDesktopWindow", CharSet = CharSet.Auto, SetLastError = true)] + public static extern IntPtr GetDesktopWindow(); + + [DllImport("user32.dll", EntryPoint = "GetWindowLong")] + private static extern IntPtr GetWindowLongPtr32(IntPtr hWnd, int nIndex); + + [DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")] + private static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex); + + // This static method is required because Win32 does not support + // GetWindowLongPtr directly + public static IntPtr GetWindowLong(IntPtr hWnd, int nIndex) + { + if (IntPtr.Size == 8) + return GetWindowLongPtr64(hWnd, nIndex); + else + return GetWindowLongPtr32(hWnd, nIndex); + } + + + public static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong) + { + if (IntPtr.Size == 8) + return SetWindowLongPtr64(hWnd, nIndex, dwNewLong); + else + return new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32())); + } + + [DllImport("user32.dll", EntryPoint = "SetWindowLong")] + private static extern int SetWindowLong32(IntPtr hWnd, int nIndex, int dwNewLong); + + [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")] + private static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong); + + [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] + public static extern IntPtr GetForegroundWindow(); + + [DllImport("user32.dll")] + public static extern bool SetForegroundWindow(IntPtr hWnd); + + + //根据窗口来获取进程ID, + public static int GetCurrentProcessID(IntPtr handle) + { + GetWindowThreadProcessId(handle, out int oo); + return oo; + } + public struct WindowInfo + { + public IntPtr hWnd; + public string szWindowName; + public string szClassName; + public int ProcessId { get; set; } + + public int Width { get; set; } + + public int Height { get; set; } + + public int X { get; set; } + + public int Y { get; set; } + } + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect); + + [StructLayout(LayoutKind.Sequential)] + public struct RECT + { + public int Left; //最左坐标 + public int Top; //最上坐标 + public int Right; //最右坐标 + public int Bottom; //最下坐标 + } + + + public static (int width, int height, int x, int y) GetWindowSize(IntPtr hwnd) + { + RECT rc = new RECT(); + GetWindowRect(hwnd, ref rc); + + int width = rc.Right - rc.Left; //窗口的宽度 + int height = rc.Bottom - rc.Top; //窗口的高度 + int x = rc.Left; + int y = rc.Top; + + + return (width, height, x, y); + } + + + + + /* + SetWindowLong(ChildWindowHandle, GWL_EXSTYLE, (GetWindowLong(ChildWindowHandle, GWL_EXSTYLE) | WS_EX_NOPARENTNOTIFY)); + */ + public enum GWL + { + GWL_WNDPROC = (-4), + GWL_HINSTANCE = (-6), + GWL_HWNDPARENT = (-8), + GWL_STYLE = (-16), + GWL_EXSTYLE = (-20), + GWL_USERDATA = (-21), + GWL_ID = (-12) + } + + public static bool ReSetParent(IntPtr hWnd) + { + int row= SetParent(hWnd, GetDesktopWindow()); + MoveWindow(hWnd, 0, 0, 0, 0, true); + return row > 0; + } + + + public static WindowInfo GetWindowInfo(IntPtr hWnd) + { + WindowInfo wnd = new WindowInfo(); + StringBuilder sb = new StringBuilder(256); + //get hwnd + wnd.hWnd = hWnd; + //get window name + GetWindowTextW(hWnd, sb, sb.Capacity); + wnd.szWindowName = sb.ToString(); + //get window class + GetClassNameW(hWnd, sb, sb.Capacity); + wnd.szClassName = sb.ToString(); + wnd.ProcessId = GetCurrentProcessID(hWnd); + + var size = GetWindowSize(hWnd); + wnd.Width = size.width; + wnd.Height = size.height; + wnd.X = size.x; + wnd.Y = size.y; + + return wnd; + } + + + public List GetAllDesktopWindows() + { + List wndList = new List(); + + //enum all desktop windows + EnumWindows(delegate (IntPtr hWnd, int lParam) + { + WindowInfo wnd = new WindowInfo(); + StringBuilder sb = new StringBuilder(256); + //get hwnd + wnd.hWnd = hWnd; + //get window name + GetWindowTextW(hWnd, sb, sb.Capacity); + wnd.szWindowName = sb.ToString(); + //get window class + GetClassNameW(hWnd, sb, sb.Capacity); + wnd.szClassName = sb.ToString(); + wnd.ProcessId = GetCurrentProcessID(hWnd); + + var (width, height, x, y) = GetWindowSize(hWnd); + wnd.Width = width; + wnd.Height = height; + wnd.X = x; + wnd.Y = y; + + //add it into list + wndList.Add(wnd); + return true; + }, 0); + + return wndList; + } + //获取窗体位置 最小化 最大化 隐藏 api + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl); + + + + } + +} + +public struct WINDOWPLACEMENT +{ + public int length; + public int flags; + public int showCmd; + public System.Drawing.Point ptMinPosition; + public System.Drawing.Point ptMaxPosition; + public System.Drawing.Rectangle rcNormalPosition; +} diff --git a/BBWY.Client/Helpers/DongDongHelper.cs b/BBWY.Client/Helpers/DongDongHelper.cs new file mode 100644 index 00000000..7f27c90a --- /dev/null +++ b/BBWY.Client/Helpers/DongDongHelper.cs @@ -0,0 +1,100 @@ +using BBWY.Common.Models; +using QYDongDongTool; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Windows; + +namespace BBWY.Client.Helpers +{ + public class DongDongHelper : IDenpendency + { + private CSharpAPIs csapi; + private System.Timers.Timer inJectionTimer; + public DongDongHelper() + { + csapi = new CSharpAPIs(); + inJectionTimer = new System.Timers.Timer(10000); + inJectionTimer.Elapsed += InJectionTimer_Elapsed; + } + + private void InJectionTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + InJection(); + } + + private void InJection() + { + try + { + ProcessStartInfo p = new ProcessStartInfo(); + //p.UseShellExecute = true; + p.CreateNoWindow = true; + p.FileName= Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "InJectionDongDong", "dllin.exe"); + p.Verb = "runas"; + Process.Start(p); + } + catch (Exception ex) + { + Console.WriteLine($"InJection Error, {ex.Message}"); + } + } + + public void StartInJection() + { + if (!inJectionTimer.Enabled) + { + InJection(); + inJectionTimer.Start(); + } + + } + + /// + /// 获取全部登录咚咚账号 + /// + /// + public List GetAllDongdongUser() + { + List dongdongList = new List(); + var list = csapi.GetAllDesktopWindows(); + + var windows = list.Where(c => c.szClassName == "DD_JM_Workbench_DLG").ToList(); + + windows.ForEach(info => + { + dongdongList.Add(info.szWindowName.Replace("的工作台", "")); + }); + + return dongdongList; + } + + /// + /// 唤醒咚咚 + /// + /// + /// + public void WakeUpDongDong(string waiterName, string buyerAccount) + { + var url = $"jdworkstation://jm/?command=openDD&pin={waiterName}&client={buyerAccount}"; + try + { + try + { + //Process.Start("explorer.exe", url); + + ShellExecuteHelper.ShellExecute(IntPtr.Zero, "open", url, string.Empty, string.Empty, ShellExecuteHelper.ShowCommands.SW_SHOWNORMAL); + } + catch (Exception ex) + { + Clipboard.SetText(url); + MessageBox.Show($"{ex.Message}\r\n唤醒咚咚失败,唤醒链接已复制到剪切板,请手动打开浏览器唤醒", "提示"); + } + } + catch { throw; } + } + } +} diff --git a/BBWY.Client/Helpers/PipeHelper.cs b/BBWY.Client/Helpers/PipeHelper.cs deleted file mode 100644 index c0b49ef7..00000000 --- a/BBWY.Client/Helpers/PipeHelper.cs +++ /dev/null @@ -1,80 +0,0 @@ -using BBWY.Common.Models; -using System; -using System.Collections.Generic; -using System.IO; -using System.IO.Pipes; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace BBWY.Client.Helpers -{ - public class PipeHelper: IDenpendency - { - public PipeHelper() - { - _pipeServerDictionary = new Dictionary(); - } - - private IDictionary _pipeServerDictionary; - - public Action ServerReceiveCallback; - - private async Task WaitForClientConnectionsAsync(NamedPipeServerStream pipeServer) - { - while (true) - { - await pipeServer.WaitForConnectionAsync().ConfigureAwait(false); - try - { - const int bufferLength = 1024; - var buffer = new byte[bufferLength]; - using (var stream = new MemoryStream()) - { - while (true) - { - var bytesRead = await pipeServer.ReadAsync(buffer.AsMemory(0, bufferLength), CancellationToken.None).ConfigureAwait(false); - if (bytesRead == 0) - { - break; - } - stream.Write(buffer, 0, bytesRead); - } - - stream.Seek(0, SeekOrigin.Begin); - ServerReceiveCallback?.Invoke(Encoding.UTF8.GetString(stream.ToArray())); - } - } - finally - { - pipeServer.Disconnect(); - } - } - } - - public void CreateServer(string pipeName) - { - var _pipeServer = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 100, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.CurrentUserOnly); - _ = WaitForClientConnectionsAsync(_pipeServer); - } - - public void CloseServer(string pipeName) - { - if (_pipeServerDictionary.TryGetValue(pipeName, out NamedPipeServerStream pipeServer)) - { - try - { - pipeServer.Disconnect(); - pipeServer.Dispose(); - pipeServer.Close(); - _pipeServerDictionary.Remove(pipeName); - } - catch (Exception ex) - { - - } - } - } - } -} - diff --git a/BBWY.Client/Helpers/ShellExecuteHelper.cs b/BBWY.Client/Helpers/ShellExecuteHelper.cs new file mode 100644 index 00000000..0b6826a0 --- /dev/null +++ b/BBWY.Client/Helpers/ShellExecuteHelper.cs @@ -0,0 +1,36 @@ +using System; +using System.Runtime.InteropServices; + +namespace BBWY.Client.Helpers +{ + public class ShellExecuteHelper + { + public enum ShowCommands : int + { + SW_HIDE = 0, + SW_SHOWNORMAL = 1, + SW_NORMAL = 1, + SW_SHOWMINIMIZED = 2, + SW_SHOWMAXIMIZED = 3, + SW_MAXIMIZE = 3, + SW_SHOWNOACTIVATE = 4, + SW_SHOW = 5, + SW_MINIMIZE = 6, + SW_SHOWMINNOACTIVE = 7, + SW_SHOWNA = 8, + SW_RESTORE = 9, + SW_SHOWDEFAULT = 10, + SW_FORCEMINIMIZE = 11, + SW_MAX = 11 + } + + [DllImport("shell32.dll")] + public static extern IntPtr ShellExecute( + IntPtr hwnd, + string lpOperation, + string lpFile, + string lpParameters, + string lpDirectory, + ShowCommands nShowCmd); + } +} diff --git a/BBWY.Client/Helpers/WSHelper.cs b/BBWY.Client/Helpers/WSHelper.cs new file mode 100644 index 00000000..55271a21 --- /dev/null +++ b/BBWY.Client/Helpers/WSHelper.cs @@ -0,0 +1,59 @@ +using BBWY.Common.Models; +using Fleck; +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Pipes; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace BBWY.Client.Helpers +{ + public class WSHelper : IDenpendency + { + //private List connectSocketPool = new List(); + + private WebSocketServer wsServer; + + public WSHelper() + { + wsServer = new WebSocketServer("ws://127.0.0.1:35192"); + } + + public Action ServerReceiveCallback; + + + public void Start() + { + //开启监听 + wsServer.Start(socket => + { + //注册客户端连接建立事件 + socket.OnOpen = () => + { + Console.WriteLine("建立连接"); + //将当前客户端连接对象放入连接池中 + //connectSocketPool.Add(socket); + }; + //注册客户端连接关闭事件 + socket.OnClose = () => + { + //Console.WriteLine("Close"); + //将当前客户端连接对象从连接池中移除 + //connectSocketPool.Remove(socket); + }; + //注册客户端发送信息事件 + socket.OnMessage = message => + { + Console.WriteLine($"收到webSocket消息:{message}"); + socket.Close(); + ////向客户端发送消息 + //socket.Send($"服务端接收到信息:{message}"); + ServerReceiveCallback?.Invoke(message); + }; + }); + } + } +} + diff --git a/BBWY.Client/Models/APIModel/Response/ServiceGroup/WaiterResponse.cs b/BBWY.Client/Models/APIModel/Response/ServiceGroup/WaiterResponse.cs new file mode 100644 index 00000000..8896fc94 --- /dev/null +++ b/BBWY.Client/Models/APIModel/Response/ServiceGroup/WaiterResponse.cs @@ -0,0 +1,11 @@ +namespace BBWY.Client.Models +{ + public class WaiterResponse + { + public string Id { get; set; } + + public string Name { get; set; } + + public string Level { get; set; } + } +} diff --git a/BBWY.Client/Properties/Settings.Designer.cs b/BBWY.Client/Properties/Settings.Designer.cs new file mode 100644 index 00000000..8f89176e --- /dev/null +++ b/BBWY.Client/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace BBWY.Client.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.3.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/BBWY.Client/Properties/Settings.settings b/BBWY.Client/Properties/Settings.settings new file mode 100644 index 00000000..049245f4 --- /dev/null +++ b/BBWY.Client/Properties/Settings.settings @@ -0,0 +1,6 @@ + + + + + + diff --git a/BBWY.Client/ViewModels/MainViewModel.cs b/BBWY.Client/ViewModels/MainViewModel.cs index d111fdc3..d793b01b 100644 --- a/BBWY.Client/ViewModels/MainViewModel.cs +++ b/BBWY.Client/ViewModels/MainViewModel.cs @@ -1,4 +1,5 @@ using BBWY.Client.APIServices; +using BBWY.Client.Helpers; using BBWY.Client.Models; using BBWY.Client.Views; using BBWY.Common.Extensions; @@ -85,7 +86,8 @@ namespace BBWY.Client.ViewModels LogisticsService logisticsService, ShopService shopService, IHttpClientFactory httpClientFactory, - WebView2Manager w2m) + WebView2Manager w2m, + DongDongHelper dongdongHelper) { this.w2m = w2m; this.managerDepartment = new List() { "董事办", "财务部", "技术部", "总经办" }; @@ -109,8 +111,10 @@ namespace BBWY.Client.ViewModels //下载webview2 runtime Task.Factory.StartNew(DownloadWebview2Runtime); } + dongdongHelper.StartInJection(); } + private void CreateMenu() { if (GlobalContext.User.TeamName == "刷单组") @@ -409,7 +413,18 @@ namespace BBWY.Client.ViewModels private void GetJDServiceGroup() { - + var apiResponse = shopService.GetServiceGroupList(); + if (!apiResponse.Success) + { + MessageBox.Show(apiResponse.Msg, "获取客服组"); + Environment.Exit(Environment.ExitCode); + } + GlobalContext.ShopServiceGroupList.Clear(); + if (apiResponse.Data != null && apiResponse.Data.Count() > 0) + { + foreach (var waiter in apiResponse.Data) + GlobalContext.ShopServiceGroupList.Add(waiter.Name); + } } #endregion } diff --git a/BBWY.Client/ViewModels/Order/OrderListViewModel.cs b/BBWY.Client/ViewModels/Order/OrderListViewModel.cs index dbd8cfc3..75a9d810 100644 --- a/BBWY.Client/ViewModels/Order/OrderListViewModel.cs +++ b/BBWY.Client/ViewModels/Order/OrderListViewModel.cs @@ -26,7 +26,7 @@ namespace BBWY.Client.ViewModels private StatisticsService statisticsService; private AfterOrderService afterOrderService; private ChoosePurchaseSchemeViewModel choosePurchaseSchemeViewModel; - + private DongDongHelper dongdongHelper; private bool isLoading; private string searchOrderId; @@ -160,7 +160,7 @@ namespace BBWY.Client.ViewModels /// public bool IsSDGroup { get => isSDGroup; set { Set(ref isSDGroup, value); } } - public OrderListViewModel(OrderService orderService, StatisticsService statisticsService, AfterOrderService afterOrderService, GlobalContext globalContext, ChoosePurchaseSchemeViewModel choosePurchaseSchemeViewModel, PipeHelper pipeHelper) + public OrderListViewModel(OrderService orderService, StatisticsService statisticsService, AfterOrderService afterOrderService, GlobalContext globalContext, ChoosePurchaseSchemeViewModel choosePurchaseSchemeViewModel, WSHelper pipeHelper, DongDongHelper dongdongHelper) { IsSDGroup = globalContext.User.TeamName == "刷单组"; if (IsSDGroup) @@ -174,7 +174,8 @@ namespace BBWY.Client.ViewModels } random = new Random(); - this.pipeHelper = pipeHelper; + this.wsHelper = pipeHelper; + this.dongdongHelper = dongdongHelper; this.globalContext = globalContext; this.orderService = orderService; this.statisticsService = statisticsService; @@ -533,19 +534,38 @@ namespace BBWY.Client.ViewModels private void GetBuyerAccount(Order order) { - var buyerAccount = string.Empty; - var grab = new GrabJDMibole(order.Id); - if (grab.ShowDialog() == true) - buyerAccount = grab.Tag.ToString(); - if (string.IsNullOrEmpty(buyerAccount)) + if (string.IsNullOrEmpty(order.BuyerAccount)) + { + var buyerAccount = string.Empty; + var grab = new GrabJDMibole(order.Id); + if (grab.ShowDialog() == true) + buyerAccount = grab.Tag.ToString(); + if (string.IsNullOrEmpty(buyerAccount)) + { + MessageBox.Show("未获取到买家账号", "提示"); + return; + } + order.BuyerAccount = buyerAccount; + } + + //获取本机咚咚客服列表 + var currentMachineServiceGroupList = dongdongHelper.GetAllDongdongUser(); + if (currentMachineServiceGroupList == null || currentMachineServiceGroupList.Count() == 0) { - MessageBox.Show("未获取到买家账号", "提示"); + MessageBox.Show("未获取到本机咚咚客服账号列表", "提示"); return; } - order.BuyerAccount = buyerAccount; - //唤醒咚咚 + //匹配客服账号 + var waiter = currentMachineServiceGroupList.Intersect(globalContext.ShopServiceGroupList)?.FirstOrDefault(); + if (string.IsNullOrEmpty(waiter)) + { + MessageBox.Show("未匹配到当前店铺客服组和本机咚咚客服账号的交集", "提示"); + return; + } + //唤醒咚咚 + dongdongHelper.WakeUpDongDong(waiter, order.BuyerAccount); } private void ChooseStorageType(object param) diff --git a/BBWY.Client/ViewModels/Order/OrderListVoewModel_DongDong.cs b/BBWY.Client/ViewModels/Order/OrderListVoewModel_DongDong.cs index 9afc6f99..1b6ce91e 100644 --- a/BBWY.Client/ViewModels/Order/OrderListVoewModel_DongDong.cs +++ b/BBWY.Client/ViewModels/Order/OrderListVoewModel_DongDong.cs @@ -1,4 +1,5 @@ using BBWY.Client.Helpers; +using GalaSoft.MvvmLight.Messaging; using Newtonsoft.Json.Linq; using System; using System.Collections.Concurrent; @@ -10,18 +11,19 @@ namespace BBWY.Client.ViewModels { public partial class OrderListViewModel { - private PipeHelper pipeHelper; + private WSHelper wsHelper; private ConcurrentDictionary dongdongBuyerDictionary; public void InitDongDong() { dongdongBuyerDictionary = new ConcurrentDictionary(); - pipeHelper.ServerReceiveCallback = OnDongDongSendMessage; - pipeHelper.CreateServer("bbwyPipeServer"); + wsHelper.ServerReceiveCallback = OnDongDongSendMessage; + wsHelper.Start(); } private void OnDongDongSendMessage(string msg) { + Console.WriteLine($"OnDongDongSendMessage 接收到消息 {msg}"); if (string.IsNullOrEmpty(msg)) return; try @@ -37,23 +39,40 @@ namespace BBWY.Client.ViewModels } var order = OrderList.FirstOrDefault(o => !string.IsNullOrEmpty(o.BuyerAccount) && o.BuyerAccount == buyerAccount); - if (order != null && order.Consignee != null && order.Consignee.IsDecode) + if (order == null || order.Consignee == null || order.Consignee.IsDecode) return; //已经解密过 - Task.Factory.StartNew(() => orderService.DecodeConsignee(order.Id, phone)).ContinueWith(t => + var response = orderService.DecodeConsignee(order.Id, phone); + if (!response.Success) { - var response = t.Result; - IsLoading = false; - if (!response.Success) - { - App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "解密失败")); - return; - } - order.Consignee.ContactName = response.Data.ContactName; - order.Consignee.Address = response.Data.Address; - order.Consignee.Mobile = response.Data.Mobile; - order.Consignee.IsDecode = true; + App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "解密失败")); + return; + } + order.Consignee.ContactName = response.Data.ContactName; + order.Consignee.Address = response.Data.Address; + order.Consignee.Mobile = response.Data.Mobile; + order.Consignee.IsDecode = true; + + App.Current.Dispatcher.BeginInvoke((Action)delegate + { + Messenger.Default.Send(string.Empty, "ActiveMainWindow"); }); + ; + + //Task.Factory.StartNew(() => orderService.DecodeConsignee(order.Id, phone)).ContinueWith(t => + //{ + // var response = t.Result; + // IsLoading = false; + // if (!response.Success) + // { + // App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "解密失败")); + // return; + // } + // order.Consignee.ContactName = response.Data.ContactName; + // order.Consignee.Address = response.Data.Address; + // order.Consignee.Mobile = response.Data.Mobile; + // order.Consignee.IsDecode = true; + //}); } catch (Exception ex) diff --git a/BBWY.Client/Views/MainWindow.xaml.cs b/BBWY.Client/Views/MainWindow.xaml.cs index 2779f90a..73387f7d 100644 --- a/BBWY.Client/Views/MainWindow.xaml.cs +++ b/BBWY.Client/Views/MainWindow.xaml.cs @@ -18,7 +18,7 @@ namespace BBWY.Client.Views private void MainWindow_Loaded(object sender, RoutedEventArgs e) { - + GalaSoft.MvvmLight.Messaging.Messenger.Default.Register(this, "ActiveMainWindow", (x) => this.Activate()); } private void frame_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e) diff --git a/BBWY.Client/Views/Order/GrabJDMibole.xaml.cs b/BBWY.Client/Views/Order/GrabJDMibole.xaml.cs index a010160d..a72a3470 100644 --- a/BBWY.Client/Views/Order/GrabJDMibole.xaml.cs +++ b/BBWY.Client/Views/Order/GrabJDMibole.xaml.cs @@ -65,22 +65,24 @@ namespace BBWY.Client.Views.Order } else if (w2m.wb2.CoreWebView2.Source.StartsWith("https://neworder.shop.jd.com/order/orderDetail")) { - Console.WriteLine($"{orderId}触发手机号查看"); + //Console.WriteLine($"{orderId}触发手机号查看"); //进入订单详情页面,触发点击查看手机号 - txtMsg.Text = "Grabbing Mobile"; + txtMsg.Text = "Grabbing BuyerAccount"; //w2m.wb2.Width = 0.1; //w2m.wb2.Height = 0.1; - var js = @"var mobileNode = document.getElementById('mobile'); - mobileNode.addEventListener('DOMNodeInserted',function(e){ var m=mobileNode.innerText; window.chrome.webview.postMessage(m);}); - document.getElementById('viewOrderMobile').click();"; + //var js = @"var mobileNode = document.getElementById('mobile'); + // mobileNode.addEventListener('DOMNodeInserted',function(e){ var m=mobileNode.innerText; window.chrome.webview.postMessage(m);}); + // document.getElementById('viewOrderMobile').click();"; + + var js = "var d = document.getElementsByName('dongdongICON')[0]; window.chrome.webview.postMessage(d.innerText);"; _ = await w2m.wb2.CoreWebView2.ExecuteScriptAsync(js); } }; w2m.OnWebMessageReceived = (e) => { - var mobole = e.TryGetWebMessageAsString(); - Console.WriteLine($"{orderId}接收手机号{mobole}"); - this.Tag = mobole; + var buyerAccount = e.TryGetWebMessageAsString().Trim(); + Console.WriteLine($"{orderId}接收买家账号{buyerAccount}"); + this.Tag = buyerAccount; this.DialogResult = true; this.Close(); }; diff --git a/BBWY.Client/Views/Order/OrderListControl.xaml b/BBWY.Client/Views/Order/OrderListControl.xaml index 81e477d4..760a4920 100644 --- a/BBWY.Client/Views/Order/OrderListControl.xaml +++ b/BBWY.Client/Views/Order/OrderListControl.xaml @@ -88,7 +88,7 @@ diff --git a/BBWY.Client/app.manifest b/BBWY.Client/app.manifest new file mode 100644 index 00000000..603d39fb --- /dev/null +++ b/BBWY.Client/app.manifest @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BBWY.Server.API/Controllers/VenderController.cs b/BBWY.Server.API/Controllers/VenderController.cs index 000ae1cc..3464a57a 100644 --- a/BBWY.Server.API/Controllers/VenderController.cs +++ b/BBWY.Server.API/Controllers/VenderController.cs @@ -99,5 +99,16 @@ namespace BBWY.Server.API.Controllers { return venderBusiness.GetShopListByShopIds(request); } + + /// + /// 获取店铺客服组 + /// + /// + /// + [HttpPost] + public IList GetServiceGroupList([FromBody]PlatformRequest request) + { + return venderBusiness.GetServiceGroupList(request); + } } } diff --git a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs index dcfdaf2e..24e937a9 100644 --- a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs +++ b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs @@ -1187,5 +1187,23 @@ namespace BBWY.Server.Business if (res.IsError) throw new BusinessException($"暂停JD活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); } + + public override IList GetServiceGroupList(PlatformRequest request) + { + var jdClient = GetJdClient(request.AppKey, request.AppSecret); + var req = new ImPopGroupinfoGetRequest(); + var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime()); + if (res.IsError) + throw new BusinessException($"查询客服组失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); + if (res.Json == null) + res.Json = JsonConvert.DeserializeObject(res.Body); + return res.Json["jingdong_im_pop_groupinfo_get_responce"]["popgroup"]["waiterList"].Select(j => new WaiterResponse() + { + Id = "", + Level = j.Value("level"), + Name = j.Value("waiter") + }).ToList(); + + } } } diff --git a/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs b/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs index ae82d228..f9a74aec 100644 --- a/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs +++ b/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs @@ -177,5 +177,10 @@ namespace BBWY.Server.Business { throw new NotImplementedException(); } + + public virtual IList GetServiceGroupList(PlatformRequest request) + { + throw new NotImplementedException(); + } } } diff --git a/BBWY.Server.Business/Vender/VenderBusiness.cs b/BBWY.Server.Business/Vender/VenderBusiness.cs index b71eec6c..9c779eb7 100644 --- a/BBWY.Server.Business/Vender/VenderBusiness.cs +++ b/BBWY.Server.Business/Vender/VenderBusiness.cs @@ -309,5 +309,17 @@ namespace BBWY.Server.Business { return freeSqlMultiDBManager.MDSfsql.Select().Where(s => s.ShopId == shopId).ToOne(); } + + public IList GetServiceGroupList(PlatformRequest request) + { + var relayAPIHost = GetPlatformRelayAPIHost(request.Platform); + var sendResult = restApiService.SendRequest(relayAPIHost, "api/PlatformSDK/GetServiceGroupList", request, GetYunDingRequestHeader(), HttpMethod.Post); + if (sendResult.StatusCode != System.Net.HttpStatusCode.OK) + throw new BusinessException(sendResult.Content) { Code = (int)sendResult.StatusCode }; + var response = JsonConvert.DeserializeObject>>(sendResult.Content); + if (!response.Success) + throw new BusinessException(response.Msg) { Code = response.Code }; + return response.Data; + } } } diff --git a/BBWY.Server.Model/Dto/Response/ServiceGroup/WaiterResponse.cs b/BBWY.Server.Model/Dto/Response/ServiceGroup/WaiterResponse.cs new file mode 100644 index 00000000..147f07a4 --- /dev/null +++ b/BBWY.Server.Model/Dto/Response/ServiceGroup/WaiterResponse.cs @@ -0,0 +1,11 @@ +namespace BBWY.Server.Model.Dto +{ + public class WaiterResponse + { + public string Id { get; set; } + + public string Name { get; set; } + + public string Level { get; set; } + } +} diff --git a/BBWY.Test/JDDongDongAPITest.cs b/BBWY.Test/JDDongDongAPITest.cs index 078d8e59..de1270fa 100644 --- a/BBWY.Test/JDDongDongAPITest.cs +++ b/BBWY.Test/JDDongDongAPITest.cs @@ -1,8 +1,11 @@ -using Jd.Api; +using BBWY.Server.Model.Dto; +using Jd.Api; using Jd.Api.Request; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; +using System.Linq; using System.Text; namespace BBWY.Test @@ -11,9 +14,24 @@ namespace BBWY.Test { public void GetServiceGroup(IJdClient client, string token) { + //var req = new ImPopGroupinfoGetRequest(); + //var response = client.Execute(req, token, DateTime.Now.ToLocalTime()); + //Console.WriteLine(JsonConvert.SerializeObject(response)); + + + var req = new ImPopGroupinfoGetRequest(); - var response = client.Execute(req, token, DateTime.Now.ToLocalTime()); - Console.WriteLine(JsonConvert.SerializeObject(response)); + var res = client.Execute(req, token, DateTime.Now.ToLocalTime()); + if (res.Json == null) + res.Json = JsonConvert.DeserializeObject(res.Body); + var list = res.Json["jingdong_im_pop_groupinfo_get_responce"]["popgroup"]["waiterList"].Select(j => new WaiterResponse() + { + Id = "", + Level = j.Value("level"), + Name = j.Value("waiter") + }).ToList(); + + Console.WriteLine(JsonConvert.SerializeObject(list)); } } } diff --git a/InDll2/InDll2.csproj b/InDll2/InDll2.csproj index 9afd8675..57df6996 100644 --- a/InDll2/InDll2.csproj +++ b/InDll2/InDll2.csproj @@ -3,9 +3,17 @@ Exe netcoreapp3.1 + x86 + app.manifest + + Never + + + Always + Always diff --git a/InDll2/Program.cs b/InDll2/Program.cs index 7e6874ed..d6be9053 100644 --- a/InDll2/Program.cs +++ b/InDll2/Program.cs @@ -12,30 +12,30 @@ public class Program public static void Main() { - var list = GetAllDongdongUser(); + //var list = GetAllDongdongUser(); - Console.WriteLine(string.Join(",",list)); + //Console.WriteLine(string.Join(",",list)); - //var list = new CSharpAPIs().GetAllDesktopWindows(); + var list = new CSharpAPIs().GetAllDesktopWindows(); - //var windows = list.Where(c => c.szClassName == "DD_JM_Workbench_DLG").ToList(); + var windows = list.Where(c => c.szClassName == "DD_JM_Workbench_DLG").ToList(); - //windows.ForEach(info => - //{ + windows.ForEach(info => + { - // foreach (ProcessModule module in Process.GetProcessById(info.ProcessId).Modules) - // { - // //检测是否已经注入 - // if (module.ModuleName.Contains("sendPhone.dll")) - // { - // return; - // } - // } + foreach (ProcessModule module in Process.GetProcessById(info.ProcessId).Modules) + { + //检测是否已经注入 + if (module.ModuleName.Contains("sendPhone.dll")) + { + return; + } + } - // //注入dll - // MP.Hook((int)info.ProcessId); + //注入dll + MP.Hook((int)info.ProcessId); - //}); + }); } diff --git a/InDll2/app.manifest b/InDll2/app.manifest new file mode 100644 index 00000000..eee90648 --- /dev/null +++ b/InDll2/app.manifest @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/InDll2/dllin.exe b/InDll2/dllin.exe new file mode 100644 index 00000000..91038ac7 Binary files /dev/null and b/InDll2/dllin.exe differ diff --git a/InDll2/sendPhone.dll b/InDll2/sendPhone.dll index 8eadd0bb..a9990849 100644 Binary files a/InDll2/sendPhone.dll and b/InDll2/sendPhone.dll differ diff --git a/JD.API/Controllers/PlatformSDKController.cs b/JD.API/Controllers/PlatformSDKController.cs index b469cd0f..84e03b86 100644 --- a/JD.API/Controllers/PlatformSDKController.cs +++ b/JD.API/Controllers/PlatformSDKController.cs @@ -317,5 +317,16 @@ namespace JD.API.API.Controllers { platformSDKBusinessList.FirstOrDefault(p => p.Platform == request.Platform).SuspendJDPromotionTask(request); } + + /// + /// 查询店铺客服组 + /// + /// + /// + [HttpPost] + public IList GetServiceGroupList([FromBody] PlatformRequest request) + { + return platformSDKBusinessList.FirstOrDefault(p => p.Platform == request.Platform).GetServiceGroupList(request); + } } }