tp5 uses Endroid to generate QR code

不言
Release: 2023-03-29 08:34:02
Original
3522 people have browsed it

This article mainly introduces how tp5 uses Endroid to generate QR codes. It has certain reference value. Now I share it with everyone. Friends in need can refer to it.

First of all, #composer require endroid/qrcode Go to my vendor library,
Then modify vendor/endroid/qrcode/src/Qrcode.php
LABEL_FONT_PATH_DEFAULT='';
Then directly upload the code

 // 分享图片[正经二维码]
    public function share(){
        // 前端带着code访问我这个接口,然后请求到openid,拼成到个人中心的url再生成二维码
        $url = 'http://www.baidueeeeeeee.com?id=33';        
        $qrCode = new QrCode();        
        $qrCode->setText($url)
            ->setSize(300)//大小
            ->setLabelFontPath(VENDOR_PATH.'endroid\qrcode\assets\noto_sans.otf')
            ->setErrorCorrectionLevel('high')
            ->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))
            ->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0))
            ->setLabelFontSize(16);
        header('Content-Type: '.$qrCode->getContentType());        
        echo $qrCode->writeString();       
        exit;
    }
Copy after login

Just call my method name directly on the front end

Related recommendations:

tp5 (thinkPHP5) Detailed explanation of the steps to operate the mongoDB database

The above is the detailed content of tp5 uses Endroid to generate QR code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!