index.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /*
  3. * PHP QR Code encoder
  4. *
  5. * Exemplatory usage
  6. *
  7. * PHP QR Code is distributed under LGPL 3
  8. * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 3 of the License, or any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. class PhpQRCode{
  25. //processing form input
  26. //remember to sanitize user input in real-life solution !!!
  27. private $errorCorrectionLevel = 'H'; // L M Q H
  28. private $matrixPointSize = 3; // 1 2 3 4 5 6 7 8 9 10
  29. private $date = 'shopnc';
  30. private $pngTempDir = '';
  31. private $pngTempName = '';
  32. /**
  33. * 设置
  34. */
  35. public function set($key,$value){
  36. $this->$key = $value;
  37. }
  38. public function __construct() {
  39. include "qrlib.php";
  40. }
  41. public function init(){
  42. //ofcourse we need rights to create temp dir
  43. if (!file_exists($this->pngTempDir))
  44. mkdir($this->pngTempDir);
  45. if ($this->date != 'shopnc') {
  46. // user data
  47. if ($this->pngTempName != '') {
  48. $filename = $this->pngTempDir.$this->pngTempName;
  49. } else {
  50. $filename = $this->pngTempDir.'test'.md5($this->date.'|'.$this->errorCorrectionLevel.'|'.$this->matrixPointSize).'.png';
  51. }
  52. QRcode::png($this->date, $filename, $this->errorCorrectionLevel, $this->matrixPointSize, 2);
  53. } else {
  54. //default data
  55. QRcode::png('http://www.baidu.com', $filename, $this->errorCorrectionLevel, $this->matrixPointSize, 2);
  56. }
  57. //display generated file
  58. return basename($filename);
  59. QRtools::timeBenchmark();
  60. }
  61. }