APDU instruction Learning: How to read the balance of an NFC mobile wallet

Source: Internet
Author: User


Select PSF (1PAY. SYS. DDF01)/*--------------------------------------------------------------*/
Beijing. Util.log ("Select File:tag.selectByName (Dfn_pse)");
if (Tag.selectbyname (dfn_pse). Isokey ()) {


Protected final static byte[] Dfn_pse = {(byte) ' 1 ', (byte) ' P ',
(byte) ' A ', (byte) ' Y ', (Byte) '. ', (byte) ' S ', (byte) ' Y ',
(byte) ' S ', (Byte) '. ', (byte) ' d ', (byte) ' d ', (byte) ' F ',
(byte) ' 0 ', (byte) ' 1 ',}; 1PAY. SYS. DDF01


name = Dfn_pse;

Bytebuffer buff = bytebuffer.allocate (name.length + 6);
Buff.put ((byte) 0x00); CLA Class
Buff.put ((byte) 0xa4); INS instruction
Buff.put ((byte) 0x04); P1 Parameter 1 SELECT by NAME
Buff.put ((byte) 0x00); P2 Parameter 2
Buff.put ((byte) name.length); Lc
Buff.put (name); Buff.put ((byte) 0x00); Le

Select Command Reference
The 1th part of the electronic wallet electronic passbook Application card specification
Table SELECT Command Message
Table-SELECT Command Reference control parameters


If the end of the returned result is 0x9000, the select succeeds


==============================================
Sfi_extra_log = 4;
Read Card info file, binary (4)
/*--------------------------------------------------------------*/
INFO = Tag.readbinary (Sfi_extra_log);
==============================================
sfi_extra_cnt = 5;
Read Card operation file, binary (5)
/*--------------------------------------------------------------*/
CNT = Tag.readbinary (sfi_extra_cnt);

Public Response readbinary (int sfi) {
Final byte[] cmd = {(byte) 0x00,//CLA Class
(byte) 0xb0,//INS instruction
(byte) (0x00000080 | (SFI & 0x1F),//P1 Parameter 1
(byte) 0x00,//P2 Parameter 2
(byte) 0x00,//Le
};
CNT = Tag.readbinary (sfi_extra_cnt);


Reference:
The 1th part of the electronic wallet electronic passbook Application card specification
Table READ BINARY Command message
==============================================
Actions before reading the balance
Select Main Application
Byte[] Dfi_ep = {(byte) 0x10, (byte) 0x01};
/*--------------------------------------------------------------*/
if (Tag.selectbyid (DFI_EP). Isokey ()) {


Public Response Selectbyid (byte[] name) {
Bytebuffer buff = bytebuffer.allocate (name.length + 6);
Buff.put ((byte) 0x00); CLA Class
Buff.put ((byte) 0xa4); INS instruction
Buff.put ((byte) 0x00); P1 Parameter 1 SELECT by ID
Buff.put ((byte) 0x00); P2 Parameter 2
Buff.put ((byte) name.length); Lc
Buff.put (name); Buff.put ((byte) 0x00); Le


return new Response (Transceive (Buff.array ()));
==============================================
Read balance
CASH = Tag.getbalance (true);


Public Response GetBalance (Boolean isep) {
Final byte[] cmd = {(byte) 0x80,//CLA Class
(byte) 0x5C,//INS instruction
(byte) 0x00,//P1 Parameter 1
(byte) (isep 2:1),//P2 Parameter 2
(byte) 0x04,//Le
};


Reference:
http://blog.csdn.net/jennyvenus/article/details/4183994
Get Balance (defined by PBOC)
5C 00 02 04


The 2nd part of the PBOC (electronic wallet-Electronic passbook Application Specification)
Table 2 Category bytes and instruction bytes for commands
Read balance (GET BALANCE)
' 5C ', ' 0X '

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.