/** * 根据需要生成二维码的数据(URL),生成二维码,并保存到storager * * $params string $data 可以是URL,文字 */ public function store($data, $matrixPointSize = null, $errorCorrectionLevel = null) { $matrixPointSize = $matrixPointSize ? $matrixPointSize : $this->matrixPointSize; $errorCorrectionLevel = $errorCorrectionLevel ? $errorCorrectionLevel : $this->errorCorrectionLevel; $imageModel = app::get('image')->model('image'); $image_id = $this->gen_qrcode_image_id($data, $matrixPointSize, $errorCorrectionLevel); if (!$imageModel->getRow('image_id', array('image_id' => $image_id))) { $filename = tempnam($this->tmp_dir, 'qrcode'); weixin_qrcode_QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2); list($w, $h) = getimagesize($filename); $storager = new base_storager(); list($url, $ident, $storage) = explode("|", $storager->save_upload($filename, 'image', '', $msg, $this->extname)); $params = array('image_id' => $image_id, 'storage' => $storage, 'image_name' => '二维码图片', 'ident' => $ident, 'url' => $url, 'width' => $w, 'height' => $h, 'last_modified' => time()); $imageModel->save($params); unlink($filename); } return $image_id; }