生成二维码的包
https:
https:
中文文档地址
https:
这里用2
composer require simplesoftwareio/simple-qrcode "~2"
demo1
public function createGrouponShareImages(GrouponRules $rules)
{
$shareUrl = 'http://mcshop.test/'.$rules->goods_id;
$resp= QrCode::format('png')->size(300)->generate($shareUrl);
return Response()->make($resp)->header('Content-Type','image/png');
}
demo2合成图片 合成图片包的的地址
https://github.com/Intervention/image
有点卡 反正composer里面的命令在里面
public function createGrouponShareImages(GrouponRules $rules)
{
$shareUrl = 'http://mcshop.test/'.$rules->goods_id;
$qrCode = QrCode::format('png')->size(300)->generate($shareUrl);
$image = Image::make(resource_path('image/back_groupon.png'))->insert($qrCode,'top-left',448,767);
return $image->encode();
}
public function createGrouponShareImages(GrouponRules $rules)
{
$shareUrl = 'http://mcshop.test/'.$rules->goods_id;
$qrCode = QrCode::format('png')->size(300)->generate($shareUrl);
$goodsImage = Image::make($rules->pic_url)->resize(660, 660);
$image = Image::make(resource_path('image/back_groupon.png'))
->insert($qrCode,'top-left',448,767)
->insert($goodsImage, 'top-left', 71, 69)
->text($rules->goods_name, 65, 867, function (AbstractFont $font) {
$font->color(array(167, 136, 69));
$font->size(28);
$font->file(resource_path('ttf/msyh.ttf'));
});
return $image->encode();
}
//如何保存文件图片
public function createGrouponShareImages(GrouponRules $rules)
{
$shareUrl = 'http://mcshop.test/'.$rules->goods_id;
$qrCode = QrCode::format('png')->size(300)->generate($shareUrl);
$goodsImage = Image::make($rules->pic_url)->resize(660, 660);
$image = Image::make(resource_path('image/back_groupon.png'))
->insert($qrCode,'top-left',448,767)
->insert($goodsImage, 'top-left', 71, 69)
->text($rules->goods_name, 65, 867, function (AbstractFont $font) {
$font->color(array(167, 136, 69));
$font->size(28);
$font->file(resource_path('ttf/msyh.ttf'));
});
$filePath = 'groupon/'.Carbon::now()->toDateString().'/'.Str::random().'.png';
Storage::disk('public')->put($filePath, $image->encode());
return Storage::url($filePath);
}
代表访问成功
但是访问地址是死的 所以我们需要一个方法
class HomeController extends WxController
{
protected $only = [];
public function redirectShareUrl()
{
$type = $this->verifyString('type', 'groupon');
$id = $this->verifyId('id');
if ($type == 'groupon') {
return redirect()->to(env('H5_URL').'/#/items/detail/'.$id);
}
if ($type == 'goods') {
return redirect()->to(env('H5_URL').'/#/items/detail/'.$id);
}
return redirect()->to(env('H5_URL').'/#/items/detail/'.$id);
}
}
Route::get('home/redirectShareUrl', 'HomeController@redirectShareUrl')->name('home.redirectShareUrl');
|