shish пре 5 година
родитељ
комит
7b7e450d35
2 измењених фајлова са 10 додато и 6 уклоњено
  1. 5 5
      common/components/oss.php
  2. 5 1
      common/services/ImageService.php

+ 5 - 5
common/components/oss.php

@@ -9,6 +9,7 @@ namespace common\components;
 use OSS\Core\OssException;
 use OSS\OssClient;
 use Yii;
+
 class oss
 {
 
@@ -17,16 +18,14 @@ class oss
     {
         $ossClient = self::getOssClient();
         $bucket = Yii::$app->params['ossBucket'];
-        try{
-
-            $res = $ossClient->uploadFile($bucket, $object, $filePath);
-        }catch (OssException $e){
+        try {
+            $ossClient->uploadFile($bucket, $object, $filePath);
+        } catch (OssException $e) {
             util::fail($e->getMessage());
         }
         return true;
     }
 
-
     public static function getOssClient()
     {
         $accessKeyId = Yii::$app->params['accessKeyId'];
@@ -39,4 +38,5 @@ class oss
             util::fail($e->getMessage());
         }
     }
+
 }

+ 5 - 1
common/services/ImageService.php

@@ -3,6 +3,7 @@
 namespace common\services;
 
 use common\components\dirUtil;
+use common\components\oss;
 use common\components\stringUtil;
 use linslin\yii2\curl;
 use yii\imagine\Image;
@@ -17,7 +18,7 @@ class ImageService
         $month = date("Ym");
         $date = date("d");
         $path = dirUtil::getImgDir();
-        $middle = "/wx/avatar/{$merchantId}/{$month}/{$date}/";
+        $middle = "wx/avatar/{$merchantId}/{$month}/{$date}/";
         if (!file_exists($path . $middle)) {
             mkdir($path . $middle, 0777, true);
         }
@@ -33,6 +34,9 @@ class ImageService
         fwrite($fp, $result);
         fclose($fp);
 
+        //上传oss
+        oss::uploadImage($middle,$fullFileName);
+
         $imgInfo = getimagesize($fullFileName);
         if (empty($imgInfo) || isset($imgInfo[0]) == false) {
             return '';