2017-10-09 45 views
0

我正在編寫用於閱讀電子護照的程序(Java應用程序)。對於訪問,我使用庫org.jmrtd。我應該在CardService.getInstance()中傳輸哪種對象?如何使用CardService連接到ACR122

import net.sf.scuba.smartcards.CardService; 
import net.sf.scuba.smartcards.CardServiceException; 
import org.jmrtd.BACKeySpec; 
import org.jmrtd.PassportService; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 

public class TestComponent { 
    private static final Logger log = LoggerFactory.getLogger(MainApp.class); 

    public static void main(String args[]) { 

     try { 
      CardService cs = CardService.getInstance(???????); 
      PassportService ps = new PassportService(cs); 
      ps.open(); 
      ps.sendSelectApplet(false); 

      ps.sendSelectApplet(false); 
      BACKeySpec bacKey = new BACKeySpec() { 
       public String getDocumentNumber() { 
        return "xxxxxxxx"; 
       } 
       public String getDateOfBirth() { 
        return "yyMMdd"; 
       } 
       public String getDateOfExpiry() { 
        return "yyMMdd"; 
       } 
      }; 
      ps.doBAC(bacKey); 
      ps.close(); 

     } catch (CardServiceException e) { 
      e.printStackTrace(); 
     } 
    } 
} 

回答

0

答發現:

  1. 在POM添加

    net.sf.scuba 水肺SC-J2SE 0.0.13

  2. 進口net.sf .scuba.smartcards.TerminalCardService;

  3. CardTerminal terminal =TerminalFactory.getDefault().terminals().list().get(0); CardService cs = CardService.getInstance(terminal); PassportService ps = new PassportService(cs); ps.open();