index.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. {
  26. //processing form input
  27. //remember to sanitize user input in real-life solution !!!
  28. private $errorCorrectionLevel = 'H'; // L M Q H
  29. private $matrixPointSize = 3; // 1 2 3 4 5 6 7 8 9 10
  30. private $date = 'shopnc';
  31. private $pngTempDir = '';
  32. private $pngTempName = '';
  33. /**
  34. * 设置
  35. */
  36. public function set($key,$value){
  37. $this->$key = $value;
  38. }
  39. public function __construct() {
  40. include "qrlib.php";
  41. }
  42. public function init()
  43. {
  44. //ofcourse we need rights to create temp dir
  45. if (!file_exists($this->pngTempDir))
  46. mkdir($this->pngTempDir);
  47. if ($this->date != 'shopnc')
  48. {
  49. // user data
  50. if ($this->pngTempName != '') {
  51. $filename = $this->pngTempDir.$this->pngTempName;
  52. } else {
  53. $filename = $this->pngTempDir.'test'.md5($this->date.'|'.$this->errorCorrectionLevel.'|'.$this->matrixPointSize).'.png';
  54. }
  55. QRcode::png($this->date, $filename, $this->errorCorrectionLevel, $this->matrixPointSize, 2);
  56. }
  57. else {
  58. //default data
  59. QRcode::png('http://www.baidu.com', $filename, $this->errorCorrectionLevel, $this->matrixPointSize, 2);
  60. }
  61. //display generated file
  62. return basename($filename);
  63. //QRtools::timeBenchmark();
  64. }
  65. }