Home  >  Article  >  Backend Development  >  thinkphp5 framework and Android implement QR code generation code

thinkphp5 framework and Android implement QR code generation code

不言
不言Original
2018-08-06 09:59:422332browse

This article introduces you to the thinkphp5 framework and Android implementation of QR code generation code. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Windows compser installs endroid/qrcode, and installs the composer tool yourself;

1. Add "endroid/qrcode" to the project directory file composer.json

require : "2.5.1" (The endroid version fills in the corresponding version according to the php version)

Configure the Chinese image download path

1 "repositories": {
2         "packagist": {
3             "type": "composer",
4             "url": " 
5         }
6     }

2 . cmd switch to the project directory and enter the command

composer require endroid/qrcode

3. PHP controller introduction

use Endroid\QrCode\QrCode;

    $qrCode=new QrCode();
        $url = 'A150';

        $qrCode->setText($url)
            ->setSize(200)//大小
            ->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))
            ->setLabel('桌码  A150')
            ->setLabelFontSize(16);

        header('Content-Type: '.$qrCode->getContentType());

        ob_clean();  /*解决提示 图像错误,无法显示问题*/

        echo $qrCode->writeString();
        exit;

Recommended related articles:

Steps for php to implement verification code and server-side verification code

How to use PHP to read the contents of excel files and obtain cells data

The above is the detailed content of thinkphp5 framework and Android implement QR code generation 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