diff --git a/WebTest/GlobalContext.cs b/WebTest/GlobalContext.cs index dc18748..aa4c2e7 100644 --- a/WebTest/GlobalContext.cs +++ b/WebTest/GlobalContext.cs @@ -1,5 +1,7 @@ using Newtonsoft.Json; +using System; using System.Runtime.InteropServices; +using System.Windows; namespace WebTest { @@ -27,5 +29,24 @@ namespace WebTest { return "10123"; } + + public void CallALiWangWang(string sellerLoginId) + { + var url = $"aliim:sendmsg?siteid=cnalichn&portalId=&gid=&itemsId=&touid=cnalichn{sellerLoginId}&status=1"; + try + { + //Process.Start("explorer.exe", url); + ShellExecuteHelper.ShellExecute(IntPtr.Zero, "open", url, string.Empty, string.Empty, ShellExecuteHelper.ShowCommands.SW_SHOWNORMAL); + } + catch (Exception ex) + { + try + { + Clipboard.SetText(url); + } + catch { } + MessageBox.Show($"{ex.Message}\r\n唤醒旺旺失败,唤醒链接已复制到剪切板,请手动打开浏览器唤醒", "提示"); + } + } } } \ No newline at end of file diff --git a/WebTest/MainWindow.xaml.cs b/WebTest/MainWindow.xaml.cs index 05a29e6..1653a5c 100644 --- a/WebTest/MainWindow.xaml.cs +++ b/WebTest/MainWindow.xaml.cs @@ -26,6 +26,14 @@ namespace WebTest private MdsApiService mdsApiService; private ShopService shopService; +#if DEBUG +private string registerName = "webTestContext"; +#else +private string registerName = "webContext"; +#endif + + + public MainWindow() { InitializeComponent(); @@ -87,7 +95,7 @@ namespace WebTest if (args.PermissionKind == CoreWebView2PermissionKind.ClipboardRead) args.State = CoreWebView2PermissionState.Allow; }; - w2m.wb2.CoreWebView2.AddHostObjectToScript("webTestContext", this.globalContext); + w2m.wb2.CoreWebView2.AddHostObjectToScript(registerName, this.globalContext); }; w2m.Init(); diff --git a/WebTest/ShellExecuteHelper.cs b/WebTest/ShellExecuteHelper.cs new file mode 100644 index 0000000..5562daa --- /dev/null +++ b/WebTest/ShellExecuteHelper.cs @@ -0,0 +1,36 @@ +using System; +using System.Runtime.InteropServices; + +namespace WebTest +{ + 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); + } +}