跳至正文

PHP TP5框架生成二维码链接

  • PHP
vendor('phpqrcode');//引入类库
$value = 'https://zhishilib.com/'; //二维码内容链接
$errorCorrectionLevel = 'L'; //容错级别
$matrixPointSize = 5; //生成图片大小
// 判断是否有这个文件夹 没有的话就创建一个
if(!is_dir("qrcode")){
// 创建文件加
mkdir("qrcode");
}
//设置二维码文件名
$filename = 'qrcode/'.time().rand(10000,9999999).'.png';
//生成二维码
\QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, 2);
//获取当前域名
$request = Request::instance();
$domain = $request->domain();
$img = $domain.'/'.$filename;
$data = [
'qr_code' => $img,  //二维码路径
'mobile' => $mobile //手机号
];
$ins = $model->er_ins($data,$mobile);//入库
return json_encode(['data'=>$ins,'code'=>200]);//返回json

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注