227 lines
8.4 KiB
PHP
227 lines
8.4 KiB
PHP
<?php
|
|
namespace app\controllers\admin;
|
|
use crazyfd\qiniu\Qiniu;
|
|
use Illuminate\Support\Facades\DB;
|
|
use OSS\OssClient;
|
|
use xplqcloud\cos\Cos;
|
|
use Yii;
|
|
use yii\web\Controller;
|
|
use yii\web\Session;
|
|
use app\models\common\Config;
|
|
use app\models\common\File;
|
|
class StorageController extends CommonController{
|
|
public $enableCsrfValidation = false;
|
|
//获取第三方储存空间列表
|
|
public function actionGetlist(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isGet){
|
|
$re= YII::$app->db->createCommand('select * from {{%ybwm_storage_space}}')->queryAll();
|
|
return $this->result(1,'成功',$re);
|
|
}
|
|
return $this->result(2,'请求异常');
|
|
}
|
|
|
|
/*远程附件上传-------------------------------------------------------------------------------------------*/
|
|
//远程附件展示页面
|
|
public function actionPlatform_enclosure()
|
|
{
|
|
return $this->renderpartial('platform_enclosure');
|
|
}
|
|
//远程附件保存
|
|
public function actionStorage_save(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost) {
|
|
$request = axios_request();
|
|
// dd($request);die;
|
|
$id = $request['id'];
|
|
$data = array(
|
|
'type' =>$request['storage_type'],
|
|
'qn_accesskey' => $request['qn_accesskey'],
|
|
'qn_secretkey' => $request['qn_secretkey'],
|
|
'qn_bucket' => $request['qn_bucket'],
|
|
'qn_url' => $request['qn_url'],
|
|
'qn_endpoint' => $request['qn_endpoint'],
|
|
'aliyuncs_accesskey' => $request['aliyuncs_accesskey'],
|
|
'aliyuncs_secret' => $request['aliyuncs_secret'],
|
|
'aliyuncs_bucket'=>$request['aliyuncs_bucket'],
|
|
'aliyuncs_url'=>$request['aliyuncs_url'],
|
|
'aliyuncs_endpoint'=>$request['aliyuncs_endpoint'],
|
|
'xplqcloud_appid'=>$request['xplqcloud_appid'],
|
|
'xplqcloud_secretid'=>$request['xplqcloud_secretid'],
|
|
'xplqcloud_secretkey'=>$request['xplqcloud_secretkey'],
|
|
'xplqcloud_bucket'=>$request['xplqcloud_bucket'],
|
|
'xplqcloud_endpoint'=>$request['xplqcloud_endpoint'],
|
|
'xplqcloud_url'=>$request['xplqcloud_url'],
|
|
);
|
|
$res=File::checkAttachmentSet($request['storage_type'],$data);
|
|
if(!$res){
|
|
return $this->result(2,'参数配置有误!!!');
|
|
}
|
|
|
|
$result=Config::saveSystemSet($data,'storage',0,'远程附件');
|
|
|
|
if ($result) {
|
|
return $this->result(1,'成功');
|
|
} else {
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
return $this->result(2,'请求异常');
|
|
}
|
|
//附件上传测试
|
|
public function actionStorage_test(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost) {
|
|
$request=axios_request();
|
|
switch ($request['enclosure']){
|
|
case 1;
|
|
$ak = 'Qa8IL3OUo4Q6pSqaSy2vaoe7omQsGwyIi9CEvQJ7';
|
|
$sk = '5JVZaQ5WYtCtGJ0i59D9XpfRVHUfaCcTlkXmT74p';
|
|
$domain = 'https://images.ddycms.cn';
|
|
$bucket = 'ddmh';
|
|
$zone = 'south_china';
|
|
$qiniu = new Qiniu($ak, $sk,$domain, $bucket,$zone);
|
|
$token=$qiniu->uploadToken(array('scope' => $bucket));
|
|
break;
|
|
case 2:
|
|
$re=2;
|
|
break;
|
|
case 3;
|
|
$re=1;
|
|
break;
|
|
}
|
|
$re=1;
|
|
if($re){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'没有符合的方案');
|
|
}
|
|
}
|
|
return $this->result(2,'请求异常');
|
|
|
|
}
|
|
//获取附件上传信息
|
|
public function actionGetapply(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost){
|
|
$row=(new \yii\db\Query())
|
|
->from('{{%ybwm_core_system}}')
|
|
->where(['uniacid'=>0,'ident'=>'storage'])
|
|
->one();
|
|
$storage_type=json_decode($row['data'],true)['type']?json_decode($row['data'],true)['type']:'0';
|
|
if($row){
|
|
echo json_encode(['code'=>1,'msg'=>'成功','storage_type'=>$storage_type,'data'=>'','result'=>json_decode($row['data'])]);
|
|
}else{
|
|
echo json_encode(['code'=>1,'msg'=>'成功','storage_type'=>$storage_type]);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//七牛云上传
|
|
public function actionQiniuupload(){
|
|
if (Yii::$app->request->isPost) {
|
|
//提交的参数名file
|
|
$ak = 'Qa8IL3OUo4Q6pSqaSy2vaoe7omQsGwyIi9CEvQJ7';
|
|
$sk = '5JVZaQ5WYtCtGJ0i59D9XpfRVHUfaCcTlkXmT74p';
|
|
$domain = 'https://images.ddycms.cn';
|
|
$bucket = 'ddmh';
|
|
$zone = 'south_china';
|
|
|
|
$qiniu = new Qiniu($ak, $sk,$domain, $bucket,$zone);
|
|
//dd($qiniu);die;
|
|
$key = time();
|
|
$key .= strtolower(strrchr($_FILES['file']['name'], '.'));
|
|
|
|
$qiniu->uploadFile($_FILES['file']['tmp_name'],$key);
|
|
$url = $qiniu->getLink($key);
|
|
return $url;
|
|
}
|
|
|
|
}
|
|
//阿里云上传
|
|
public function actionAliupload(){
|
|
if (Yii::$app->request->isPost) {
|
|
$accessKeyId = "LTAI4G4UAYdPvXzZrQsffCUd";
|
|
$accessKeySecret = "NwWPsKOmVsflpXNkgc4LkJuymBVgZv";
|
|
$endpoint = "https://yunbeioss.oss-accelerate.aliyuncs.com";
|
|
try {
|
|
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
|
|
|
|
$bucketListInfo = $ossClient->listBuckets();
|
|
$bucketList = $bucketListInfo->getBucketList();
|
|
dd($bucketList);die;
|
|
|
|
$bucket="yunbeioss";
|
|
//dd($ossClient->createObjectDir($bucket,'test'));die;
|
|
$oss_path = time();
|
|
$oss_path .= strtolower(strrchr($_FILES['file']['name'], '.'));
|
|
//dd($oss_path);dd($_FILES['file']['tmp_name']);die;
|
|
$result=$ossClient->uploadFile($bucket, $oss_path, $_FILES['file']['tmp_name']);
|
|
dd($result);die;
|
|
} catch (OssException $e) {
|
|
print $e->getMessage();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
//腾讯云上传
|
|
public function actionTxyupload(){
|
|
$data=[
|
|
'app_id' =>'1300261712',
|
|
'secret_id' =>'AKIDrrZ7Tbc1IhtysV73SaVaRB181e4E5roV',
|
|
'secret_key' =>'pzrVQ6aoxwJTMI9sKUSIuGzUlnamESQY',
|
|
'region' =>'sh',
|
|
'bucket'=>'ybshop',
|
|
'timeout' =>60
|
|
];
|
|
//var_dump($data);die;
|
|
$url='https://ybshop-1300261712.cos.ap-shanghai.myqcloud.com';
|
|
$cos=new Cos($data);
|
|
//创建文件夹
|
|
$path='test/'.date('Ymd',time());
|
|
$d=$cos->createFolder($path);
|
|
|
|
var_dump($d);die;
|
|
$srcPath=$_FILES['file']['tmp_name'];//文件夹/文件名
|
|
$dstPath = $path.'/'. md5(time() . mt_rand(0,1000)).'.png';
|
|
$result2 = $cos->upload($data['bucket'],$srcPath,$dstPath );
|
|
var_dump($result2);
|
|
|
|
}
|
|
|
|
public function actionGetBucket(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost){
|
|
$result=axios_request();
|
|
if(!$result['aliyuncs_accesskey']){
|
|
return $this->result(2,'Access Key ID参数不正确');
|
|
}
|
|
if(!$result['aliyuncs_secret']){
|
|
return $this->result(2,'Access Key Secret参数不正确');
|
|
}
|
|
$accessKeyId =$result['aliyuncs_accesskey'];
|
|
$accessKeySecret = $result['aliyuncs_secret'];
|
|
$endpoint =$result['endpoint'];
|
|
try {
|
|
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
|
|
$bucketListInfo = $ossClient->listBuckets();
|
|
$bucketList = $bucketListInfo->getBucketList();
|
|
$bucket_arr=[];
|
|
foreach ($bucketList as $key=>$v){
|
|
$bucket_arr[]=array(
|
|
'value'=>$key,
|
|
'label'=>array_values(object_array($v))[1]
|
|
);
|
|
}
|
|
return $this->result(1,'成功',$bucket_arr);
|
|
} catch (OssException $e) {
|
|
return $this->result(2,'参数不正确');
|
|
}
|
|
}
|
|
|
|
}
|
|
} |