Blogger Information
Blog 17
fans 0
comment 0
visits 23399
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
tp5生成二维码
星辰幽梦
Original
1911 people have browsed it

tp5生成二维码

1.下载endroid扩展

  1. #composer require endroid/qrcode

2.实现代码(生成二维码图片)

  1. public function index(){
  2. $qrCode = new QrCode('http://baidu.com/');
  3. $qrCode->setSize(150);
  4. // 边框宽度
  5. $qrCode->setMargin(2);
  6. // 图片格式
  7. $qrCode->setWriterByName('png');
  8. // 字符编码
  9. $qrCode->setEncoding('UTF-8');
  10. // 颜色设置,前景色,背景色(默认黑白)
  11. $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
  12. $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
  13. header('Content-Type: ' . $qrCode->getContentType());
  14. // 容错等级,分为L、M、Q、H四级
  15. $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH());
  16. $sha1 = sha1('yhq6584');
  17. $path = substr($sha1, 0, 2) .'/'. substr($sha1, 2, 3) . '/';
  18. $qrcode_dir = ROOT_PATH.'public/uploads/' . $path;
  19. if (!file_exists($qrcode_dir)) mkdir($qrcode_dir, 0777, true);
  20. $code_path = $qrcode_dir .$sha1 . '.png';
  21. $code_logo = ROOT_PATH.'public\uploads\head\20200317\c15342e43d82a8c83604d84195c1d068.jpg';
  22. $qrCode->setLabel('手机扫一扫', 12);
  23. $qrCode->setLogoPath($code_logo);
  24. $qrCode->setLogoWidth(64);
  25. $qrCode->writeFile($code_path);
  26. // return $this->redirect('Login/indexYhq');
  27. // echo date('Y-m-d H:i:s',2437112213);
  28. echo $path.$sha1 . '.png';
  29. }
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post