當前位置: 首頁>>代碼示例>>Java>>正文


Java CommunicationException類代碼示例

本文整理匯總了Java中com.github.devnied.emvnfccard.exception.CommunicationException的典型用法代碼示例。如果您正苦於以下問題:Java CommunicationException類的具體用法?Java CommunicationException怎麽用?Java CommunicationException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CommunicationException類屬於com.github.devnied.emvnfccard.exception包,在下文中一共展示了CommunicationException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
public static void main(final String[] args) throws CardException, CommunicationException {

		TerminalFactory factory = TerminalFactory.getDefault();
		List<CardTerminal> terminals = factory.terminals().list();
		LOGGER.info("Terminals: " + terminals);

		if (terminals != null && !terminals.isEmpty()) {
			// Use the first terminal
			CardTerminal terminal = terminals.get(0);

			// Connect with the card
			Card card = terminal.connect("*");
			LOGGER.info("card: " + card);
			CardChannel channel = card.getBasicChannel();

			PcscProvider provider = new PcscProvider(channel);
			EmvParser parser = new EmvParser(provider, false);
			parser.readEmvCard();

			// Disconnect the card
			card.disconnect(false);
		} else {
			LOGGER.error("No pcsc terminal found");
		}

	}
 
開發者ID:devnied,項目名稱:EMV-NFC-Paycard-Enrollment,代碼行數:27,代碼來源:Main.java

示例2: getLeftPinTry

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
/**
 * Method used to get the number of pin try left
 *
 * @return the number of pin try left
 * @throws CommunicationException
 */
protected int getLeftPinTry() throws CommunicationException {
    int ret = UNKNOW;
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Get Left PIN try");
    }
    // Left PIN try command
    byte[] data = provider.transceive(new CommandApdu(CommandEnum.GET_DATA, 0x9F, 0x17, 0).toBytes());
    if (ResponseUtils.isSucceed(data)) {
        // Extract PIN try counter
        byte[] val = TlvUtil.getValue(data, EmvTags.PIN_TRY_COUNTER);
        if (val != null) {
            ret = BytesUtils.byteArrayToInt(val);
        }
    }
    return ret;
}
 
開發者ID:JackuyLiu,項目名稱:Android-NFC-Paycard-Reader,代碼行數:23,代碼來源:EmvParser.java

示例3: parseFCIProprietaryTemplate

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
/**
 * Method used to parse FCI Proprietary Template
 *
 * @param pData data to parse
 * @return
 * @throws CommunicationException
 */
protected byte[] parseFCIProprietaryTemplate(final byte[] pData) throws CommunicationException {
    // Get SFI
    byte[] data = TlvUtil.getValue(pData, EmvTags.SFI);

    // Check SFI
    if (data != null) {
        int sfi = BytesUtils.byteArrayToInt(data);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("SFI found:" + sfi);
        }
        data = provider.transceive(new CommandApdu(CommandEnum.READ_RECORD, sfi, sfi << 3 | 4, 0).toBytes());
        // If LE is not correct
        if (ResponseUtils.isEquals(data, SwEnum.SW_6C)) {
            data = provider.transceive(new CommandApdu(CommandEnum.READ_RECORD, sfi, sfi << 3 | 4, data[data.length - 1]).toBytes());
        }
        return data;
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("(FCI) Issuer Discretionary Data is already present");
    }
    return pData;
}
 
開發者ID:JackuyLiu,項目名稱:Android-NFC-Paycard-Reader,代碼行數:30,代碼來源:EmvParser.java

示例4: extractPublicData

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
/**
 * Read public card data from parameter AID
 *
 * @param pAid              card AID in bytes
 * @param pApplicationLabel application scheme (Application label)
 * @return true if succeed false otherwise
 */
protected boolean extractPublicData(final byte[] pAid, final String pApplicationLabel) throws CommunicationException {
    boolean ret = false;
    // Select AID
    byte[] data = selectAID(pAid);
    // check response
    if (ResponseUtils.isSucceed(data)) {
        // Parse select response
        ret = parse(data, provider);
        if (ret) {
            // Get AID
            String aid = BytesUtils.bytesToStringNoSpace(TlvUtil.getValue(data, EmvTags.DEDICATED_FILE_NAME));
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Application label:" + pApplicationLabel + " with Aid:" + aid);
            }
            card.setAid(aid);
            card.setType(findCardScheme(aid, card.getCardNumber()));
            card.setApplicationLabel(pApplicationLabel);
            card.setLeftPinTry(getLeftPinTry());
        }
    }
    return ret;
}
 
開發者ID:JackuyLiu,項目名稱:Android-NFC-Paycard-Reader,代碼行數:30,代碼來源:EmvParser.java

示例5: getLeftPinTry

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
/**
 * Method used to get the number of pin try left
 *
 * @return the number of pin try left
 * @throws CommunicationException
 */
protected int getLeftPinTry() throws CommunicationException {
	int ret = UNKNOW;
	if (LOGGER.isDebugEnabled()) {
		LOGGER.debug("Get Left PIN try");
	}
	// Left PIN try command
	byte[] data = provider.transceive(new CommandApdu(CommandEnum.GET_DATA, 0x9F, 0x17, 0).toBytes());
	if (ResponseUtils.isSucceed(data)) {
		// Extract PIN try counter
		byte[] val = TlvUtil.getValue(data, EmvTags.PIN_TRY_COUNTER);
		if (val != null) {
			ret = BytesUtils.byteArrayToInt(val);
		}
	}
	return ret;
}
 
開發者ID:devnied,項目名稱:EMV-NFC-Paycard-Enrollment,代碼行數:23,代碼來源:EmvParser.java

示例6: parseFCIProprietaryTemplate

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
/**
 * Method used to parse FCI Proprietary Template
 *
 * @param pData
 *            data to parse
 * @return
 * @throws CommunicationException
 */
protected byte[] parseFCIProprietaryTemplate(final byte[] pData) throws CommunicationException {
	// Get SFI
	byte[] data = TlvUtil.getValue(pData, EmvTags.SFI);

	// Check SFI
	if (data != null) {
		int sfi = BytesUtils.byteArrayToInt(data);
		if (LOGGER.isDebugEnabled()) {
			LOGGER.debug("SFI found:" + sfi);
		}
		data = provider.transceive(new CommandApdu(CommandEnum.READ_RECORD, sfi, sfi << 3 | 4, 0).toBytes());
		// If LE is not correct
		if (ResponseUtils.isEquals(data, SwEnum.SW_6C)) {
			data = provider.transceive(new CommandApdu(CommandEnum.READ_RECORD, sfi, sfi << 3 | 4, data[data.length - 1]).toBytes());
		}
		return data;
	}
	if (LOGGER.isDebugEnabled()) {
		LOGGER.debug("(FCI) Issuer Discretionary Data is already present");
	}
	return pData;
}
 
開發者ID:devnied,項目名稱:EMV-NFC-Paycard-Enrollment,代碼行數:31,代碼來源:EmvParser.java

示例7: extractPublicData

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
/**
 * Read public card data from parameter AID
 *
 * @param pAid
 *            card AID in bytes
 * @param pApplicationLabel
 *            application scheme (Application label)
 * @return true if succeed false otherwise
 */
protected boolean extractPublicData(final byte[] pAid, final String pApplicationLabel) throws CommunicationException {
	boolean ret = false;
	// Select AID
	byte[] data = selectAID(pAid);
	// check response
	if (ResponseUtils.isSucceed(data)) {
		// Parse select response
		ret = parse(data, provider);
		if (ret) {
			// Get AID
			String aid = BytesUtils.bytesToStringNoSpace(TlvUtil.getValue(data, EmvTags.DEDICATED_FILE_NAME));
			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("Application label:" + pApplicationLabel + " with Aid:" + aid);
			}
			card.setAid(aid);
			card.setType(findCardScheme(aid, card.getCardNumber()));
			card.setApplicationLabel(pApplicationLabel);
			card.setLeftPinTry(getLeftPinTry());
		}
	}
	return ret;
}
 
開發者ID:devnied,項目名稱:EMV-NFC-Paycard-Enrollment,代碼行數:32,代碼來源:EmvParser.java

示例8: getGetProcessingOptions

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
/**
 * Method used to create GPO command and execute it
 *
 * @param pPdol
 *            PDOL data
 * @param pProvider
 *            provider
 * @return return data
 */
protected byte[] getGetProcessingOptions(final byte[] pPdol, final IProvider pProvider) throws CommunicationException {
	// List Tag and length from PDOL
	List<TagAndLength> list = TlvUtil.parseTagAndLength(pPdol);
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	try {
		out.write(EmvTags.COMMAND_TEMPLATE.getTagBytes()); // COMMAND
		// TEMPLATE
		out.write(TlvUtil.getLength(list)); // ADD total length
		if (list != null) {
			for (TagAndLength tl : list) {
				out.write(EmvTerminal.constructValue(tl));
			}
		}
	} catch (IOException ioe) {
		LOGGER.error("Construct GPO Command:" + ioe.getMessage(), ioe);
	}
	return pProvider.transceive(new CommandApdu(CommandEnum.GPO, out.toByteArray(), 0).toBytes());
}
 
開發者ID:devnied,項目名稱:EMV-NFC-Paycard-Enrollment,代碼行數:28,代碼來源:EmvParser.java

示例9: testPPSEVisa

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
@Test
public void testPPSEVisa() throws CommunicationException {

	IProvider prov = new PpseProviderVisaTest();

	EmvParser parser = new EmvParser(prov, true);
	EmvCard card = parser.readEmvCard();

	if (card != null) {
		LOGGER.debug(card.toString());
	}
	Assertions.assertThat(card).isNotNull();
	Assertions.assertThat(card.getAid()).isEqualTo("A0000000421010");
	Assertions.assertThat(card.getCardNumber()).isEqualTo("4999999999999999");
	Assertions.assertThat(card.getType()).isEqualTo(EmvCardScheme.VISA);
	Assertions.assertThat(card.getHolderLastname()).isNull();
	Assertions.assertThat(card.getHolderFirstname()).isNull();
	Assertions.assertThat(card.getApplicationLabel()).isEqualTo("CB");
	Assertions.assertThat(card.getListTransactions().size()).isEqualTo(30);
	SimpleDateFormat sdf = new SimpleDateFormat("MM/yyyy");
	Assertions.assertThat(sdf.format(card.getExpireDate())).isEqualTo("09/2015");
	Assertions.assertThat(card.isNfcLocked()).isFalse();
}
 
開發者ID:devnied,項目名稱:EMV-NFC-Paycard-Enrollment,代碼行數:24,代碼來源:EmvParserTest.java

示例10: testPPSEVisa3

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
@Test
public void testPPSEVisa3() throws CommunicationException {

	IProvider prov = new PpseProviderVisa3Test();

	EmvParser parser = new EmvParser(prov, true);
	EmvCard card = parser.readEmvCard();

	if (card != null) {
		LOGGER.debug(card.toString());
	}
	Assertions.assertThat(card).isNotNull();
	Assertions.assertThat(card.getAid()).isEqualTo("A0000000421010");
	Assertions.assertThat(card.getCardNumber()).isEqualTo("4999999999999999");
	Assertions.assertThat(card.getType()).isEqualTo(EmvCardScheme.VISA);
	Assertions.assertThat(card.getHolderFirstname()).isNull();
	Assertions.assertThat(card.getHolderLastname()).isNull();
	Assertions.assertThat(card.getApplicationLabel()).isEqualTo(null);
	Assertions.assertThat(card.getListTransactions().size()).isEqualTo(0);
	SimpleDateFormat sdf = new SimpleDateFormat("MM/yyyy");
	Assertions.assertThat(sdf.format(card.getExpireDate())).isEqualTo("06/2018");
	Assertions.assertThat(card.isNfcLocked()).isFalse();
}
 
開發者ID:devnied,項目名稱:EMV-NFC-Paycard-Enrollment,代碼行數:24,代碼來源:EmvParserTest.java

示例11: testPPSEVisaNullLog

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
@Test
public void testPPSEVisaNullLog() throws CommunicationException {

	IProvider prov = new PpseProviderVisaNulTransactionsTest();

	EmvParser parser = new EmvParser(prov, true);
	EmvCard card = parser.readEmvCard();

	if (card != null) {
		LOGGER.debug(card.toString());
	}
	Assertions.assertThat(card).isNotNull();
	Assertions.assertThat(card.getAid()).isEqualTo("A0000000421010");
	Assertions.assertThat(card.getCardNumber()).isEqualTo("4999999999999999");
	Assertions.assertThat(card.getType()).isEqualTo(EmvCardScheme.VISA);
	Assertions.assertThat(card.getHolderLastname()).isNull();
	Assertions.assertThat(card.getHolderFirstname()).isNull();
	Assertions.assertThat(card.getApplicationLabel()).isEqualTo("CB");
	Assertions.assertThat(card.getListTransactions().size()).isEqualTo(0);
	SimpleDateFormat sdf = new SimpleDateFormat("MM/yyyy");
	Assertions.assertThat(sdf.format(card.getExpireDate())).isEqualTo("09/2015");
	Assertions.assertThat(card.isNfcLocked()).isFalse();
}
 
開發者ID:devnied,項目名稱:EMV-NFC-Paycard-Enrollment,代碼行數:24,代碼來源:EmvParserTest.java

示例12: testPPSEMasterCard

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
@Test
public void testPPSEMasterCard() throws CommunicationException {

	IProvider prov = new PpseProviderMasterCardTest();

	EmvParser parser = new EmvParser(prov, true);
	EmvCard card = parser.readEmvCard();

	if (card != null) {
		LOGGER.debug(card.toString());
	}
	Assertions.assertThat(card).isNotNull();
	Assertions.assertThat(card.getAid()).isEqualTo("A0000000421010");
	Assertions.assertThat(card.getCardNumber()).isEqualTo("5599999999999999");
	Assertions.assertThat(card.getType()).isEqualTo(EmvCardScheme.MASTER_CARD);
	Assertions.assertThat(card.getHolderLastname()).isNull();
	Assertions.assertThat(card.getHolderFirstname()).isNull();
	Assertions.assertThat(card.getApplicationLabel()).isEqualTo("CB");
	Assertions.assertThat(card.getListTransactions()).isEmpty();
	SimpleDateFormat sdf = new SimpleDateFormat("MM/yyyy");
	Assertions.assertThat(sdf.format(card.getExpireDate())).isEqualTo("09/2015");
	Assertions.assertThat(card.isNfcLocked()).isFalse();
}
 
開發者ID:devnied,項目名稱:EMV-NFC-Paycard-Enrollment,代碼行數:24,代碼來源:EmvParserTest.java

示例13: testPPSEVisa2

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
@Test
public void testPPSEVisa2() throws CommunicationException {

	IProvider prov = new PpseProviderVisa2Test();

	EmvParser parser = new EmvParser(prov, true);
	EmvCard card = parser.readEmvCard();

	if (card != null) {
		LOGGER.debug(card.toString());
	}
	Assertions.assertThat(card).isNotNull();
	Assertions.assertThat(card.getAid()).isEqualTo("A0000000421010");
	Assertions.assertThat(card.getCardNumber()).isEqualTo("4999999999999999");
	Assertions.assertThat(card.getType()).isEqualTo(EmvCardScheme.VISA);
	Assertions.assertThat(card.getHolderLastname()).isNull();
	Assertions.assertThat(card.getHolderFirstname()).isNull();
	Assertions.assertThat(card.getApplicationLabel()).isEqualTo("CB");
	SimpleDateFormat sdf = new SimpleDateFormat("MM/yyyy");
	Assertions.assertThat(sdf.format(card.getExpireDate())).isEqualTo("09/2015");
	Assertions.assertThat(card.isNfcLocked()).isFalse();
}
 
開發者ID:devnied,項目名稱:EMV-NFC-Paycard-Enrollment,代碼行數:23,代碼來源:EmvParserTest.java

示例14: testAid

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
@Test
public void testAid() throws CommunicationException {

	IProvider prov = new ProviderAidTest();

	EmvParser parser = new EmvParser(prov, true);
	EmvCard card = parser.readEmvCard();

	if (card != null) {
		LOGGER.debug(card.toString());
	}
	Assertions.assertThat(card).isNotNull();
	Assertions.assertThat(card.getAid()).isEqualTo("A0000000031010");
	Assertions.assertThat(card.getCardNumber()).isEqualTo("5772829193253472");
	Assertions.assertThat(card.getType()).isEqualTo(EmvCardScheme.VISA);
	Assertions.assertThat(card.getApplicationLabel()).isEqualTo("VISA");
	Assertions.assertThat(card.getHolderLastname()).isNull();
	Assertions.assertThat(card.getHolderFirstname()).isNull();
	SimpleDateFormat sdf = new SimpleDateFormat("MM/yyyy");
	Assertions.assertThat(sdf.format(card.getExpireDate())).isEqualTo("08/2014");
	Assertions.assertThat(card.isNfcLocked()).isFalse();
}
 
開發者ID:devnied,項目名稱:EMV-NFC-Paycard-Enrollment,代碼行數:23,代碼來源:EmvParserTest.java

示例15: readEmvCard

import com.github.devnied.emvnfccard.exception.CommunicationException; //導入依賴的package包/類
/**
 * Method used to read public data from EMV card
 *
 * @return data read from card or null if any provider match the card type
 */
public EmvCard readEmvCard() throws CommunicationException {
    // use PSE first
    if (!readWithPSE()) {
        // Find with AID
        readWithAID();
    }
    return card;
}
 
開發者ID:JackuyLiu,項目名稱:Android-NFC-Paycard-Reader,代碼行數:14,代碼來源:EmvParser.java


注:本文中的com.github.devnied.emvnfccard.exception.CommunicationException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。