从前端谈二维码的解析与生成过程

Posted 骑着代马去流浪

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从前端谈二维码的解析与生成过程相关的知识,希望对你有一定的参考价值。

Technology Architecture

How to parse the QR code by RN 

  1. QR handles are independent and non-conflicting matching and parsing logic.
  2. EMVCo is just a format, specific services may include QRIS, Duitnow, NETS, etc.
  3. If matched, it will be parsed into a object carried by the QR code, including type, content, merchantName, merchantCity, countryCode...

 QR code parsing rules

        Here we mainly talk about EMVCo rules, other rules are relatively simple, if you don't know about EMVCo, please click this link.

  1. It can be clearly seen that starting from the first digit, the first two digits are the ID, the next two digits are the length, and then the digits of the changed length are intercepted as the value.
  2. But the value may also be of subSchema type. When it is of subSchema type, value itself also conforms to EMVCo rules.

For example 

00020101021226610016ID.CO.SHOPEE.WWW01189360091800200869990208200869990303UMI520453995303360540869300.005802ID5912Epoint DUMMY6015KOTA JAKARTA UT61051446062330521628008-A000037-1156460704T001630446E4

In fact, by EMVCo rule, we can parse it into

00 02 01 
01 02 12 
26 61 00 16 ID.CO.SHOPEE.WWW
      01 18 936009180020086999 
      02 08 20086999
      03 03 UMI 
52 04 5399 
53 03 360 
54 08 69300.00
58 02 ID 
59 12 Epoint DUMMY
60 15 KOTA JAKARTA UT
61 05 14460
62 33 05 21 628008-A000037-115646
      07 04 T001
63 04 46E4

Finally, how to generate an object with key name ?

yes, you guessed it right, according to many schemas.

...
const EMVCoSchema: Schema<QRISData> = [
  
    ids: '01',
    name: 'pointOfInitiationMethod',
    mandatory: false,
    type: 'string',
  ,
  
    ids: ['26', '45'],
    name: 'merchantAccountInformation',
    mandatory: true,
    type: 'subSchemaById',
    schema: EMVCoMerchantSchema,
  ,
  
    ids: '51',
    name: 'merchantAccountInformation',
    mandatory: false,
    type: 'subSchemaById',
    schema: EMVCoMerchantSchema
  
];
...

So, the flow looks like this

How to generate a QR code 

        According to the actual situation, the QR code generation rules of `C scan B` and `B scan C` are different.

        In addition, there is a difference between static QR code and dynamic QR code. Dynamic QR code contains Amount information, but static QR code does not.

以上是关于从前端谈二维码的解析与生成过程的主要内容,如果未能解决你的问题,请参考以下文章

从前端谈二维码的解析与生成过程

从前端谈二维码的解析与生成过程

浅谈浏览器解析 URL+DNS 域名解析+TCP 三次握手与四次挥手+浏览器渲染页面

qrcode.js的识别解析二维码图片和生成二维码图片

Java使用QRCode.jar生成与解析二维码

java实现二维码的生成与解析