为什么 QR 生成器在生成的 QR 图像中没有给我正确的 URL?

Why QR Generator does not give me the correct URL in the generated QR Image?

我正在使用 QR 生成器并为此使用 google API。我正在生成一个带有 URL 的 QR 码,或者我们可以在 QR 码中对网站说 link。 link 在我打印时是正确的但问题是当我将它传递给 QR 生成器时,link 不正确。正确的link是这样的。 (http://localhost/crs/web/index.php/birthPublicSearch/birthCertificate/view/cert/B/MTc5OQ%3D%3D)。但在二维码中,/MTC5OQ 之后的字符没有显示在 link 中意味着 %3D%3D 在 QR Image 中没有显示。谁可以帮我这个事。下面是我的代码。 另一个问题也是,当我重定向到 url 使用我的单元格 phone 编码图像时, url 中的斜杠更改为 %2F 并且 url 无法打开并显示一条感谢您使用 Neo Reader 的消息。我该如何解决。

<?php
class QRGenerator { 
protected $size; 
protected $data; 
protected $encoding; 
protected $errorCorrectionLevel; 
protected $marginInRows;
protected $debug; 

public function __construct($data,$size='100',$encoding='UTF-8',$errorCorrectionLevel='L',$marginInRows=4,$debug=false) { 

    $this->data=urlencode($data); 
    $this->size=100;
    $this->encoding=($encoding == 'Shift_JIS' || $encoding == 'ISO-8859-1' || $encoding == 'UTF-8') ? $encoding : 'UTF-8'; 
    $this->errorCorrectionLevel=($errorCorrectionLevel == 'L' || $errorCorrectionLevel == 'M' || $errorCorrectionLevel == 'Q' || $errorCorrectionLevel == 'H') ?  $errorCorrectionLevel : 'L';
    $this->marginInRows=($marginInRows>0 && $marginInRows<10) ? $marginInRows:4; 
    $this->debug = ($debug==true)? true:false;     
} 
public function generate(){ 

    $QRLink = "https://chart.googleapis.com/chart?cht=qr&chs=".$this->size."x".$this->size.                 
               "&chl=" . $this->data .  
               "&choe=" . $this->encoding . 
               "&chld=" . $this->errorCorrectionLevel . "|" . $this->marginInRows; 
if ($this->debug) echo $QRLink;          
return $QRLink;} } ?>

而我打印二维码的TD是:

<td align="center" valign="top">
    <div style="float: left; margin-left: -230px; margin-top: 34px; padding-right: 20px;">
     <script type="text/javascript">                                                                            
       (function() {
         var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
          po.src = 'https://apis.google.com/js/plusone.js';
          var s = document.getElementsByTagName('script')[0];     
          s.parentNode.insertBefore(po, s);
     });
      </script>
  </div>                                                   
<?php


$unique_value = base64_encode($birhtId);// Unique Value is MTc5OQ

$data='localhost/web/index.php/birthPublicSearch/birthCertificate/view/cert/B/'.$unique_value.'%3D%3D';
$size='200';
$ex1 = new QRGenerator($data,$size); 
$img1 = "<img src=".$ex1->generate().">";
$content ='<table>
    <tr>
         <td colspan="2">'.$img1.'</td>
    </tr>                                                                     
  </table>';                                                         
    print_r($content);
?>
</td>

因为在构建 url:

时,您必须 运行 自己对参数进行 url 编码函数
$data='localhost/web/index.php/birthPublicSearch/birthCertificate/view/cert/B/' . urlencode($unique_value) . '%3D%3D';

您必须在此处 url 编码的原因是因为您不仅有 MTc5OQ,还有 MTc5OQ=== 需要编码。

你也应该考虑在另一个地方做同样的事情:

$QRLink = "https://chart.googleapis.com/chart?cht=qr&chs=" . urlencode($this->size."x".$this->size) .                 
           "&chl=" . urlencode($this->data) .  
           "&choe=" . urlencode($this->encoding) . 
           "&chld=" . urlencode($this->errorCorrectionLevel . "|" . $this->marginInRows);
<?php
class QRGenerator { 
protected $size; 
protected $data; 
protected $encoding; 
protected $errorCorrectionLevel; 
protected $marginInRows;
protected $debug; 

public function __construct($data,$size='100',$encoding='UTF-8',$errorCorrectionLevel='L',$marginInRows=4,$debug=false) { 

    $this->data=$data; // This is where I changed
    $this->size=100;
    $this->encoding=($encoding == 'Shift_JIS' || $encoding == 'ISO-8859-1' || $encoding == 'UTF-8') ? $encoding : 'UTF-8'; 
    $this->errorCorrectionLevel=($errorCorrectionLevel == 'L' || $errorCorrectionLevel == 'M' || $errorCorrectionLevel == 'Q' || $errorCorrectionLevel == 'H') ?  $errorCorrectionLevel : 'L';
    $this->marginInRows=($marginInRows>0 && $marginInRows<10) ? $marginInRows:4; 
    $this->debug = ($debug==true)? true:false;     
} 
public function generate(){ 

    $QRLink = "https://chart.googleapis.com/chart?cht=qr&chs=". urlencode($this->size."x".$this->size) .                 
               "&chl=" . $this->data .  // This is where I changed
               "&choe=" .urlencode($this->encoding) . 
               "&chld=" .urlencode($this->errorCorrectionLevel . "|" . $this->marginInRows); 
    if ($this->debug) echo $QRLink;          
    return $QRLink; 
} 
} 
?>

而我们要显示二维码的地方,放这个代码:

<td align="center" valign="top">
<div style="float: left; margin-left: -230px; margin-top: 34px; padding-right: 20px;">
        <script type="text/javascript">
          (function() {
            var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
            po.src = 'https://apis.google.com/js/plusone.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
          });();
        </script>
</div>

<?php
        $birhtId='1234';
        $bir_id = base64_encode($birhtId);

$data='crsdemo.lsipl.com/crs/web/index.php/birthPublicSearch/birthCertificate/view/cert/B/'.urlencode($bir_id);
        ?>
        <script>
            console.log("<?php echo $data ?>");
        </script>
        <?php
        $size='200';
        $ex1 = new QRGenerator($data,$size); 
        $img1 = "<img src=".$ex1->generate().">";
        $content ='<table>
                    <tr>
                        <td colspan="2">'.$img1.'</td>
                    </tr>              
                </table>';
        print_r($content);
?>
</td>