<a href="javascript:;" data-url="{$vo.url}" class="info_generate_qr">生成二维码</a>
$(".info_generate_qr").on('click', function () {
let url = $(this).data('url');
window.open('__APP__/Women/generate_qr?url='+encodeURIComponent(url));
});
/**
* 生成二维码
*/
public function generate_qr() {
$url = $_GET['url'];
$qrCode = new QrCode();
$qrCode->setText($url)
->setSize(300)
->setPadding(10)
->setErrorCorrection('high')
->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0])
->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0])
->setLabelFontSize(16)
->setImageType(QrCode::IMAGE_TYPE_PNG);
header('Content-Type: '.$qrCode->getContentType());
$qrCode->render();
}
这里的encodeURIComponent,很重要。否则获取url参数的时候,容易造成数据丢失。