GoogleQRCodeProvider.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace RobThree\Auth\Providers\Qr;
  3. // https://developers.google.com/chart/infographics/docs/qr_codes
  4. class GoogleQRCodeProvider extends BaseHTTPQRCodeProvider
  5. {
  6. public $errorcorrectionlevel;
  7. public $margin;
  8. function __construct($verifyssl = false, $errorcorrectionlevel = 'L', $margin = 1)
  9. {
  10. if (!is_bool($verifyssl))
  11. throw new \QRException('VerifySSL must be bool');
  12. $this->verifyssl = $verifyssl;
  13. $this->errorcorrectionlevel = $errorcorrectionlevel;
  14. $this->margin = $margin;
  15. }
  16. public function getMimeType()
  17. {
  18. return 'image/png';
  19. }
  20. public function getQRCodeImage($qrtext, $size)
  21. {
  22. return $this->getContent($this->getUrl($qrtext, $size));
  23. }
  24. public function getUrl($qrtext, $size)
  25. {
  26. return 'https://chart.googleapis.com/chart?cht=qr'
  27. . '&chs=' . $size . 'x' . $size
  28. . '&chld=' . $this->errorcorrectionlevel . '|' . $this->margin
  29. . '&chl=' . rawurlencode($qrtext);
  30. }
  31. }