首先,我们需要下载 phpqrcode 库
地址:https://nchc.dl.sourceforge.net/project/phpqrcode/releases/phpqrcode-2010100721_1.1.4.zip
声明一下:使用的是 Yii 框架
传的参数则为需要写入二维码的内容,这里传了 id
public function createCode1($id) {
$qrcode_path='';
$file_tmp_name='';
$errors=array();
$content = $id; //二维码内容
Yii::$enableIncludePath = false;
Yii::import ('application.extensions.phpqrcode.phpqrcode', 1 );
$tpgs='png';//图片格式
//$bas_path=dirname ( Yii::app ()->BasePath );
$qrcode_bas_path='/web/image/qrcode/';
if(!is_dir($qrcode_bas_path)){
mkdir($qrcode_bas_path, 0777, true);
}
$uniqid_rand=date("Ymdhis").uniqid(). rand(1,1000);
$qrcode_path=$qrcod