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


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

我正在使用QR生成器并为此使用google API。我正在生成一个二维码,它有一个URL,或者我们可以说二维码中的网站链接。当我打印它时,链接是正确的。但问题是,当我将它传递给QR生成器时,链接不正确。正确的链接是这样的。(http://localhost/crs/web/index.php/birthPublicSearch/birthCertificate/view/cert/B/MTc5OQ%3D%3D)。但在二维码中/MC5OQ之后的字符没有显示在链接中,这意味着%3D%3D没有显示在二维码图像中。有人能帮我吗。下面是我的代码。另一个问题是,当我用手机重定向到编码图像的url时,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:时,您必须自己对参数运行urlencode函数

$data='localhost/web/index.php/birthPublicSearch/birthCertificate/view/cert/B/' . urlencode($unique_value) . '%3D%3D';

你必须在这里进行urlencode的原因是,你不仅有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>