Ai có thuật toán giải mã thì cho em xin với ạ, code js thì càng tốt ạ.
Em cảm ơn!
Giải quyết
Cảm ơn anh @tdv12, đoạn code sau hỗ trợ dịch ngược QRcode sang thông tin ngân hàng, có hỗ trợ không có thông tin số tiền và nội dung chuyển tiền:
Ngôn ngữ JAVA
package com.thiendz.test; import java.util.HashMap; import java.util.Map; public class VietQRDecoder { private static final String PREFIX = "000201010212"; private static final String SUFFIX = "6304"; private static final String PART_11_PREFIX = "0010A00000072701"; private static final String PART_2_PREFIX = "5303704"; private static final String AMOUNT_HEADER = "54"; private static final String PART_21_PREFIX = "5802VN62"; private static final int CHECK_SUM_LENGTH = 4; public static void main(String[] args) { Map<String, String> information = new HashMap<>(); // String input = "00020101021238540010A00000072701240006970436011010137721710208QRIBFTTA530370454061000005802VN62090805Hello63049F12"; // String input = "00020101021238560010A0000007270126000697100501121133666688880208QRIBFTTA53037045802VN6304AAAB"; // String input = "00020101021238580010A000000727012800069704070114190375154450150208QRIBFTTA53037045802VN62120808BTEST001630478FB"; // String input = "00020101021238580010A000000727012800069704070114190375154450150208QRIBFTTA53037045802VN62120808BTEST00263049629"; String input = "00020101021238580010A000000727012800069704150114190375154450150208QRIBFTTA5303704540410005802VN6304DDD5"; String parts = input.substring( PREFIX.length(), input.length() - SUFFIX.length() - CHECK_SUM_LENGTH ); parts = parts.substring(2); int part1Length = Integer.parseInt(parts.substring(0, 2)); parts = parts.substring(2); String part1 = parts.substring(0, part1Length); part1 = part1.substring(PART_11_PREFIX.length()); int part12Length = Integer.parseInt(part1.substring(0, 2)); part1 = part1.substring(2); String part12 = part1.substring(0, part12Length); part12 = part12.substring(2); int bankIdLength = Integer.parseInt(part12.substring(0, 2)); part12 = part12.substring(2); String bankId = part12.substring(0, bankIdLength); information.put("bankId", bankId); part12 = part12.substring(bankIdLength); part12 = part12.substring(2); int bankAccountLength = Integer.parseInt(part12.substring(0, 2)); part12 = part12.substring(2); String bankAccount = part12.substring(0, bankAccountLength); information.put("bankAccount", bankAccount); parts = parts.substring(part1Length); String part2 = parts.substring(PART_2_PREFIX.length()); information.put("amount", "0"); if (part2.startsWith(AMOUNT_HEADER)) { part2 = part2.substring(2); int amountLength = Integer.parseInt(part2.substring(0, 2)); part2 = part2.substring(2); String amount = part2.substring(0, amountLength); information.put("amount", amount); part2 = part2.substring(amountLength); } information.put("message", ""); if (part2.length() - PART_21_PREFIX.length() > PART_21_PREFIX.length()) { part2 = part2.substring(PART_21_PREFIX.length()); int part21Length = Integer.parseInt(part2.substring(0, 2)); part2 = part2.substring(2); String part21 = part2.substring(0, part21Length); part21 = part21.substring(2); int messageLength = Integer.parseInt(part21.substring(0, 2)); part21 = part21.substring(2); String message = part21.substring(0, messageLength); information.put("message", message); } System.out.println(information); } }
Ngôn ngữ Js
class Qr { static PREFIX = '000201010212'; static SUFFIX = '6304'; static PART_11_PREFIX = '0010A00000072701'; static PART_2_PREFIX = '5303704'; static AMOUNT_HEADER = '54'; static PART_21_PREFIX = '5802VN62'; static CHECK_SUM_LENGTH = 4; static decoder(input) { let parts = input.substring( Qr.PREFIX.length, input.length - Qr.SUFFIX.length - Qr.CHECK_SUM_LENGTH ); parts = parts.substring(2); let part1Length = parseInt(parts.substring(0, 2)); parts = parts.substring(2); let part1 = parts.substring(0, part1Length); part1 = part1.substring(Qr.PART_11_PREFIX.length); let part12Length = parseInt(part1.substring(0, 2)); part1 = part1.substring(2); let part12 = part1.substring(0, part12Length); part12 = part12.substring(2); let bankIdLength = parseInt(part12.substring(0, 2)); part12 = part12.substring(2); let bankId = part12.substring(0, bankIdLength); part12 = part12.substring(bankIdLength); part12 = part12.substring(2); let bankAccountLength = parseInt(part12.substring(0, 2)); part12 = part12.substring(2); let bankAccount = part12.substring(0, bankAccountLength); let amount = 0; parts = parts.substring(part1Length); let part2 = parts.substring(Qr.PART_2_PREFIX.length); console.log(part2) if (part2.startsWith(Qr.AMOUNT_HEADER)) { part2 = part2.substring(2); let amountLength = parseInt(part2.substring(0, 2)); part2 = part2.substring(2); amount = part2.substring(0, amountLength); part2 = part2.substring(amountLength); } let message = ''; if (part2.length - Qr.PART_21_PREFIX.length > Qr.PART_21_PREFIX.length) { part2 = part2.substring(Qr.PART_21_PREFIX.length); let part21Length = parseInt(part2.substring(0, 2)); part2 = part2.substring(2); let part21 = part2.substring(0, part21Length); part21 = part21.substring(2); let messageLength = parseInt(part21.substring(0, 2)); part21 = part21.substring(2); message = part21.substring(0, messageLength); } return { bankId, bankAccount, amount, message }; } } console.log(Qr.decoder('00020101021238580010A000000727012800069704150114190375154450150208QRIBFTTA5303704540410005802VN6304DDD5'))