我必须制作一个将读卡器连接到系统的应用程序,如果有人在连接的读卡器上交换卡,我必须读取磁卡读卡器数据。
磁卡主要保存用户注册信息。所以用户会在接待时给卡。接待员将交换卡,系统将从卡中读取数据并在我的派对管理应用程序中注册该用户。
不,我知道该怎么做?可以用 PHP 吗?
请分享想法如何做到这一点。
我必须制作一个将读卡器连接到系统的应用程序,如果有人在连接的读卡器上交换卡,我必须读取磁卡读卡器数据。
磁卡主要保存用户注册信息。所以用户会在接待时给卡。接待员将交换卡,系统将从卡中读取数据并在我的派对管理应用程序中注册该用户。
不,我知道该怎么做?可以用 PHP 吗?
请分享想法如何做到这一点。
I have to make a application where card reader will be attached to system and I have to read magnetic card reader data if someone swap card on card reader attached.
Since you want to do this in PHP, I assume this is a web application and that the card is swiped at the client machine where the browser is running.
You may have a keyboard-emulation swiper (you usually get a text such as '123456'), in which case you need to intercept the keyboard/focus and upload the data as form field or AJAX. This can be tricky if the field or the browser lose the focus, and you'd need to run the browser in "kiosk mode".
Or you can have a swiper using other technologies such as serial (RS232[C]), which I believe is quite obsolete, or custom interface (which means normally an USB swiper and a set of API). If this is the case, it all depends on what API are implemented; some devices come with an ActiveX applet which will force you to use Internet Explorer technologies on Windows platform. Some others use Java applets, and you will have to integrate them in the Web page.
Finally some of them have a completely custom application which may interface with the system in several ways (the case "custom LIBRARY" is the same, except that you have to also develop the custom application yourself!):
lynx
(either Linux or Windows) and dovetail into case #1, "custom HTTP query".Unfortunately the various suppliers tend to either the "hacky" side (i.e., they supply you the hardware and a minimum of software, a library and a sample MFC app or source code, and you're on your own) or on the "everything included and nonnegotiable" side (i.e., you get your reader with a fully configured POS or employee timelogger app, and no easy way of doing anything else with it).
If you're running server side, i.e., PHP script (not its HTML/text output) and badge reader are on the same machine, then again it depends on what software you were supplied with. For servers, keyboard emulation are either the best (if you have a headless server with no reason to ever connect a keyboard) or asking for trouble (if the magnetic reader and the real keyboard find themselves in competition). RS232[C] are also very simple to use, in Linux you can ttytail
or maybe even tail -f
the device on a log file and poll the log file. YOU MAY HAVE PRIVACY ISSUES WITH THAT (think "recording all customers' credit card numbers in plain text"). Or you can attach the device in PHP with fopen()
, no trouble there.
Custom-API libraries might be tricky. You might have to resort to the trick of creating a socket or named pipe "server" which opens the device and makes its results available to PHP through fsockopen()
. Unix sockets and client/server programming knowledge required.
UPDATE
I saw in a comment that you have the library for the barcode reader. I still assume you're in a web app scenario (say, three POS with readers, one server).
A way of doing this could be:
// PHP "server" application running as CLI on POS #1
// (will read some data from an INI file)
* application initialization
for(;;)
{
/* Hypothesis 1: blocking library */
$code = read_barcode();
/* Hypothesis 2: nonblocking, but buffering library */
if (!barcode_available())
{
sleep(1);
continue;
}
/* Hypothesis 3 is left as an exercise ;-) - remember to reinit the buffer */
if (!checks_if_valid_barcode($code))
continue;
// Unless there's some reason of using cURL, we keep it simple
// We might want to use mcrypt() function to encrypt the code, though.
$response = file_get_contents(
$CONFIG['server_url'].'?terminal='.$CONFIG['terminal']
.'&code='.$code
);
// Do something with the response - maybe just an OK or an ERROR
// (e.g. play a sound, just for kicks).
// The server, which generates the error, knows all about the error itself
// and the webapp will poll details from the server, not from this app.
}
The web application will query the server at intervals; we have two paralle workflows:
On a unix system i would use a named pipe and have something like python handle the magnetic card. the ones ive used use RS232 which python handles nicely. and can then pipe to PHP. PHP can also send info back on this pipe eg ask for a re read etc.
使用条形码阅读器构建了一个模块化系统 - 一种方法是使用 VB 或 c# 之类的语言构建一个简单的 Web 浏览器(C# 有一个组件供您在大约 5 分钟内完成此操作)。然后 C# 可以与浏览器交互,将数据发送到站点?