Bladeren bron

产品海报

lizhen_gitee 1 jaar geleden
bovenliggende
commit
07356212a6

+ 153 - 0
application/api/controller/Product.php

@@ -0,0 +1,153 @@
+<?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"=> "10px",
+                "type"=> "img",
+                "width"=> "320px",
+                "height"=> "320px",
+                "src"=> $info['image'],//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
+            ],
+            [
+                "left"=> "10px",
+                "top"=> "340px",
+                "type"=> "img",
+                "width"=> "100px",
+                "height"=> "100px",
+                "src"=> localpath_to_netpath('/assets/img/posterlogo.png')//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
+            ],
+            [
+                "left"=> "5px",
+                "top"=> "450px",
+                "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"=> "470px",
+                "type"=> "nickname",
+                "width"=> "166px",
+                "height"=> "38px",
+                "size"=> "11px",
+                "color"=> "#ff0000",
+                "content" => '¥'.$info['sales_price'],
+            ],
+            [
+                "left"=> "10px",
+                "top"=> "490px",
+                "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"=> "340px",
+                "type"=> "img",
+                "width"=> "110px",
+                "height"=> "110px",
+                "src"=> httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
+            ],
+            [
+                "left"=> "205px",
+                "top"=> "455px",
+                "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);
+    }
+
+}

+ 16 - 0
application/common.php

@@ -882,4 +882,20 @@ function request_post_hub($field_array = [],$required = [],$noempty = []){
     }
 
     return $data;
+}
+if (!function_exists('httpurllocal')) {
+    /**
+     * 判断当前url是否为全路径,并返回全路径
+     */
+    function httpurllocal($path) {
+        if(!$path) return $path;
+        $host = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"];
+        // 获取当前域名
+        if(strpos($path,'http://') === false && strpos($path,'https://') === false) {
+            $url = $host.$path;
+        } else {
+            $url = $path;
+        }
+        return $url;
+    }
 }

+ 1 - 0
application/config.php

@@ -310,6 +310,7 @@ return [
 
     //图片地址
     'domain_cdnurl' => 'http://mingxiang.huxiukeji.cn',
+    'domain_cdnurl' => 'http://mingxiang.com',
     //h5页面地址
     'h5_url' => 'http://mingxiangweb.huxiukeji.cn',
 

BIN
public/assets/img/posterlogo.png


BIN
public/assets/img/posterproductbg.png