Home  >  Article  >  Backend Development  >  tp5 uses Endroid to generate QR code

tp5 uses Endroid to generate QR code

不言
不言Original
2018-06-01 15:09:553477browse

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;
    }

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!

Statement:
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