1.插入讀卡機跟健保卡後,使用psctest 確認讀卡機功能正常
#pcsctest
1. 手動安裝pyscard ,不要用pip安裝,目前預設會安裝1.7.0版,會有bug
Download pyscard-1.9.1.tar.gz
2.使用網路找到的範例檔案,讀取你的健保卡資訊
from smartcard.System import readers
# define the APDUs used in this script
SelectAPDU = [ 0x00, 0xA4, 0x04, 0x00, 0x10, 0xD1, 0x58, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00 ]
ReadProfileAPDU = [ 0x00, 0xca, 0x11, 0x00, 0x02, 0x00, 0x00 ]
# get all the available readers
r = readers()
print "Available readers:", r
reader = r[0]
print "Using:", reader
connection = reader.createConnection()
connection.connect()
data, sw1, sw2 = connection.transmit(
SelectAPDU)
print "Select Applet: %02X %02X" % (sw1, sw2)
data, sw1, sw2 = connection.transmit(
ReadProfileAPDU)
#print data
print "Command: %02X %02X" % (sw1, sw2)
print 'Card Number : %s' % ''.join(chr(i) for i in data[0:12])
print 'Name : %s' % ''.join(chr(i) for i in data[12:18])
print 'ID Number : %s' % ''.join(chr(i) for i in data[32:42])
print 'Birthday : %s' % ''.join(chr(i) for i in data[43:49])
print 'Sex : %s' % ''.join(chr(i) for i in data[49:50])
print 'Card Date : %s' % ''.join(chr(i) for i in data[51:57])
備註:
@不確定需不需要的scardservice
http://smartcardservices.macosforge.org/post/installers-for-previous-os-x-releases-updatedreposted-v212/