You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
3.2 KiB
82 lines
3.2 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author: CRMEB Team <admin@crmeb.com>
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\kefu\controller;
|
|
|
|
use Api\AliyunOss;
|
|
use app\admin\model\system\SystemAttachment as SystemAttachmentModel;
|
|
use app\admin\model\system\SystemAttachmentCategory as Category;
|
|
use app\kefu\controller\AuthController;
|
|
use service\SystemConfigService;
|
|
use service\JsonService as Json;
|
|
use service\FormBuilder as Form;
|
|
use think\Url;
|
|
|
|
/**
|
|
* TODO 附件控制器
|
|
* Class Images
|
|
* @package app\admin\controller\widget
|
|
*/
|
|
class Upload extends AuthController
|
|
{
|
|
protected static $AccessKeyId = ''; //阿里云AccessKeyId
|
|
|
|
protected static $accessKeySecret = ''; //阿里云AccessKeySecret
|
|
|
|
protected static $end_point = ''; //EndPoint(地域节点)
|
|
|
|
protected static $OssBucket = ''; //存储空间名称
|
|
|
|
protected static $uploadUrl = ''; //空间域名 Domain
|
|
/**
|
|
* 初始化
|
|
*/
|
|
protected function init()
|
|
{
|
|
self::$AccessKeyId = SystemConfigService::get('accessKeyId'); //阿里云AccessKeyId
|
|
self::$accessKeySecret = SystemConfigService::get('accessKeySecret'); //阿里云AccessKeySecret
|
|
self::$end_point = SystemConfigService::get('end_point'); //EndPoint
|
|
self::$OssBucket = SystemConfigService::get('OssBucket'); //存储空间名称
|
|
self::$uploadUrl = SystemConfigService::get('uploadUrl'); //空间域名 Domain
|
|
if (self::$AccessKeyId == '' || self::$accessKeySecret == '') return Json::fail('阿里云AccessKeyId或阿里云AccessKeySecret没有配置');
|
|
if (self::$end_point == '') return Json::fail('EndPoint没有配置');
|
|
if (self::$OssBucket == '') return Json::fail('存储空间名称没有配置');
|
|
if (self::$uploadUrl == '') return Json::fail('空间域名没有配置');
|
|
return AliyunOss::instance([
|
|
'AccessKey' => self::$AccessKeyId,
|
|
'AccessKeySecret' => self::$accessKeySecret,
|
|
'OssEndpoint' => self::$end_point,
|
|
'OssBucket' => self::$OssBucket,
|
|
'uploadUrl' => self::$uploadUrl
|
|
]);
|
|
}
|
|
|
|
|
|
/**
|
|
* 图片管理上传图片
|
|
* @return \think\response\Json
|
|
*/
|
|
public function upload()
|
|
{
|
|
try {
|
|
$aliyunOss = $this->init();
|
|
$res = $aliyunOss->upload('file');
|
|
$res['url'] = str_replace("http", "https", $res['url']);
|
|
if ($res) {
|
|
return Json::successful($res);
|
|
} else {
|
|
return Json::fail($aliyunOss->getErrorInfo()['msg']);
|
|
}
|
|
} catch (\Exception $e) {
|
|
return Json::fail('上传失败:' . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|