<?php class QRGenerator { protected $qr_size; protected $qr_data; protected $qr_encoding; protected $qr_errorCorrectionLevel; protected $qr_marginInRows; protected $qr_debug; public function __construct($qr_data='',$qr_size='300',$qr_encoding='UTF-8',$errorCorrectionLevel='L',$qr_marginInRows=4,$qr_debug=false) { $this->qr_data=urlencode($qr_data); $this->qr_size=($qr_size>100 && $qr_size<800)? $qr_size : 300; $this->qr_encoding=($qr_encoding == 'Shift_JIS' || $qr_encoding == 'ISO-8859-1' || $qr_encoding == 'UTF-8') ? $qr_encoding : 'UTF-8'; $this->qr_errorCorrectionLevel=($qr_errorCorrectionLevel == 'H' || $qr_errorCorrectionLevel == 'L' || $qr_errorCorrectionLevel == 'M' || $qr_errorCorrectionLevel == 'Q') ? $qr_errorCorrectionLevel : 'L'; $this->qr_marginInRows=($qr_marginInRows>0 && $qr_marginInRows<10) ? $qr_marginInRows:4; $this->qr_debug = ($qr_debug==true)? true:false; } public function generateQR(){ $QRLink = "https://chart.googleapis.com/chart?cht=qr&chs=".$this->qr_size."x".$this->qr_size. "&chl=" . $this->qr_data . "&choe=" . $this->qr_encoding . "&chld=" . $this->qr_errorCorrectionLevel . "|" . $this->qr_marginInRows; if ($this->qr_debug) echo $QRLink; return $QRLink; } } $data = (object)[]; $data->action = 'PAY'; $json_data = json_encode($data); $qr_code = new QRGenerator($json_data,1000); echo "<img src=".$qr_code->generateQR().">"; ?>