登录  /  注册
博主信息
博文 17
粉丝 0
评论 0
访问量 27290
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
tp5生成二维码
星辰幽梦
原创
2072人浏览过

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举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学