From 08846488cc78d5a416b15cf5cfd505a1b5b901de Mon Sep 17 00:00:00 2001 From: Milan Date: Sun, 3 Oct 2021 19:14:10 +0300 Subject: [PATCH 1/5] Implemented new ChartGoogleQrCodeProvider --- .../Qr/ChartGoogleQrCodeProvider.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 lib/Providers/Qr/ChartGoogleQrCodeProvider.php diff --git a/lib/Providers/Qr/ChartGoogleQrCodeProvider.php b/lib/Providers/Qr/ChartGoogleQrCodeProvider.php new file mode 100644 index 0000000..b682bff --- /dev/null +++ b/lib/Providers/Qr/ChartGoogleQrCodeProvider.php @@ -0,0 +1,61 @@ +verifyssl = false; + + $this->errorcorrectionlevel = $errorcorrectionlevel; + $this->margin = $margin; + $this->encoding = $encoding; + } + + /** + * {@inheritdoc} + */ + public function getMimeType() + { + return 'image/png'; + } + + /** + * {@inheritdoc} + */ + public function getQRCodeImage($qrtext, $size) + { + return $this->getContent($this->getUrl($qrtext, $size)); + } + + /** + * @param string $qrtext the value to encode in the QR code + * @param int|string $size the desired size of the QR code + * + * @return string file contents of the QR code + */ + public function getUrl($qrtext, $size) + { + return 'https://chart.googleapis.com/chart' + . '?chs=' . $size . 'x' . $size + . '&chld=' . urlencode(strtoupper($this->errorcorrectionlevel) . '|' . $this->margin) + . '&cht=' . 'qr' + . '&chl=' . rawurlencode($qrtext); + } +} From 49f681e90532fb66d5880aad37d2bce27d87da5c Mon Sep 17 00:00:00 2001 From: fman42 Date: Mon, 4 Oct 2021 15:00:06 +0300 Subject: [PATCH 2/5] Rename a class --- ...tGoogleQrCodeProvider.php => GoogleChartsQrCodeProvider.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename lib/Providers/Qr/{ChartGoogleQrCodeProvider.php => GoogleChartsQrCodeProvider.php} (95%) diff --git a/lib/Providers/Qr/ChartGoogleQrCodeProvider.php b/lib/Providers/Qr/GoogleChartsQrCodeProvider.php similarity index 95% rename from lib/Providers/Qr/ChartGoogleQrCodeProvider.php rename to lib/Providers/Qr/GoogleChartsQrCodeProvider.php index b682bff..4ec708f 100644 --- a/lib/Providers/Qr/ChartGoogleQrCodeProvider.php +++ b/lib/Providers/Qr/GoogleChartsQrCodeProvider.php @@ -3,7 +3,7 @@ namespace RobThree\Auth\Providers\Qr; // https://developers.google.com/chart/infographics/docs/qr_codes -class ChartGoogleQrCodeProvider extends BaseHTTPQRCodeProvider +class GoogleChartsQrCodeProvider extends BaseHTTPQRCodeProvider { /** @var string */ public $errorcorrectionlevel; From 0453a9434911b53ba2d9b96d6c5ca5a80e23d531 Mon Sep 17 00:00:00 2001 From: fman42 Date: Mon, 4 Oct 2021 15:01:04 +0300 Subject: [PATCH 3/5] Made verifySSL optional --- lib/Providers/Qr/GoogleChartsQrCodeProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Providers/Qr/GoogleChartsQrCodeProvider.php b/lib/Providers/Qr/GoogleChartsQrCodeProvider.php index 4ec708f..3b300ff 100644 --- a/lib/Providers/Qr/GoogleChartsQrCodeProvider.php +++ b/lib/Providers/Qr/GoogleChartsQrCodeProvider.php @@ -19,9 +19,9 @@ class GoogleChartsQrCodeProvider extends BaseHTTPQRCodeProvider * @param int $margin * @param string $encoding */ - public function __construct($errorcorrectionlevel = 'L', $margin = 4, $encoding = 'UTF-8') + public function __construct($errorcorrectionlevel = 'L', $margin = 4, $encoding = 'UTF-8', $verifySSL = true) { - $this->verifyssl = false; + $this->verifyssl = $verifySSL; $this->errorcorrectionlevel = $errorcorrectionlevel; $this->margin = $margin; From c01202bc100b4a94980031b80ff033db651a44c1 Mon Sep 17 00:00:00 2001 From: Milan Date: Sun, 17 Oct 2021 21:08:32 +0300 Subject: [PATCH 4/5] Make verifySSL argument as first option in constructor --- lib/Providers/Qr/GoogleChartsQrCodeProvider.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Providers/Qr/GoogleChartsQrCodeProvider.php b/lib/Providers/Qr/GoogleChartsQrCodeProvider.php index 3b300ff..1f8cfad 100644 --- a/lib/Providers/Qr/GoogleChartsQrCodeProvider.php +++ b/lib/Providers/Qr/GoogleChartsQrCodeProvider.php @@ -15,13 +15,18 @@ class GoogleChartsQrCodeProvider extends BaseHTTPQRCodeProvider public $encoding; /** + * @param bool $verifyssl * @param string $errorcorrectionlevel * @param int $margin * @param string $encoding */ - public function __construct($errorcorrectionlevel = 'L', $margin = 4, $encoding = 'UTF-8', $verifySSL = true) + public function __construct($verifyssl = false, $errorcorrectionlevel = 'L', $margin = 4, $encoding = 'UTF-8') { - $this->verifyssl = $verifySSL; + if (!is_bool($verifyssl)) { + throw new QRException('VerifySSL must be bool'); + } + + $this->verifyssl = $verifyssl; $this->errorcorrectionlevel = $errorcorrectionlevel; $this->margin = $margin; From 65b17bca5915c45b823d8644b13c4473b3813c06 Mon Sep 17 00:00:00 2001 From: Milan Date: Sun, 17 Oct 2021 21:21:54 +0300 Subject: [PATCH 5/5] Add encoding option in query to google API --- lib/Providers/Qr/GoogleChartsQrCodeProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Providers/Qr/GoogleChartsQrCodeProvider.php b/lib/Providers/Qr/GoogleChartsQrCodeProvider.php index 1f8cfad..1118ea7 100644 --- a/lib/Providers/Qr/GoogleChartsQrCodeProvider.php +++ b/lib/Providers/Qr/GoogleChartsQrCodeProvider.php @@ -61,6 +61,7 @@ public function getUrl($qrtext, $size) . '?chs=' . $size . 'x' . $size . '&chld=' . urlencode(strtoupper($this->errorcorrectionlevel) . '|' . $this->margin) . '&cht=' . 'qr' + . '&choe=' . $this->encoding . '&chl=' . rawurlencode($qrtext); } }