QRicketProvider.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace RobThree\Auth\Providers\Qr;
  3. // http://qrickit.com/qrickit_apps/qrickit_api.php
  4. class QRicketProvider extends BaseHTTPQRCodeProvider
  5. {
  6. /** @var string */
  7. public $errorcorrectionlevel;
  8. /** @var string */
  9. public $bgcolor;
  10. /** @var string */
  11. public $color;
  12. /** @var string */
  13. public $format;
  14. /**
  15. * @param string $errorcorrectionlevel
  16. * @param string $bgcolor
  17. * @param string $color
  18. * @param string $format
  19. */
  20. public function __construct($errorcorrectionlevel = 'L', $bgcolor = 'ffffff', $color = '000000', $format = 'p')
  21. {
  22. $this->verifyssl = false;
  23. $this->errorcorrectionlevel = $errorcorrectionlevel;
  24. $this->bgcolor = $bgcolor;
  25. $this->color = $color;
  26. $this->format = $format;
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function getMimeType()
  32. {
  33. switch (strtolower($this->format)) {
  34. case 'p':
  35. return 'image/png';
  36. case 'g':
  37. return 'image/gif';
  38. case 'j':
  39. return 'image/jpeg';
  40. }
  41. throw new QRException(sprintf('Unknown MIME-type: %s', $this->format));
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function getQRCodeImage($qrtext, $size)
  47. {
  48. return $this->getContent($this->getUrl($qrtext, $size));
  49. }
  50. /**
  51. * @param string $qrtext the value to encode in the QR code
  52. * @param int|string $size the desired size of the QR code
  53. *
  54. * @return string file contents of the QR code
  55. */
  56. public function getUrl($qrtext, $size)
  57. {
  58. return 'http://qrickit.com/api/qr'
  59. . '?qrsize=' . $size
  60. . '&e=' . strtolower($this->errorcorrectionlevel)
  61. . '&bgdcolor=' . $this->bgcolor
  62. . '&fgdcolor=' . $this->color
  63. . '&t=' . strtolower($this->format)
  64. . '&d=' . rawurlencode($qrtext);
  65. }
  66. }