PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

博客列表 > tp5生成二维码

tp5生成二维码

星辰幽梦
星辰幽梦 原创
2020年04月24日 15:39:09 1877浏览

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. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议