I need to get Track 1 and Track 2 data off magnetic cards and send them over the network to a waiting server. What is an easy way to get the track data from a USB HID magnetic card reader?
In case it helps, I have a MAGTEK Mini Swipe Magnetic Strip Reader (part no. 21040140)
开发者_StackOverflowI'm OS agnostic -- a solution for Windows, Mac or Linux would be great. Preferably no .NET, but if that's the easiest way I'll go for it.
What do you all think?
Thanks!
Every card reader I've seen has had a keyboard emulator, so you swipe the card and it sends characters through the keyboard buffer. Looks like this one also does that (documentation : http://www.magtek.com/documentation/public/99875206-16.01.pdf)
Page 14 describes the data sent after a swipe, which is again, fairly standard across card readers:
[Tk1 SS] [Tk1 Data] [ES] [Tk2 SS] [Tk2 Data] [ES] [Tk3 SS] [Tk3 Data] [ES] [CR]
So your track one data starts with %
and ends with ?
Track two data starts with ;
and ends with ?
I noticed the question was tagged credit-card though, so it would be worth making sure you know the consequences of sending raw card-data across a network (even an internal network). Take a look at the Payment Card Industry Data Security Standards (PCI-DSS) : https://www.pcisecuritystandards.org/security_standards/pci_dss.shtml
There is a demo program for that specific reader that comes with VB source.
http://www.magtek.com/support/software/demo_programs/usb_swipe_insert.asp
Easiest way to download the Cab file from this link & include it in the project directory in a "magtek" folder.
http://www.magtek.com/support/software/demo_programs/card/usb_hid_swipe_readers/read_parse.asp
Add this code in aspx file after tag (change cab file src as per )
<object id="USBHID" classid="CLSID:22571E97-956A-4CDD-AF8D-AE9C26597683" codebase="magtek/99510060.CAB#version=1,13,0,2">
</object>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#txtNameFirst').focus(); // Focus on a textbox is required
USBHID.PortOpen = true;
if (USBHID.PortOpen == false) {
$('#<%= lblStatus.ClientID %>').text('Could not open MagTek reader');
}
else {
$('#<%= lblStatus.ClientID %>').text('Please Swipe a card');
}
});
$("#txtNameFirst").bind('change', function () {
var CCData = $("#txtNameFirst").val(); // CCData will contain the complete credit card data in a string.
alert(CCData);
$("#txtNameFirst").val(CCData.split('^')[1].split(' ')[0]);
$("#txtNameLast").val(CCData.split('^')[1].split(' ')[1]);
$("#txtCCNo").val(CCData.split('^')[0].substring(2, 18));
//alert(' Split1: ' + CCData.split('^')[1] + ' Split2: ' + CCData.split('^')[2]);
//alert('parsing good!');
$("#txtExpiDt_RoutingNo").val(CCData.split('^')[2].substring(2, 4) + '/' + CCData.split('^')[2].substring(0, 2));
});
</script>
As per the above code I have added focus on a text box . After swiping the card focused textboxes automatically show the complete credit card data string.
精彩评论