Commit dd416904 authored by wangtao's avatar wangtao

业务板块api接口

parent a23d313f
...@@ -75,6 +75,7 @@ class Upload extends BaseController ...@@ -75,6 +75,7 @@ class Upload extends BaseController
'file' => array('ext'=>$this->CF['upload_file_type'],'size'=>$this->CF['upload_file_size']), 'file' => array('ext'=>$this->CF['upload_file_type'],'size'=>$this->CF['upload_file_size']),
'video' => array('ext'=>$this->CF['upload_video_type'],'size'=>$this->CF['upload_video_size']), 'video' => array('ext'=>$this->CF['upload_video_type'],'size'=>$this->CF['upload_video_size']),
'audio' => array('ext'=>$this->CF['upload_audio_type'],'size'=>$this->CF['upload_audio_size']), 'audio' => array('ext'=>$this->CF['upload_audio_type'],'size'=>$this->CF['upload_audio_size']),
'upfile'=>''
), ),
'qiniu'=>array( 'qiniu'=>array(
'bucket'=>$this->CF['qiniu_bucket'], 'bucket'=>$this->CF['qiniu_bucket'],
...@@ -86,7 +87,8 @@ class Upload extends BaseController ...@@ -86,7 +87,8 @@ class Upload extends BaseController
'bucket'=>$this->CF['aliyun_bucket'], 'bucket'=>$this->CF['aliyun_bucket'],
'access_key_id'=>$this->CF['access_key_id'], 'access_key_id'=>$this->CF['access_key_id'],
'access_key_secret'=>$this->CF['access_key_secret'], 'access_key_secret'=>$this->CF['access_key_secret'],
'domain'=>$this->CF['aliyun_domain'] 'domain'=>$this->CF['aliyun_domain'],
'upfile'=>'public/',
), ),
'qcloud'=>array( 'qcloud'=>array(
'bucket'=>$this->CF['qcloud_bucket'], 'bucket'=>$this->CF['qcloud_bucket'],
...@@ -110,6 +112,7 @@ class Upload extends BaseController ...@@ -110,6 +112,7 @@ class Upload extends BaseController
*/ */
public function upfile(string $file = 'file', int $groupid = 0, string $action = '', string $thum = '') public function upfile(string $file = 'file', int $groupid = 0, string $action = '', string $thum = '')
{ {
$action = $action ? $action : input('action'); $action = $action ? $action : input('action');
if(!$action) return $this->returnMsg('参数错误'); if(!$action) return $this->returnMsg('参数错误');
$this->init(); $this->init();
...@@ -118,6 +121,7 @@ class Upload extends BaseController ...@@ -118,6 +121,7 @@ class Upload extends BaseController
$this->config['engine'][$engine]['thum'] = $thum; $this->config['engine'][$engine]['thum'] = $thum;
$domain = $this->config['engine'][$engine]['domain']; $domain = $this->config['engine'][$engine]['domain'];
//实例化存储驱动 //实例化存储驱动
$StorageDriver = new StorageDriver($this->config); $StorageDriver = new StorageDriver($this->config);
try{ try{
//设置上传文件的信息 //设置上传文件的信息
...@@ -125,6 +129,10 @@ class Upload extends BaseController ...@@ -125,6 +129,10 @@ class Upload extends BaseController
}catch(\think\Exception $e){ }catch(\think\Exception $e){
return $this->returnMsg('上传失败!'.$e->getMessage()); return $this->returnMsg('上传失败!'.$e->getMessage());
} }
if($engine == 'aliyun'){
$_FILES['file']['name'] = 'public/'.$_FILES['file']['name'];
}
//上传图片 //上传图片
if(!$StorageDriver->upload()) return $this->returnMsg('上传失败!'.$StorageDriver->getError()); if(!$StorageDriver->upload()) return $this->returnMsg('上传失败!'.$StorageDriver->getError());
//图片上传路径 //图片上传路径
......
<?php
namespace app\api\controller;
use think\Request;
use app\api\validate\ArticleValidate;
use app\BaseController;
use app\model\ArticleModel;
class Wecaht extends BaseController
{
public function index()
{
$get = input();
exit($get['echostr']);
// // 配置 Token(需与微信公众号后台设置一致)
// define("WX_TOKEN", "YOUR_TOKEN_HERE");
// // 处理微信服务器发送的 GET 验证请求
// if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['echostr'])) {
// $signature = $_GET['signature'] ?? '';
// $timestamp = $_GET['timestamp'] ?? '';
// $nonce = $_GET['nonce'] ?? '';
// $echostr = $_GET['echostr'] ?? '';
//
// // 参数缺失检测
// if (empty($signature) || empty($timestamp) || empty($nonce) || empty($echostr)) {
// exit('Invalid Request: Missing Parameters');
// }
//
// // 1. 生成本地签名
// $tmpArr = [WX_TOKEN, $timestamp, $nonce];
// sort($tmpArr, SORT_STRING); // 字典序排序
// $tmpStr = implode('', $tmpArr); // 拼接字符串
// $localSign = sha1($tmpStr); // SHA1 加密
//
// // 2. 验证签名并返回 echostr
// if ($localSign == $signature) {
// header('Content-Type: text/plain; charset=utf-8');
// exit($echostr);
// } else {
// exit('Signature Verification Failed');
// }
// return true;
// }
}
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = 'VtUEf2MvC0dMMaDGwMT8';
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode($tmpArr);
$tmpStr = sha1($tmpStr);
if ($tmpStr == $signature) {
return true;
} else {
return false;
}
}
}
\ No newline at end of file
...@@ -18,7 +18,7 @@ class Advert extends Model ...@@ -18,7 +18,7 @@ class Advert extends Model
{ {
return $this->hasOne(SystemUploadFile::class, 'fileid', 'cover_img_id') return $this->hasOne(SystemUploadFile::class, 'fileid', 'cover_img_id')
->where('isdel',0) ->where('isdel',0)
->field('fileid, filename, filesize, fileurl, filetype'); ->field('fileid, filename, filesize, fileurl, filetype,storage');
} }
public function getAdvcatenameAttr($value, $data){ public function getAdvcatenameAttr($value, $data){
......
...@@ -40,7 +40,10 @@ class SystemUploadFile extends Base ...@@ -40,7 +40,10 @@ class SystemUploadFile extends Base
public function getFileurlAttr($value, $data) public function getFileurlAttr($value, $data)
{ {
return config('app.file_http_url').$value; if (isset($data['storage']) && $data['storage'] == 'local') {
return config('app.file_http_url') . $value;
}
return $value;
} }
} }
\ No newline at end of file
...@@ -104,6 +104,7 @@ class Driver ...@@ -104,6 +104,7 @@ class Driver
if (!class_exists($classSpace)) { if (!class_exists($classSpace)) {
throw new Exception('未找到存储引擎类: ' . $engineName); throw new Exception('未找到存储引擎类: ' . $engineName);
} }
return new $classSpace($this->config['engine'][$engineName]); return new $classSpace($this->config['engine'][$engineName]);
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* Licensed: 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 * Licensed: 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
* --------------------------------------------------------------------------- * ---------------------------------------------------------------------------
*/ */
namespace veitool\storage\engine; namespace veitool\storage\engine;
use OSS\OssClient; use OSS\OssClient;
...@@ -19,7 +20,7 @@ use OSS\Core\OssException; ...@@ -19,7 +20,7 @@ use OSS\Core\OssException;
*/ */
class Aliyun extends Server class Aliyun extends Server
{ {
private $config; // private $config;
/** /**
* 构造方法 * 构造方法
...@@ -28,8 +29,8 @@ class Aliyun extends Server ...@@ -28,8 +29,8 @@ class Aliyun extends Server
*/ */
public function __construct($config) public function __construct($config)
{ {
parent::__construct(); parent::__construct($config);
$this->config = $config; // $this->config = $config;
} }
/** /**
...@@ -45,6 +46,7 @@ class Aliyun extends Server ...@@ -45,6 +46,7 @@ class Aliyun extends Server
$this->config['domain'], $this->config['domain'],
true true
); );
$result = $ossClient->uploadFile( $result = $ossClient->uploadFile(
$this->config['bucket'], $this->config['bucket'],
$this->fileName, $this->fileName,
......
...@@ -17,7 +17,7 @@ use think\facade\Filesystem; ...@@ -17,7 +17,7 @@ use think\facade\Filesystem;
*/ */
class Local extends Server class Local extends Server
{ {
private $config; // private $config;
/** /**
* 构造方法 * 构造方法
...@@ -25,8 +25,8 @@ class Local extends Server ...@@ -25,8 +25,8 @@ class Local extends Server
*/ */
public function __construct($config) public function __construct($config)
{ {
parent::__construct(); parent::__construct($config);
$this->config = $config; // $this->config = $config;
} }
/** /**
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* Licensed: 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 * Licensed: 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
* --------------------------------------------------------------------------- * ---------------------------------------------------------------------------
*/ */
namespace veitool\storage\engine; namespace veitool\storage\engine;
use think\Exception; use think\Exception;
...@@ -23,12 +24,16 @@ abstract class Server ...@@ -23,12 +24,16 @@ abstract class Server
protected $error; protected $error;
protected $fileName; protected $fileName;
protected $fileInfo; protected $fileInfo;
protected $config;
/** /**
* 构造函数 * 构造函数
* Server constructor. * Server constructor.
*/ */
protected function __construct(){} protected function __construct($config)
{
$this->config = $config;
}
/** /**
* 设置上传的文件信息 * 设置上传的文件信息
...@@ -45,7 +50,7 @@ abstract class Server ...@@ -45,7 +50,7 @@ abstract class Server
// 生成保存文件名 // 生成保存文件名
$this->fileName = $this->buildSaveName(); $this->fileName = $this->buildSaveName();
// 文件信息 // 文件信息
$this->fileInfo = ['name'=>$this->file->getFilename(),'oname'=> $this->file->getOriginalName(),'size'=>$this->file->getSize(),'type' => $this->file->getMime(),'ext' => $this->file->getOriginalExtension()]; $this->fileInfo = ['name' => $this->file->getFilename(), 'oname' => $this->file->getOriginalName(), 'size' => $this->file->getSize(), 'type' => $this->file->getMime(), 'ext' => $this->file->getOriginalExtension()];
} }
/** /**
...@@ -95,7 +100,7 @@ abstract class Server ...@@ -95,7 +100,7 @@ abstract class Server
// 扩展名 // 扩展名
$ext = $this->file->getOriginalExtension(); $ext = $this->file->getOriginalExtension();
// 自动生成文件名 // 自动生成文件名
return date('YmdHis') . substr(md5($realPath), 0, 5) . str_pad(rand(0, 9999), 4, '0', STR_PAD_LEFT) . '.' . $ext; return $this->config['upfile'] . date('YmdHis') . substr(md5($realPath), 0, 5) . str_pad(rand(0, 9999), 4, '0', STR_PAD_LEFT) . '.' . $ext;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment