wesmiler 1 månad sedan
förälder
incheckning
24a7d3e2d2
3 ändrade filer med 52 tillägg och 4 borttagningar
  1. 11 4
      app/Helpers/common.php
  2. 7 0
      app/Services/Api/MemberService.php
  3. 34 0
      app/Services/QiniuService.php

+ 11 - 4
app/Helpers/common.php

@@ -1722,7 +1722,17 @@ if(!function_exists('save_base64_image')){
     {
         $content = str_replace('data:image/png;base64,','', urldecode(trim($base64)));
         $save_path = create_image_path($save_dir, $ext);
-        return file_put_contents(ATTACHMENT_PATH . $save_path, base64_decode($content)) ? $save_path : false;
+        $driver = \App\Services\ConfigService::make()->getConfigByCode('file_upload_driver','local');
+        if($driver == 'qiniu'){
+            if($path = \App\Services\QiniuService::make()->uploadBase64($save_path, base64_decode($content))){
+                return $path;
+            }
+
+            return false;
+        }else{
+            return file_put_contents(ATTACHMENT_PATH . $save_path, base64_decode($content)) ? $save_path : false;
+        }
+
     }
 }
 
@@ -1917,9 +1927,6 @@ if (!function_exists('upload_image')) {
         }
 
 
-
-
-
         // 返回结果
         $result = [
             'img_original_name' => $original_name,

+ 7 - 0
app/Services/Api/MemberService.php

@@ -614,6 +614,7 @@ class MemberService extends BaseService
     }
 
     /**
+     * 获取团队列表
      * @param $userId
      * @param $params
      * @return array
@@ -662,6 +663,12 @@ class MemberService extends BaseService
 
     }
 
+    /**
+     * 设置账户参数
+     * @param $userId
+     * @param $params
+     * @return array|false|mixed|string
+     */
     public function setting($userId, $params)
     {
         $apiUrl = ConfigService::make()->getConfigByCode('bonus_settle_url','');

+ 34 - 0
app/Services/QiniuService.php

@@ -82,4 +82,38 @@ class QiniuService extends BaseService
             return $this->host . '/' . $filename;
         }
     }
+
+    /**
+     * 查询
+     * @param $no 快递单号
+     * @param string $phone // 手机号
+     * @param string $code 快递公司编号
+     * @return bool
+     */
+    public function uploadBase64($filename,$base64)
+    {
+        // 配置参数
+        if(empty($this->accessKey) || empty($this->secretKey) || empty($this->bucket) || empty($this->host)){
+            $this->error = 'QINIU接口参数未配置';
+            return false;
+        }
+
+        // 初始化鉴权对象
+        $auth = new Auth($this->accessKey, $this->secretKey);
+
+        // 生成上传策略
+        $policy = null;
+        $uptoken = $auth->uploadToken($this->bucket, $filename, 3600, $policy);
+
+        // 初始化 UploadManager 对象并进行文件上传
+        $uploadMgr = new UploadManager();
+        list($ret, $err) = $uploadMgr->put($uptoken, $filename, $base64,'');
+
+        if ($err !== null) {
+            $this->error = 'QINIU图片上传失败:' . $err->getMessage();
+            return false;
+        } else {
+            return $this->host . '/' . $filename;
+        }
+    }
 }