zoukankan      html  css  js  c++  java
  • qrcode length overflow (1632>1056)--qrcode.js使用过程中二维码长度溢出解决办法

      近日在开发过程中需要为页面动态生成一个二维码信息,由于这个二维码中包含了很多文字,字母以及符号,测试过程中发现有些二维码会报错,因为二维码内容太多了,没办法显示。后来在GitHub中找到了解决办法。

    这是源码中修改前的内容:

    make:function(){this.makeImpl(false,this.getBestMaskPattern());}

    QRCode.prototype.makeCode = function (sText) { this._oQRCode = new QRCodeModel(_getTypeNumber(sText, this._htOption.correctLevel), this._htOption.correctLevel); this._oQRCode.addData(sText); this._oQRCode.make(); this._el.title = sText; this._oDrawing.draw(this._oQRCode); this.makeImage(); };

    这是修改后的内容:

    make:function(){
    if(this.typeNumber<1){
    var typeNumber = 1;
    for (typeNumber = 1;typeNumber<40;typeNumber++){
    var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel);
    var buffer = new QRBitBuffer();var totalDataCount = 0;
    for(var i=0;i<rsBlocks.length;i++) {
      totalDataCount+=rsBlocks[i].dataCount;
    }
    for (var i = 0; i < this.dataList.length; i++) {
      var data = this.dataList[i];
      buffer.put(data.mode, 4);
      buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber));
      data.write(buffer);}
    if (buffer.getLengthInBits() <= totalDataCount * 8)break;}
      this.typeNumber = typeNumber;
    }



    QRCode.prototype.makeCode = function (sText) {
    this._oQRCode = new QRCodeModel(-1, this._htOption.correctLevel);
    this._oQRCode.addData(sText);
    this._oQRCode.make();
    this._el.title = sText;
    this._oDrawing.draw(this._oQRCode);
    this.makeImage();
    };
  • 相关阅读:
    java中4种修饰符访问权限的区别
    Java中List的排序方法
    Hibernate事务
    @Component、@Service、@Constroller
    MySQL查看一个表的创建文本以及删除表某列的索引
    深入Session2
    Tomcat容器的Session管理
    深入Session
    使用spring mvc或者resteasy构建restful服务
    Spring MVC学习回顾
  • 原文地址:https://www.cnblogs.com/Miracle-ZLZ/p/7723857.html
Copyright © 2011-2022 走看看