header("Content-Type", $mimetype); // 直接显示二维码 // header('Content-Type: ' . $qrcode_service->getContentType()); // $response->content($qrcode_service->writeString()); $qrcodePath = ROOT_PATH . 'public/uploads/qrcode/'; if (!is_dir($qrcodePath)) { @mkdir($qrcodePath); } if (is_really_writable($qrcodePath)) { $filename = md5(implode('', $params)) . '.png'; $filePath = $qrcodePath . $filename; $qrcode_service->writeFile($filePath); } return '/uploads/qrcode/' . $filename; } //生成视频分享海报 public function shareposter() { $product_id = input('product_id', 0); if (!$product_id) { $this->error('参数缺失'); } $id = \addons\unishop\extend\Hashids::decodeHex($product_id); $info = Db::name('unishop_product')->where('id',$id)->find(); if (!$info) { $this->error('商品不存在'); } $info = info_domain_image($info,['image']); $inviteimage = $this->inviteimage($product_id,$this->auth->introcode); $data = [ [ "left"=> "0px", "top"=> "0px", "type"=> "img", "width"=> "320px", "height"=> "320px", "src"=> $info['image'],//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg" ], [ "left"=> "10px", "top"=> "330px", "type"=> "img", "width"=> "100px", "height"=> "100px", "src"=> httpurllocal('/assets/img/posterlogo.png')//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg" ], [ "left"=> "5px", "top"=> "440px", "type"=> "nickname", "width"=> "166px", "height"=> "38px", "size"=> "11px", "color"=> "#333333", "content" => (iconv_strlen($info['title'], 'utf-8') <= 12 ? $info['title'] : mb_substr($info['title'], 0, 12) ) ], [ "left"=> "10px", "top"=> "460px", "type"=> "nickname", "width"=> "166px", "height"=> "38px", "size"=> "11px", "color"=> "#ff0000", "content" => '¥'.$info['sales_price'], ], [ "left"=> "10px", "top"=> "480px", "type"=> "nickname", "width"=> "166px", "height"=> "38px", "size"=> "11px", "color"=> "#333333", "content" => (iconv_strlen($this->auth->nickname, 'utf-8') <= 8 ? $this->auth->nickname : mb_substr($this->auth->nickname, 0, 8)) ], [ "left"=> "200px", "top"=> "330px", "type"=> "img", "width"=> "110px", "height"=> "110px", "src"=> httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg" ], [ "left"=> "205px", "top"=> "445px", "type"=> "nickname", "width"=> "166px", "height"=> "38px", "size"=> "9px", "color"=> "#666666", "content" => '长按扫码查看详情', ], ]; $data = json_encode($data, 320); $poster = [ 'id' => 1, 'title' => '测试', 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...', 'bg_image' => '/assets/img/posterproductbg.png', 'data' => $data, 'status' => 'normal', 'weigh' => 0, 'createtime' => 1653993709, 'updatetime' => 1653994259, ]; $image = new \addons\poster\library\Image(); $imgurl = $image->createPosterImage($poster, $this->auth->getUser()); if (!$imgurl) { $this->error('生成海报出错'); } $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl; //echo ''; $this->success('', $imgurl); } }