File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace RobThree \Auth \Providers \Qr ;
4
+
5
+ // https://developers.google.com/chart/infographics/docs/qr_codes
6
+ class ChartGoogleQrCodeProvider extends BaseHTTPQRCodeProvider
7
+ {
8
+ /** @var string */
9
+ public $ errorcorrectionlevel ;
10
+
11
+ /** @var int */
12
+ public $ margin ;
13
+
14
+ /** @var string */
15
+ public $ encoding ;
16
+
17
+ /**
18
+ * @param string $errorcorrectionlevel
19
+ * @param int $margin
20
+ * @param string $encoding
21
+ */
22
+ public function __construct ($ errorcorrectionlevel = 'L ' , $ margin = 4 , $ encoding = 'UTF-8 ' )
23
+ {
24
+ $ this ->verifyssl = false ;
25
+
26
+ $ this ->errorcorrectionlevel = $ errorcorrectionlevel ;
27
+ $ this ->margin = $ margin ;
28
+ $ this ->encoding = $ encoding ;
29
+ }
30
+
31
+ /**
32
+ * {@inheritdoc}
33
+ */
34
+ public function getMimeType ()
35
+ {
36
+ return 'image/png ' ;
37
+ }
38
+
39
+ /**
40
+ * {@inheritdoc}
41
+ */
42
+ public function getQRCodeImage ($ qrtext , $ size )
43
+ {
44
+ return $ this ->getContent ($ this ->getUrl ($ qrtext , $ size ));
45
+ }
46
+
47
+ /**
48
+ * @param string $qrtext the value to encode in the QR code
49
+ * @param int|string $size the desired size of the QR code
50
+ *
51
+ * @return string file contents of the QR code
52
+ */
53
+ public function getUrl ($ qrtext , $ size )
54
+ {
55
+ return 'https://chart.googleapis.com/chart '
56
+ . '?chs= ' . $ size . 'x ' . $ size
57
+ . '&chld= ' . urlencode (strtoupper ($ this ->errorcorrectionlevel ) . '| ' . $ this ->margin )
58
+ . '&cht= ' . 'qr '
59
+ . '&chl= ' . rawurlencode ($ qrtext );
60
+ }
61
+ }
You can’t perform that action at this time.
0 commit comments