我有一个previous question关于在使用Chrome时从网页中访问代理卡的方法。我现在试图改为使用带有嵌入式CefSharp对象的vb.Net应用程序。我有访问代理卡所需的代码(感谢Smart Card API),但我需要一种简单的方法来表明这甚至是一个选项。我的想法是:
<div id='smartcard' />
)<div />
页面的内容
<div />
,请确保检测到读卡器。如果是这样,请在其内容中添加一些文本(可能是图像),表示可以扫描卡在我看来,我将不得不使用JavaScript和vb.net代码的某些组合,但我对CefSharp这么新,我真的不知道从哪里开始。< / p>
提前感谢您的帮助。
答案 0 :(得分:0)
不是C#程序员,我多次查看General Usage指南中的信息,但仍然没有真正理解它。那就是说,我想我已经能够实现这个项目了。除了CefSharp项目,我还使用CardWerk的非免费Smart Card API。
以下是我所做的一些片段。
Imports CefSharp
Imports Subsembly ' For the SmartCard namespace
Class MainWindow
Private WithEvents CardManager As SmartCard.CardTerminalManager
Private Sub MainWindow_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
browser.Address = "https://jake-dev7.local/trainingmatrix/"
Debug.Print(SmartCard.SMARTCARDAPI.API_VERSION)
CardManager = SmartCard.CardTerminalManager.Singleton
CardManager.Startup(True)
End Sub
Private Sub browser_LoadingStateChanged(sender As Object, e As LoadingStateChangedEventArgs) Handles browser.LoadingStateChanged
Dim script As String
If Not e.IsLoading Then
If CardManager.SlotCount Then
script = "if ($('#proxcard').length) { proxcard_init() }"
browser.GetMainFrame().ExecuteJavaScriptAsync(script)
End If
End If
End Sub
Protected Sub InsertedEvent(ByVal aSender As Object, ByVal aEventArgs As SmartCard.CardTerminalEventArgs) Handles CardManager.CardInsertedEvent
Dim aCard As SmartCard.CardHandle
Dim nActivationResult As SmartCard.CardActivationResult
Dim iFacilityCode As Integer
Dim iCardID As Integer
' There's a bunch of code here taken from the sample code that came
' with the SmartCard API from CardWerk to pull the facility code and
' card id out of the prox card.
If iFacilityCode <> 0 And iCardID <> 0 Then
Dim script As String
script = "if ($('#proxcard').length) { proxcard_scan(" & iFacilityCode & ", " & iCardID & ") }"
browser.GetMainFrame().ExecuteJavaScriptAsync(script)
End If
End Sub
End Class
(这是在网页加载的.js
文件中。此页面也可以在Chrome,Firefox,IE等中加载,这些功能永远不会运行,这使得该实用程序可用于计算机没有自定义.exe
和读卡器。)
// These proxcard_* functions are called via our parent application
// (CefSharp object embeded in a vb.Net assembly)
function proxcard_init() {
$('#proxcard').html("<div class='or'>- OR -</div><div><img src='proxcard.jpg'><br>Scan your card</div>");
}
function proxcard_scan(facilityID, cardID) {
var vars = {
facilityID: facilityID,
cardID: cardID
};
if ($('form#adduser').length) {
// We're on the add user page. Check to see if this card matches somebody.
$.post('httprequest.php?type=get-emp-from-prox', vars, function(data) {
if (data && data.number) {
// Update UI and backend form fields. If everything validates, submit the form
} else {
// Clear UI and backend form fields that pertain to user ID
alert('Card not found');
}
}, 'json');
} else if ($('form#update').length) {
// Deal with the update form
}
}
在我的实际代码中,我有多个else if
语句用于处理我允许扫描卡的不同表单。它们不包括在内以防止失控:)。
请注意:这不是整个项目或使用CefSharp处理代理卡所需的所有代码。我希望能够帮助其他人。