当前位置: 首页 > news >正文

Qt系列:调用Edge浏览器示例

背景

需要解决以下几个问题

  1. 政府项目新浏览器兼容老系统ActiveX控件,Qt WebEngineView没有直接的实现方案,需要利用Qt的ActiveX兼容模块与浏览器往返多次交互
  2. Qt ActiveX未实现COM事件通知
  3. 官方Win32示例存在滥用lambda函数的嫌疑,lambda函数多层嵌套,程序逻辑层次混乱,整个逻辑被揉成一垛。

官方示例代码

官方介绍文档在这里:https://learn.microsoft.com/microsoft-edge/webview2/get-started/win32。官方代码仓库在这里:GitHub - MicrosoftEdge/WebView2Samples: Microsoft Edge WebView2 samples

摘录一段lambda多层嵌套的代码,你们体会一下:

	CreateCoreWebView2EnvironmentWithOptions(nullptr, nullptr, nullptr,Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>([hWnd](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {// Create a CoreWebView2Controller and get the associated CoreWebView2 whose parent is the main window hWndenv->CreateCoreWebView2Controller(hWnd, Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>([hWnd](HRESULT result, ICoreWebView2Controller* controller) -> HRESULT {if (controller != nullptr) {webviewController = controller;webviewController->get_CoreWebView2(&webview);}// Add a few settings for the webview// The demo step is redundant since the values are the default settingswil::com_ptr<ICoreWebView2Settings> settings;webview->get_Settings(&settings);settings->put_IsScriptEnabled(TRUE);settings->put_AreDefaultScriptDialogsEnabled(TRUE);settings->put_IsWebMessageEnabled(TRUE);// Resize WebView to fit the bounds of the parent windowRECT bounds;GetClientRect(hWnd, &bounds);webviewController->put_Bounds(bounds);// Schedule an async task to navigate to Bingwebview->Navigate(L"https://www.bing.com/");// <NavigationEvents>// Step 4 - Navigation events// register an ICoreWebView2NavigationStartingEventHandler to cancel any non-https navigationEventRegistrationToken token;webview->add_NavigationStarting(Callback<ICoreWebView2NavigationStartingEventHandler>([](ICoreWebView2* webview, ICoreWebView2NavigationStartingEventArgs* args) -> HRESULT {wil::unique_cotaskmem_string uri;args->get_Uri(&uri);std::wstring source(uri.get());if (source.substr(0, 5) != L"https") {args->put_Cancel(true);}return S_OK;}).Get(), &token);// </NavigationEvents>// <Scripting>// Step 5 - Scripting// Schedule an async task to add initialization script that freezes the Object objectwebview->AddScriptToExecuteOnDocumentCreated(L"Object.freeze(Object);", nullptr);// Schedule an async task to get the document URLwebview->ExecuteScript(L"window.document.URL;", Callback<ICoreWebView2ExecuteScriptCompletedHandler>([](HRESULT errorCode, LPCWSTR resultObjectAsJson) -> HRESULT {LPCWSTR URL = resultObjectAsJson;//doSomethingWithURL(URL);return S_OK;}).Get());// </Scripting>// <CommunicationHostWeb>// Step 6 - Communication between host and web content// Set an event handler for the host to return received message back to the web contentwebview->add_WebMessageReceived(Callback<ICoreWebView2WebMessageReceivedEventHandler>([](ICoreWebView2* webview, ICoreWebView2WebMessageReceivedEventArgs* args) -> HRESULT {wil::unique_cotaskmem_string message;args->TryGetWebMessageAsString(&message);// processMessage(&message);webview->PostWebMessageAsString(message.get());return S_OK;}).Get(), &token);// Schedule an async task to add initialization script that// 1) Add an listener to print message from the host// 2) Post document URL to the hostwebview->AddScriptToExecuteOnDocumentCreated(L"window.chrome.webview.addEventListener(\'message\', event => alert(event.data));" \L"window.chrome.webview.postMessage(window.document.URL);",nullptr);// </CommunicationHostWeb>return S_OK;}).Get());return S_OK;}).Get());

解决方案

下面以实现自动登录外网网关为目标,企业微信自动上线,免开机输入账号密码。这样领导看到你上线,可以开机以后就可以慢慢吃早餐了。(开个玩笑)

本实现方案把官方示例代码做成了静态库,没有添加其它东西。

新建CMake项目

这里用到了Qt5静态库,目的是单文件可执行,不需要部署。需要静态库的读者可以自行删除。代码如下:

cmake_minimum_required(VERSION 3.21)
project(auto-online CXX)set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)add_definitions(/D_UNICODE /DUNICODE)
add_compile_definitions(WIN32 _WINDOWS)add_compile_options(/utf-8 $<IF:$<CONFIG:Debug>,/MTd,/MT>)
link_directories($ENV{Qt5_DIR}/lib)
link_directories($ENV{Qt5_DIR}/plugins/platforms)
link_directories($ENV{Qt5_DIR}/plugins/imageformats)
link_libraries(UxTheme Winmm Version ws2_32 imm32 dwmapi)link_libraries($<IF:$<CONFIG:Debug>,Qt5FontDatabaseSupportd,Qt5FontDatabaseSupport>)
link_libraries($<IF:$<CONFIG:Debug>,Qt5UiToolsd,Qt5UiTools>)
link_libraries($<IF:$<CONFIG:Debug>,Qt5AccessibilitySupportd,Qt5AccessibilitySupport>)
link_libraries($<IF:$<CONFIG:Debug>,Qt5EventDispatcherSupportd,Qt5EventDispatcherSupport>)
link_libraries($<IF:$<CONFIG:Debug>,Qt5ThemeSupportd,Qt5ThemeSupport>)
link_libraries($<IF:$<CONFIG:Debug>,Qt5UiToolsd,Qt5UiTools>)link_libraries($<IF:$<CONFIG:Debug>,qtpcre2d,qtpcre2>)
link_libraries($<IF:$<CONFIG:Debug>,qtlibpngd,qtlibpng>)
link_libraries($<IF:$<CONFIG:Debug>,qtharfbuzzd,qtharfbuzz>)
link_libraries($<IF:$<CONFIG:Debug>,qtfreetyped,qtfreetype>)
link_libraries($<IF:$<CONFIG:Debug>,qwindowsd,qwindows>)
link_libraries($<IF:$<CONFIG:Debug>,qicnsd,qicns>)
link_libraries($<IF:$<CONFIG:Debug>,qtgad,qtga>)
link_libraries($<IF:$<CONFIG:Debug>,qtiffd,qtiff>)
link_libraries($<IF:$<CONFIG:Debug>,qwbmpd,qwbmp>)
link_libraries($<IF:$<CONFIG:Debug>,qtiffd,qtiff>)
link_libraries($<IF:$<CONFIG:Debug>,qwebpd,qwebp>)
link_libraries($<IF:$<CONFIG:Debug>,qgifd,qgif>)
link_libraries($<IF:$<CONFIG:Debug>,qjpegd,qjpeg>)
link_libraries($<IF:$<CONFIG:Debug>,qicod,qico>)message("-- Qt5_DIR: " $ENV{Qt5_DIR})
find_package(Qt5 COMPONENTS Core Gui Widgets Network REQUIRED)include_directories(${CMAKE_SOURCE_DIR}/3rdparty/webview2loader/include)
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/wil/include)
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/webview2loader/lib)
link_libraries(Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network WebView2LoaderStatic)file(GLOB SRCS *.ui *.cpp *.h)
add_executable(${PROJECT_NAME} WIN32 ${SRCS})
set_directory_properties(PROPERTIES VS_STARTUP_PROJECT ${PROJECT_NAME})
# 环境变量的路径不能带双引号
# message("VCINSTALLDIR: " $ENV{VCINSTALLDIR})
# find_file(VSPATH NAMES "vcruntime140d.dll" PATHS $ENV{VCINSTALLDIR}  REQUIRED NO_DEFAULT_PATH)
# file(TO_NATIVE_PATH ${VSPATH} VSPATH) 
#message("VC CRT PATH: " ${VSPATH})
# set(VSPATH $<IF:$<CONFIG:Debug>,$ENV{VCINSTALLDIR}/Redist/MSVC/14.29.30133/onecore/debug_nonredist/x64/Microsoft.VC142.DebugCRT,$ENV{VCINSTALLDIR}/Redist/MSVC/14.29.30133/x64/Microsoft.VC142.CRT> CACHE STRING "VCRT" FORCE)
# string(CONCAT VSPATH ${VSPATH} ";$ENV{Qt5_DIR}\\bin")set_target_properties(${PROJECT_NAME} PROPERTIESVS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_BINARY_DIR}VS_DEBUGGER_ENVIRONMENT "Path=$ENV{Qt5_DIR}\\bin"WIN32_EXECUTABLE TRUE)

用Qt Designer设计一个简单的窗口类型

类型名字很简单,就是MainWindow。这个窗口仅启用了布局,没有添加任何控件。UI代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"><class>MainWindow</class><widget class="QMainWindow" name="MainWindow"><property name="geometry"><rect><x>0</x><y>0</y><width>800</width><height>600</height></rect></property><property name="windowTitle"><string>MainWindow</string></property><widget class="QWidget" name="central_widget"><layout class="QVBoxLayout" name="vl1"><property name="spacing"><number>0</number></property><property name="leftMargin"><number>0</number></property><property name="topMargin"><number>0</number></property><property name="rightMargin"><number>0</number></property><property name="bottomMargin"><number>0</number></property><item><widget class="QWidget" name="browser_widget" native="true"><layout class="QVBoxLayout" name="vl2"/></widget></item></layout></widget></widget><resources/><connections/>
</ui>

声明信号槽

#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QThread>#include <windows.h>
#include <stdlib.h>
#include <string>
#include <tchar.h>
#include "wrl.h"
#include "wil/com.h"
#include "WebView2.h"#define PROFILE_DATA "cw_webview2"namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{Q_OBJECTpublic:explicit MainWindow(QWidget *parent = nullptr);~MainWindow();void load_webview2(HWND hWnd);void task_run();HRESULT cb_create_environment(HWND, HRESULT, ICoreWebView2Environment *);HRESULT cb_create_controller(HWND, HRESULT, ICoreWebView2Controller *);HRESULT on_navigate_started(ICoreWebView2 *, ICoreWebView2NavigationStartingEventArgs *);HRESULT cb_execute_script(HRESULT, LPCWSTR);HRESULT on_webmessage_received(ICoreWebView2 *, ICoreWebView2WebMessageReceivedEventArgs *);HRESULT on_navigate_completed(ICoreWebView2*, ICoreWebView2NavigationCompletedEventArgs*);// HRESULT cb_deliver(HWND, HRESULT, ...);signals:void prepare();void load_auth_page();void put_name();void put_password();void click_login();void wait(int iminute);protected:void resizeEvent(QResizeEvent* evt) override;void closeEvent(QCloseEvent*) override;protected slots:void on_prepare();void on_load_auth_page();void on_put_name();void on_put_password();void on_click_login();void on_wait(int iminute);private:Ui::MainWindow *ui;// Pointer to WebViewControllerwil::com_ptr<ICoreWebView2Controller> m_controller;bool m_brunning = false;QThread* m_task;// Pointer to WebView windowwil::com_ptr<ICoreWebView2_15> m_webview;Microsoft::WRL::ComPtr<ICoreWebView2ExecuteScriptCompletedHandler> js_cb;Microsoft::WRL::ComPtr<ICoreWebView2WebMessageReceivedEventHandler> msg_cb;
};#endif // MAINWINDOW_H

在合适的时机填入账号密码

本来想做成弹框让用户输入账号密码,忽然发现这种做法对信息部门的同事不太友好,各位读者如有请自行修改。示例代码中的网关地址、用户名和密码是乱写的。

#include "MainWindow.h"
#include "ui_MainWindow.h"#include <QResizeEvent>
#include <QRect>
#include <QDebug>
#include <QStandardPaths>
#include <QDir>
#include <QMessageBox>
#include <QTimer>
#include <QApplication>using namespace Microsoft::WRL;MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{ui->setupUi(this);load_webview2((HWND)ui->browser_widget->winId());setWindowTitle(u8"自动连接外网工具");connect(this, SIGNAL(prepare()), this, SLOT(on_prepare()), Qt::QueuedConnection);connect(this, SIGNAL(load_auth_page()), this, SLOT(on_load_auth_page()), Qt::QueuedConnection);connect(this, SIGNAL(put_name()), this, SLOT(on_put_name()), Qt::QueuedConnection);connect(this, SIGNAL(put_password()), this, SLOT(on_put_password()), Qt::QueuedConnection);connect(this, SIGNAL(click_login()), this, SLOT(on_click_login()), Qt::QueuedConnection);connect(this, SIGNAL(wait(int)), this, SLOT(on_wait(int)), Qt::QueuedConnection);
}MainWindow::~MainWindow()
{delete ui;
}HRESULT MainWindow::on_navigate_started(ICoreWebView2 *webview,ICoreWebView2NavigationStartingEventArgs *args)
{wil::unique_cotaskmem_string uri;args->get_Uri(&uri);QString zurl = QString::fromStdWString(uri.get());// std::wstring source(uri.get());// if (source.substr(0, 5) != L"https")// {//     args->put_Cancel(true);// }qInfo().noquote() << "navigate: " << zurl;return S_OK;
}HRESULT MainWindow::cb_execute_script(HRESULT errorCode, LPCWSTR resultObjectAsJson)
{LPCWSTR URL = resultObjectAsJson;//doSomethingWithURL(URL);qInfo() << "executed javascript.";return S_OK;
}HRESULT MainWindow::on_webmessage_received(ICoreWebView2 *webview,ICoreWebView2WebMessageReceivedEventArgs *args)
{wil::unique_cotaskmem_string message;args->TryGetWebMessageAsString(&message);// processMessage(&message);//webview->PostWebMessageAsString(message.get());QString zmsg = QString::fromStdWString(message.get());qInfo().noquote() << "message: " << zmsg;return S_OK;
}HRESULT MainWindow::on_navigate_completed(ICoreWebView2 *webview,ICoreWebView2NavigationCompletedEventArgs *args)
{BOOL bsuccess;COREWEBVIEW2_WEB_ERROR_STATUS ierror;args->get_IsSuccess(&bsuccess);args->get_WebErrorStatus(&ierror);LPWSTR lpuri;webview->get_Source(&lpuri);QString zuri = QString::fromStdWString(lpuri);qInfo().noquote() << "complate : " << bsuccess << ", " << ierror << ", " << zuri;return S_OK;
}void MainWindow::resizeEvent(QResizeEvent *evt)
{if (!m_controller)return;RECT rc;QRect qrc =  ui->browser_widget->rect();rc.left = qrc.left();rc.top = qrc.top();rc.right = qrc.right();rc.bottom = qrc.bottom();m_controller->put_Bounds(rc);
}void MainWindow::closeEvent(QCloseEvent *)
{m_brunning = false;m_task->terminate();QThread::sleep(1);m_task->deleteLater();m_task = nullptr;
}void MainWindow::on_prepare()
{if (!m_webview)return;m_webview->NavigateToString(L"Preparing...");
}void MainWindow::on_load_auth_page()
{if (!m_webview)return;m_webview->Navigate(L"http://1.1.1.3/ac_portal/default/pc.html?tabs=pwd");qInfo() << "begin load auth page";
}void MainWindow::on_put_name()
{if (!m_webview)return;m_webview->ExecuteScript(L"$('#password_name').val('test1');""window.chrome.webview.postMessage('put name ok.');",js_cb.Get());
}void MainWindow::on_put_password()
{if (!m_webview)return;m_webview->ExecuteScript(L"$('#password_pwd').val('123456');""window.chrome.webview.postMessage('put password ok.');",js_cb.Get());
}void MainWindow::on_click_login()
{if (!m_webview)return;m_webview->ExecuteScript(L"$('#password_submitBtn').click();""window.chrome.webview.postMessage('click login ok.');",js_cb.Get());
}void MainWindow::on_wait(int iminute)
{QString zhtml = QString("Already wairted %1 minutes.").arg(iminute);if (!m_webview)return;m_webview->NavigateToString(zhtml.toStdWString().c_str());
}HRESULT MainWindow::cb_create_controller(HWND hWnd, HRESULT result,ICoreWebView2Controller *controller)
{if (!controller)return E_POINTER;m_controller = controller;wil::com_ptr<ICoreWebView2> webview;HRESULT ir =  m_controller->get_CoreWebView2(&webview);if (FAILED(ir))return ir;ir = webview->QueryInterface(IID_ICoreWebView2_15, (void **)&m_webview);if (FAILED(ir))return ir;// Add a few settings for the webview// The demo step is redundant since the values are the default settingswil::com_ptr<ICoreWebView2Settings> settings;m_webview->get_Settings(&settings);settings->put_IsScriptEnabled(TRUE);settings->put_AreDefaultScriptDialogsEnabled(TRUE);settings->put_IsWebMessageEnabled(TRUE);// Resize WebView to fit the bounds of the parent windowRECT bounds;GetClientRect(hWnd, &bounds);m_controller->put_Bounds(bounds);m_webview->NavigateToString(L"Preparing...");// <NavigationEvents>// Step 4 - Navigation events// register an ICoreWebView2NavigationStartingEventHandler to cancel any non-https navigationEventRegistrationToken token;auto nav_func = std::bind(&MainWindow::on_navigate_started, this, std::placeholders::_1,std::placeholders::_2);auto nav_cb = Callback<ICoreWebView2NavigationStartingEventHandler>(nav_func);m_webview->add_NavigationStarting(nav_cb.Get(), &token);auto com_func = std::bind(&MainWindow::on_navigate_completed, this, std::placeholders::_1,std::placeholders::_2);auto com_cb = Callback<ICoreWebView2NavigationCompletedEventHandler>(com_func);m_webview->add_NavigationCompleted(com_cb.Get(), &token);// </NavigationEvents>// <Scripting>// Step 5 - Scripting// Schedule an async task to add initialization script that freezes the Object object// 注入脚本//webview->AddScriptToExecuteOnDocumentCreated(L"Object.freeze(Object);", nullptr);// Schedule an async task to get the document URLauto js_func = std::bind(&MainWindow::cb_execute_script, this, std::placeholders::_1,std::placeholders::_2);js_cb = Callback<ICoreWebView2ExecuteScriptCompletedHandler>(js_func);//webview->ExecuteScript(L"window.document.URL;", js_cb.Get());// </Scripting>// <CommunicationHostWeb>// Step 6 - Communication between host and web content// Set an event handler for the host to return received message back to the web contentauto msg_func = std::bind(&MainWindow::on_webmessage_received, this, std::placeholders::_1,std::placeholders::_2);msg_cb = Callback<ICoreWebView2WebMessageReceivedEventHandler>(msg_func);m_webview->add_WebMessageReceived(msg_cb.Get(), &token);// Schedule an async task to add initialization script that// 1) Add an listener to print message from the host// 2) Post document URL to the host// 注入脚本//webview->AddScriptToExecuteOnDocumentCreated(//    L"window.chrome.webview.addEventListener(\'message\', event => alert(event.data));" \//    L"window.chrome.webview.postMessage(window.document.URL);",//    nullptr);// </CommunicationHostWeb>m_task = QThread::create(&MainWindow::task_run, this);m_task->setParent(this);m_task->start();return S_OK;
}void MainWindow::load_webview2(HWND hWnd)
{MainWindow *obj = this;auto func = &MainWindow::cb_create_environment;auto fn = [hWnd, obj, func](HRESULT result, ICoreWebView2Environment * env)->HRESULT{return (obj->*func)(hWnd, result, env);};auto cb = Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(fn);QDir d(QStandardPaths::writableLocation(QStandardPaths::TempLocation));auto ztemp = d.absoluteFilePath(PROFILE_DATA).toStdWString();HRESULT ir = CreateCoreWebView2EnvironmentWithOptions(nullptr, ztemp.c_str(), nullptr, cb.Get());if (FAILED(ir)){qCritical() << "create webview2 failed. code: " << ir;QTimer::singleShot(3000, [](){QApplication::quit();_Exit(1);});QMessageBox::warning(this,windowTitle(),u8"严重错误。程序即将退出。\n""请检查Microsoft Edge WebView2 Runtime是否存在。\n");}
}void MainWindow::task_run()
{if (!m_controller || !m_webview)return;m_brunning = true;while (m_brunning){emit on_prepare();QThread::sleep(3);if (!m_brunning)break;emit load_auth_page();QThread::sleep(10);if (!m_brunning)break;emit put_name();QThread::sleep(3);if (!m_brunning)break;emit put_password();QThread::sleep(3);if (!m_brunning)break;emit click_login();for (int i = 0; i < 10; i++){QThread::sleep(60);if (!m_brunning)break;emit wait(i + 1);}}
}HRESULT MainWindow::cb_create_environment(HWND hWnd, HRESULT result, ICoreWebView2Environment *env)
{MainWindow *obj = this;auto func = &MainWindow::cb_create_controller;auto fn = [hWnd, obj, func](HRESULT result, ICoreWebView2Controller * controller)->HRESULT{return (obj->*func)(hWnd, result, controller);};// Create a CoreWebView2Controller and get the associated CoreWebView2 whose parent is the main window hWndauto cb = Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(fn);HRESULT hr = env->CreateCoreWebView2Controller(hWnd, cb.Get());return hr;
}

免责声明

此代码仅供技术研究娱乐之用,禁止用于商业用途,否则一切后果自负。

作者:岬淢箫声

岬淢箫声的博客_CSDN博客-C/C++,MFC/VC,桌面H5领域博主icon-default.png?t=N176https://caowei.blog.csdn.net/

转载请注明来源

相关文章:

Qt系列:调用Edge浏览器示例

背景 需要解决以下几个问题 政府项目新浏览器兼容老系统ActiveX控件&#xff0c;Qt WebEngineView没有直接的实现方案&#xff0c;需要利用Qt的ActiveX兼容模块与浏览器往返多次交互Qt ActiveX未实现COM事件通知官方Win32示例存在滥用lambda函数的嫌疑&#xff0c;lambda函数…...

内推|香港外企急招ETL工程师!数据分析师+Python开发+运营专家

2月已过半还在找工作&#xff1f;快来看看有没有适合你的岗位&#xff01;01公司&#xff1a;友邦科技 工作地点&#xff1a;成都市高新区OCG国际中心招聘岗位&#xff1a;ETL工程师 15-18k该岗位为香港项目&#xff0c;需要有数仓或者大数据经验。本科IT或数据相关专业&#…...

zlib压缩原理

数据压缩的本质 去除数据中的冗余信息&#xff0c;对于ABABABABABABAB字样的字符串&#xff0c;AB出现了7次&#xff0c;占用14个字节&#xff0c;如果将该字符串编码为7AB&#xff0c;只占用3个字节。 为什么需要对数据压缩 数据需要存储或者传输&#xff0c;为了节省磁盘空…...

论文阅读笔记《DEEP GRAPH MATCHING CONSENSUS》

核心思想 本文提出一种基于图神经网络的图匹配方法&#xff0c;首先利用节点相似度构建初始的匹配关系&#xff0c;然后利用局部的一致性对初始的匹配关系进行迭代优化&#xff0c;不断筛除误匹配点&#xff0c;得到最终的匹配结果。本文还提出几种措施来降低计算复杂度&#x…...

华为OD机试题 - 开放日活动(JavaScript)

最近更新的博客 2023新华为OD机试题 - 斗地主(JavaScript)2023新华为OD机试题 - 箱子之形摆放(JavaScript)2023新华为OD机试题 - 考古学家(JavaScript)2023新华为OD机试题 - 相同数字的积木游戏 1(JavaScript)2023新华为OD机试题 - 最多等和不相交连续子序列(JavaScri…...

(考研湖科大教书匠计算机网络)第四章网络层-第八节:网际控制报文协议ICMP

获取pdf&#xff1a;密码7281专栏目录首页&#xff1a;【专栏必读】考研湖科大教书匠计算机网络笔记导航 文章目录一&#xff1a;网际控制报文协议ICMP&#xff08;1&#xff09;ICMP差错报告报文A&#xff1a;终点不可达B&#xff1a;源点抑制C&#xff1a;时间超过D&#xff…...

华为OD机试 - GPU 调度 | 备考思路,刷题要点,答疑 【新解法】

最近更新的博客 【新解法】华为OD机试 - 关联子串 | 备考思路,刷题要点,答疑,od Base 提供【新解法】华为OD机试 - 停车场最大距离 | 备考思路,刷题要点,答疑,od Base 提供【新解法】华为OD机试 - 任务调度 | 备考思路,刷题要点,答疑,od Base 提供【新解法】华为OD机试…...

华为OD机试题 - 任务总执行时长(JavaScript)

最近更新的博客 2023新华为OD机试题 - 斗地主(JavaScript)2023新华为OD机试题 - 箱子之形摆放(JavaScript)2023新华为OD机试题 - 考古学家(JavaScript)2023新华为OD机试题 - 相同数字的积木游戏 1(JavaScript)2023新华为OD机试题 - 最多等和不相交连续子序列(JavaScri…...

还在想假期去哪玩?直接做一个旅游攻略小程序

憋了几年好不容易解封准备出去散散心,但看着大江南北这么多景点是不是有点让你选择强迫症呢?那就先制作一个旅游攻略小程序看看驴友们的分享吧。...

十四、vue3项目如何使用three.js

近期在开发过程中&#xff0c;因为项目已经接近尾声&#xff0c;就需要对项目中的数据进行整合&#xff0c;而数据看板不失为一个比较直观的展现形式。在数据看板中3D的展现形式是比较流行的展现形式&#xff0c;那么如何在项目引入一个大的场景&#xff0c;并且能够和后台发生…...

python 向excel表中添加新的sheet页或者向旧sheet中写入数据

import xlwt import xlrd from xlutils.copy import copy import os import numpy as np import pandas as pd class Excel_Add_Sheet():def save_table(self, table, file_name):# 保存表table.save(file_name)def add_new_sheet(self, file_name, sheet_name, titleNone):&q…...

RPC-grpc实践

参考&#xff1a;https://developer.aliyun.com/article/1152352?spma2c6h.12873639.article-detail.33.344f6446zEnbRi&scm20140722.ID_communityarticle1152352._.ID_communityarticle1152352-OR_rec-V_1 参考&#xff1a;https://onejson.blog.csdn.net/article/detai…...

JavaEE——MyBatis配置文件的详细介绍

简单介绍&#xff1a; 需要我们编写的配置文件主要有三个&#xff0c;分别是核心配置文件&#xff08;mybatis-config.xml&#xff09;&#xff0c;数据库连接信息文件&#xff08;db.properties&#xff09;&#xff0c;SQL语句映射文件&#xff08;Mappers&#xff09;&…...

bwmarrin/snowflake生成ID重复问题排查记录

现象 某日&#xff0c;运营反馈&#xff0c;在某个时间区间丢失了一段日志&#xff0c;让看看是什么问题。 排查 查看项目日志有无错误 发现项目日志有报错信息Error 1062 Duplicate entry 149059529550598144 for key PRIMARY,很显然&#xff0c;问题在此&#xff0c;数据库…...

操作系统题目收录(十)

1、在存储管理中&#xff0c;采用覆盖与交换技术的目的是&#xff08;&#xff09;。 A&#xff1a;节省主存空间B&#xff1a;物理上扩充主存容量C&#xff1a;提高CPU效率D&#xff1a;实现主存共享 解析 覆盖和交换的提出就是为了解决主存空间不足的问题&#xff0c;但不…...

IOS 自动化测试环境搭建

购买MacPDD 比TB JD 便宜500&#xff0c;下单安装homebrew/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"安装npm cnpmbrew install node; npm install -g cnpm --registryhttps://registry.npm.taobao.org;安装类似Andro…...

系统设计原则

系统设计原则 好的系统是迭代出来的。先解决核心问题&#xff0c;预测未来可能出现的问题&#xff0c;对现有的问题有方案&#xff0c;对未来的问题有预案。不是一上来就按1亿用户量设计&#xff0c;也不要过度复杂化系统。 业务千变万化&#xff0c;技术层出不穷&#xff0c…...

推荐130个网站,非常实用,比涨工资都重要

搞学习 TED&#xff08;最优质的演讲&#xff09;&#xff1a;https://www.ted.com/ 谷粉学术&#xff1a;https://gfsoso.99lb.net/scholar.html 大学资源网&#xff1a;http://www.dxzy163.com/ 简答题&#xff1a;http://www.jiandati.com/ 网易公开课&#xff1a;https…...

手机棋牌游戏开发的流程是怎样的?

最近几年&#xff0c;随着网络游戏的兴起&#xff0c;棋牌手游开发也越来越受欢迎&#xff0c;在国内&#xff0c;几乎随处可见从事手游和手游的公司。不过&#xff0c;虽然公司和产品很多&#xff0c;但效果也不一样&#xff0c;区别就在于&#xff0c;他们能不能掌握好这款游…...

浅谈C++函数重载

C相较于C语言来说,重载是一重大特性,让我们一起简单的回顾一下重载那些事 传送门函数重载是什么为什么有函数重载函数重载是如何实现的总结函数重载是什么 函数重载:是函数的一种特殊情况,C允许在同一作用域中声明几个功能相似的同名函数 这些同名函数的形参列表(参数个数or类…...

多云管理“拦路虎”:深入解析网络互联、身份同步与成本可视化的技术复杂度​

一、引言&#xff1a;多云环境的技术复杂性本质​​ 企业采用多云策略已从技术选型升维至生存刚需。当业务系统分散部署在多个云平台时&#xff0c;​​基础设施的技术债呈现指数级积累​​。网络连接、身份认证、成本管理这三大核心挑战相互嵌套&#xff1a;跨云网络构建数据…...

测试微信模版消息推送

进入“开发接口管理”--“公众平台测试账号”&#xff0c;无需申请公众账号、可在测试账号中体验并测试微信公众平台所有高级接口。 获取access_token: 自定义模版消息&#xff1a; 关注测试号&#xff1a;扫二维码关注测试号。 发送模版消息&#xff1a; import requests da…...

synchronized 学习

学习源&#xff1a; https://www.bilibili.com/video/BV1aJ411V763?spm_id_from333.788.videopod.episodes&vd_source32e1c41a9370911ab06d12fbc36c4ebc 1.应用场景 不超卖&#xff0c;也要考虑性能问题&#xff08;场景&#xff09; 2.常见面试问题&#xff1a; sync出…...

智慧工地云平台源码,基于微服务架构+Java+Spring Cloud +UniApp +MySql

智慧工地管理云平台系统&#xff0c;智慧工地全套源码&#xff0c;java版智慧工地源码&#xff0c;支持PC端、大屏端、移动端。 智慧工地聚焦建筑行业的市场需求&#xff0c;提供“平台网络终端”的整体解决方案&#xff0c;提供劳务管理、视频管理、智能监测、绿色施工、安全管…...

Qt Widget类解析与代码注释

#include "widget.h" #include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget) {ui->setupUi(this); }Widget::~Widget() {delete ui; }//解释这串代码&#xff0c;写上注释 当然可以&#xff01;这段代码是 Qt …...

MySQL中【正则表达式】用法

MySQL 中正则表达式通过 REGEXP 或 RLIKE 操作符实现&#xff08;两者等价&#xff09;&#xff0c;用于在 WHERE 子句中进行复杂的字符串模式匹配。以下是核心用法和示例&#xff1a; 一、基础语法 SELECT column_name FROM table_name WHERE column_name REGEXP pattern; …...

多种风格导航菜单 HTML 实现(附源码)

下面我将为您展示 6 种不同风格的导航菜单实现&#xff0c;每种都包含完整 HTML、CSS 和 JavaScript 代码。 1. 简约水平导航栏 <!DOCTYPE html> <html lang"zh-CN"> <head><meta charset"UTF-8"><meta name"viewport&qu…...

SQL慢可能是触发了ring buffer

简介 最近在进行 postgresql 性能排查的时候,发现 PG 在某一个时间并行执行的 SQL 变得特别慢。最后通过监控监观察到并行发起得时间 buffers_alloc 就急速上升,且低水位伴随在整个慢 SQL,一直是 buferIO 的等待事件,此时也没有其他会话的争抢。SQL 虽然不是高效 SQL ,但…...

基于IDIG-GAN的小样本电机轴承故障诊断

目录 🔍 核心问题 一、IDIG-GAN模型原理 1. 整体架构 2. 核心创新点 (1) ​梯度归一化(Gradient Normalization)​​ (2) ​判别器梯度间隙正则化(Discriminator Gradient Gap Regularization)​​ (3) ​自注意力机制(Self-Attention)​​ 3. 完整损失函数 二…...

R 语言科研绘图第 55 期 --- 网络图-聚类

在发表科研论文的过程中&#xff0c;科研绘图是必不可少的&#xff0c;一张好看的图形会是文章很大的加分项。 为了便于使用&#xff0c;本系列文章介绍的所有绘图都已收录到了 sciRplot 项目中&#xff0c;获取方式&#xff1a; R 语言科研绘图模板 --- sciRplothttps://mp.…...