|
|
|
|
Strumenti |
02-03-2018, 21:16 | #1 |
Senior Member
Iscritto dal: Jul 2005
Città: San Marino
Messaggi: 308
|
[PHP] aiutino su array di bytes
Buonasera a tutti, avrei bisogno di un vostro prezioso aiuto.
Praticamente dovrei inviare un'array di bytes con una connessione UDP in socket. Ho a disposizione il codice in java, dovrei fare la stessa cosa però in php Codice:
bb = ByteBuffer.allocate(1024); bb.position(2); // leave the first two bytes for the length bb.put((byte) 0xA1); // auth request bb.put((byte) 0xB0); // operation type bb.put((byte) currency); // currency type bb.put(String.format("%09d", this.amount).getBytes()); // purchase amount bb.put((byte) 0xFF); // manual trans., that is the track data to be read by WEClient bb.put(String.format("%8s", "").getBytes()); // cashier bb.put(String.format("%8s", "").getBytes()); // receipt number bb.put((byte) 0x00); // plug-in bb.put((byte) 0x00); // RFU bb.put(String.format("%09d", amount).getBytes()); // total amount bb.put((byte) 0x00); // track1 length bb.put((byte) 0x00); // track2 length bb.put((byte) 0x00); // track3 length // extra data length bb.put((byte) 0x00).put((byte) 0x07); // 2-byte extra data length // extra data: setting English as trx language bb.put((byte) 0x1F).put((byte) 0x80).put((byte) 0x1A); // tag 1F801A bb.put((byte) 0x03); // value length: 3 bytes bb.put((byte) 0x07); // always 0x07 bb.put((byte) 0x65).put((byte) 0x6E); // 'en' short msglen = (short) (bb.limit() - bb.remaining()); ByteBuffer bb2 = ByteBuffer.allocate(2); bb2.putShort(msglen); byte[] bMsgLen = bb2.array(); int curPosition = bb.position(); bb.position(0); bb.put(bMsgLen); byte[] a = bb.array(); byte[] bytecrc = null; bytecrc = crc.calc_crc(a, (int) msglen); bb.position(curPosition); bb.put(bytecrc); bb.limit(bb.position()); byte[] bbArray = bb.array(); byte[] msg = new byte[bb.position()]; for (int i=0; i<bb.position(); i++) { msg[i] = bbArray[i]; }
__________________
|
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 10:43.