songxingwei 2 år sedan
förälder
incheckning
6a542a7d0d
1 ändrade filer med 14 tillägg och 1 borttagningar
  1. 14 1
      application/common.php

+ 14 - 1
application/common.php

@@ -2,6 +2,7 @@
 
 use app\common\library\QRcode;
 use think\Db;
+use OSS\OssClient;
 
 function IntToChr($index, $start = 65) {
     $str = '';
@@ -1164,7 +1165,19 @@ function setqrcode($value,$name){
     }
     $filename = $dir.'/'.$name.'.png';
     QRcode::png($value,$filename,QR_ECLEVEL_L,7);
-    return 'http://'.$_SERVER['SERVER_NAME']."/user/".$name.'.png';
+
+    $storage_type = getConfigValue('storage_type');
+    if ($storage_type == 'oss'){
+        $ossClient = new OssClient(getConfigValue('storage_oss_keyid'), getConfigValue('storage_oss_secret'), getConfigValue('storage_oss_endpoint'));
+        $file_path = dirname($_SERVER['SCRIPT_FILENAME']) . "/user/".$name.".png";
+        $newName = date('Ymd').'/'.get_order_sn().'.png';
+        $result = $ossClient->uploadFile(getConfigValue('storage_oss_bucket'), $newName, $file_path);
+        $url = $result['info']['url'];
+        unlink($file_path);
+    }else{
+        $url = 'http://'.$_SERVER['SERVER_NAME']."/user/".$name.'.png';
+    }
+    return $url;
 }
 
 //生成邀请二维码