lizhen_gitee vor 3 Monaten
Ursprung
Commit
d042c8285a
2 geänderte Dateien mit 33 neuen und 12 gelöschten Zeilen
  1. 15 12
      application/api/controller/Userposter.php
  2. 18 0
      application/common.php

+ 15 - 12
application/api/controller/Userposter.php

@@ -35,13 +35,18 @@ class Userposter extends Api
             'padding' => 0,
         ];
         $qrCode = \addons\qrcode\library\Service::qrcode($params);
-        $qrcode_path = 'uploads/hbplayer/'.date('Ymd');
-        mk_dir($qrcode_path);
-        $download_qrcode = $qrcode_path.'/download'.$player_id.'.png';
-        $qrCode->writeFile($download_qrcode);
-
+        $qrcode_path = ROOT_PATH . 'public/uploads/hbplayer/'.date('Ymd');
+        if (!is_dir($qrcode_path)) {
+            @mkdir($qrcode_path);
+        }
+        if (is_really_writable($qrcode_path)) {
+            $filename = 'download'.$player_id.'.png';
+            $download_qrcode = $qrcode_path.'/'.$filename;
+            $qrCode->writeFile($download_qrcode);
+        }
         //海报
-        $haibao = $this->createhaibao($download_qrcode,$player_id,$data);
+        $filepath = '/uploads/hbplayer/'.date('Ymd') .'/'. $filename;
+        $haibao = $this->createhaibao($filepath,$player_id,$data);
 
         return $haibao;
     }
@@ -68,7 +73,6 @@ class Userposter extends Api
 
     public function createhaibao($download_qrcode,$player_id,$sub_data){
         //二维码
-        $download_qrcode= config('img_url').'/'.$download_qrcode;
 
         $data = [
             [
@@ -105,18 +109,17 @@ class Userposter extends Api
                 "type" => "img",
                 "width" => "80px",
                 "height" => "80px",
-//                "src" => httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
-                "src" => $download_qrcode//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
+                "src" => httpurllocal($download_qrcode)
             ]
         ];
 
         $data = json_encode($data, 320);
 
         $poster = [
-            'id' => 1,
-            'title' => '测试2',
+            'id' => $this->auth->id,
+            'title' => '星链',
             'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
-            'bg_image' => $sub_data['background'] ? cdnurl($sub_data['background']) : '/assets/img/inviteposter.png',
+            'bg_image' => $sub_data['background'] ? localpath_to_netpath($sub_data['background']) : '/assets/img/inviteposter.png',
             'data' => $data,
             'status' => 'normal',
             'weigh' => 0,

+ 18 - 0
application/common.php

@@ -547,6 +547,24 @@ function localpath_to_netpath($path)
     }
 }
 
+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;
+    }
+}
+
+
 //秒 转换 日月分
 function Sec2Time($time){
     if(is_numeric($time)){