123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use think\Response;
- /**
- * 商品
- */
- class Product extends Api
- {
- protected $noNeedLogin = [''];
- // 无需鉴权的接口,*表示全部
- protected $noNeedRight = ['*'];
- //生成我的视频海报
- //生成邀请码二维码图片
- public function inviteimage($product_id,$introcode) {
- $params['text'] = config('h5_url') . '/#/pages/home/detail?id='.$product_id.'&introcode=' . $introcode;
- $qrcode_service = \addons\qrcode\library\Service::qrcode($params);
- // $mimetype = 'image/png';
- // $response = Response::create()->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 '<html><body><img src="'.$imgurl.'"></body></html>';
- $this->success('', $imgurl);
- }
- }
|