为什么QR生成器没有在生成的QR图像中为我提供正确的URL? [英] Why QR Generator does not give me the correct URL in the generated QR Image?

查看:47
本文介绍了为什么QR生成器没有在生成的QR图像中为我提供正确的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用QR生成器并使用Google API来实现这一点。我正在生成一个二维码,它有一个URL,或者我们可以说在二维码中链接到一个网站。当我打印它时,链接是正确的,但问题是,当我将它传递给QR生成器时,链接不正确。正确的链接如下所示。(http://localhost/crs/web/index.php/birthPublicSearch/birthCertificate/view/cert/B/MTc5OQ%3D%3D)。但在二维码中,/MTC5OQ之后的字符没有显示在链接中,意味着%3D%3d不在QR Image中显示。有人能在这件事上帮我吗?以下是我的代码。 另一个问题是,当我用手机重定向到编码图像的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);

这篇关于为什么QR生成器没有在生成的QR图像中为我提供正确的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆