147 changed files with 0 additions and 20331 deletions
@ -1,29 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
declare (strict_types=1); |
|
||||
|
|
||||
namespace core\base; |
|
||||
|
|
||||
/** |
|
||||
* 管理端控制器基类 |
|
||||
* Class BaseAdminController |
|
||||
* @package core\base |
|
||||
*/ |
|
||||
class BaseAdminController extends BaseController |
|
||||
{ |
|
||||
|
|
||||
public function initialize() |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,31 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\base; |
|
||||
|
|
||||
/** |
|
||||
* 后台基础服务层 |
|
||||
* Class BaseAdminService |
|
||||
* @package app\service\admin |
|
||||
*/ |
|
||||
class BaseAdminService extends BaseService |
|
||||
{ |
|
||||
|
|
||||
protected $username; |
|
||||
protected $uid; |
|
||||
|
|
||||
public function __construct() |
|
||||
{ |
|
||||
parent::__construct(); |
|
||||
$this->username = $this->request->username(); |
|
||||
$this->uid = $this->request->uid(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,29 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
declare (strict_types=1); |
|
||||
|
|
||||
namespace core\base; |
|
||||
|
|
||||
/** |
|
||||
* api基础控制器 |
|
||||
* Class BaseApiController |
|
||||
* @package app\api\controller |
|
||||
*/ |
|
||||
class BaseApiController extends BaseController |
|
||||
{ |
|
||||
|
|
||||
public function initialize() |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,31 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\base; |
|
||||
|
|
||||
/** |
|
||||
* 手机前端基础服务层 |
|
||||
* Class BaseApiService |
|
||||
* @package app\service\api |
|
||||
*/ |
|
||||
class BaseApiService extends BaseService |
|
||||
{ |
|
||||
|
|
||||
protected $member_id; |
|
||||
protected $channel; |
|
||||
|
|
||||
public function __construct() |
|
||||
{ |
|
||||
parent::__construct(); |
|
||||
$this->member_id = $this->request->memberId(); |
|
||||
$this->channel = $this->request->getChannel(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,96 +0,0 @@ |
|||||
<?php |
|
||||
declare (strict_types=1); |
|
||||
|
|
||||
namespace core\base; |
|
||||
|
|
||||
use app\Request; |
|
||||
use think\App; |
|
||||
use think\exception\ValidateException; |
|
||||
use think\Validate; |
|
||||
|
|
||||
/** |
|
||||
* 控制器基础类 |
|
||||
*/ |
|
||||
abstract class BaseController |
|
||||
{ |
|
||||
/** |
|
||||
* Request实例 |
|
||||
* @var Request |
|
||||
*/ |
|
||||
protected $request; |
|
||||
|
|
||||
/** |
|
||||
* 应用实例 |
|
||||
* @var App |
|
||||
*/ |
|
||||
protected $app; |
|
||||
|
|
||||
/** |
|
||||
* 是否批量验证 |
|
||||
* @var bool |
|
||||
*/ |
|
||||
protected $batchValidate = false; |
|
||||
|
|
||||
/** |
|
||||
* 控制器中间件 |
|
||||
* @var array |
|
||||
*/ |
|
||||
protected $middleware = []; |
|
||||
|
|
||||
/** |
|
||||
* 构造方法 |
|
||||
* @access public |
|
||||
* @param App $app 应用对象 |
|
||||
*/ |
|
||||
public function __construct(App $app) |
|
||||
{ |
|
||||
$this->app = $app; |
|
||||
$this->request = $this->app->request; |
|
||||
// 控制器初始化 |
|
||||
$this->initialize(); |
|
||||
} |
|
||||
|
|
||||
// 初始化 |
|
||||
protected function initialize() |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 验证数据 |
|
||||
* @access protected |
|
||||
* @param array $data 数据 |
|
||||
* @param string|array $validate 验证器名或者验证规则数组 |
|
||||
* @param array $message 提示信息 |
|
||||
* @param bool $batch 是否批量验证 |
|
||||
* @return array|string|true |
|
||||
* @throws ValidateException |
|
||||
*/ |
|
||||
protected function validate(array $data, $validate, array $message = [], bool $batch = false) |
|
||||
{ |
|
||||
if (is_array($validate)) { |
|
||||
$v = new Validate(); |
|
||||
$v->rule($validate); |
|
||||
} else { |
|
||||
if (strpos($validate, '.')) { |
|
||||
// 支持场景 |
|
||||
[$validate, $scene] = explode('.', $validate); |
|
||||
} |
|
||||
$class = str_contains($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate); |
|
||||
$v = new $class(); |
|
||||
if (!empty($scene)) { |
|
||||
$v->scene($scene); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
$v->message($message); |
|
||||
|
|
||||
// 是否批量验证 |
|
||||
if ($batch || $this->batchValidate) { |
|
||||
$v->batch(); |
|
||||
} |
|
||||
|
|
||||
return $v->failException()->check($data); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -1,27 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\base; |
|
||||
|
|
||||
/** |
|
||||
* 系统基础服务层 |
|
||||
* Class BaseCoreService |
|
||||
* @package app\service\core |
|
||||
*/ |
|
||||
class BaseCoreService extends BaseService |
|
||||
{ |
|
||||
|
|
||||
|
|
||||
public function __construct() |
|
||||
{ |
|
||||
parent::__construct(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,61 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\base; |
|
||||
|
|
||||
|
|
||||
use core\exception\CommonException; |
|
||||
use core\job\Dispatch; |
|
||||
use think\facade\Log; |
|
||||
use think\queue\Job; |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 队列 |
|
||||
*/ |
|
||||
abstract class BaseJob extends Dispatch |
|
||||
{ |
|
||||
|
|
||||
/** |
|
||||
* 消费任务 |
|
||||
* @param $params |
|
||||
*/ |
|
||||
public function fire($params): void |
|
||||
{ |
|
||||
$method = $params['method'] ?? 'doJob';//任务名 |
|
||||
$data = $params['data'] ?? [];//数据 |
|
||||
$this->runJob($method, $data); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 执行任务 |
|
||||
* @param string $method |
|
||||
* @param array $data |
|
||||
* @param int $error_count |
|
||||
*/ |
|
||||
protected function runJob(string $method, array $data) |
|
||||
{ |
|
||||
try { |
|
||||
$method = method_exists($this, $method) ? $method : 'handle'; |
|
||||
if (!method_exists($this, $method)) { |
|
||||
throw new CommonException('Job "'.static::class.'" not found!'); |
|
||||
} |
|
||||
$this->{$method}(...$data); |
|
||||
return true; |
|
||||
} catch (\Throwable $e) { |
|
||||
Log::write('队列错误:'.static::class.$method.'_'.'_'.$e->getMessage().'_'.$e->getFile().'_'.$e->getLine()); |
|
||||
throw new CommonException('Job "'.static::class.'" has error!'); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,48 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\base; |
|
||||
|
|
||||
|
|
||||
use think\facade\Db; |
|
||||
use think\Model; |
|
||||
|
|
||||
/** |
|
||||
* 基础模型 |
|
||||
* Class BaseModel |
|
||||
* @package app\model |
|
||||
*/ |
|
||||
class BaseModel extends Model |
|
||||
{ |
|
||||
public function getModelColumn() |
|
||||
{ |
|
||||
$table_name = $this->getTable(); |
|
||||
$sql = 'SHOW TABLE STATUS WHERE 1=1 '; |
|
||||
$tablePrefix = config('database.connections.mysql.prefix'); |
|
||||
if (!empty($table_name)) { |
|
||||
$sql .= "AND name='" .$table_name."'"; |
|
||||
} |
|
||||
$tables = Db::query($sql); |
|
||||
$table_info = $tables[0] ?? []; |
|
||||
$table_name = preg_replace("/^{$tablePrefix}/", '', $table_info['Name'], 1); |
|
||||
return Db::name($table_name)->getFields(); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 处理搜索条件特殊字符(%、_) |
|
||||
* @param $value |
|
||||
*/ |
|
||||
public function handelSpecialCharacter($value) |
|
||||
{ |
|
||||
$value = str_replace('%', '\%', str_replace('_', '\_', $value)); |
|
||||
return $value; |
|
||||
} |
|
||||
} |
|
||||
@ -1,135 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\base; |
|
||||
|
|
||||
|
|
||||
use app\validate\sys\Page; |
|
||||
use think\db\exception\DbException; |
|
||||
use think\Model; |
|
||||
|
|
||||
/** |
|
||||
* 基础服务层 |
|
||||
* Class BaseService |
|
||||
* @package app\service |
|
||||
*/ |
|
||||
abstract class BaseService |
|
||||
{ |
|
||||
/** |
|
||||
* Model 实例 |
|
||||
* @var BaseModel |
|
||||
*/ |
|
||||
protected $model; |
|
||||
protected $request; |
|
||||
|
|
||||
public function __construct() |
|
||||
{ |
|
||||
$this->request = request(); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 分页列表参数(页码和每页多少条) |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function getPageParam() |
|
||||
{ |
|
||||
|
|
||||
$page = request()->params([ |
|
||||
['page', 1], |
|
||||
['limit', 15] |
|
||||
]); |
|
||||
validate(Page::class) |
|
||||
->check($page); |
|
||||
return $page; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 分页列表 |
|
||||
* @param Model $model |
|
||||
* @param array $where |
|
||||
* @param string $field |
|
||||
* @param string $order |
|
||||
* @param array $append |
|
||||
* @return array |
|
||||
* @throws DbException |
|
||||
*/ |
|
||||
public function getPageList(Model $model, array $where, string $field = '*', string $order = '', array $append = [], $with = null, $each = null) |
|
||||
{ |
|
||||
$page_params = $this->getPageParam(); |
|
||||
$page = $page_params['page']; |
|
||||
$limit = $page_params['limit']; |
|
||||
|
|
||||
$list = $model->where($where)->when($append, function ($query) use ($append) { |
|
||||
$query->append($append); |
|
||||
})->when($with, function ($query) use ($with) { |
|
||||
$query->with($with); |
|
||||
})->field($field)->order($order)->paginate([ |
|
||||
'list_rows' => $limit, |
|
||||
'page' => $page, |
|
||||
]); |
|
||||
if (!empty($each)) { |
|
||||
$list = $list->each($each); |
|
||||
} |
|
||||
return $list->toArray(); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 分页数据查询,传入model(查询后结果) |
|
||||
* @param $model BaseModel |
|
||||
* @return array |
|
||||
* @throws DbException |
|
||||
*/ |
|
||||
public function pageQuery($model, $each = null) |
|
||||
{ |
|
||||
$page_params = $this->getPageParam(); |
|
||||
$page = $page_params['page']; |
|
||||
$limit = $page_params['limit']; |
|
||||
$list = $model->paginate([ |
|
||||
'list_rows' => $limit, |
|
||||
'page' => $page, |
|
||||
]); |
|
||||
if (!empty($each)) { |
|
||||
$list = $list->each($each); |
|
||||
} |
|
||||
return $list->toArray(); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 分页视图列表查询 |
|
||||
* @param Model $model |
|
||||
* @param array $where |
|
||||
* @param string $field |
|
||||
* @param string $order |
|
||||
* @param array $append |
|
||||
* @return array |
|
||||
* @throws DbException |
|
||||
*/ |
|
||||
public function getPageViewList(Model $model, array $where, string $field = '*', string $order = '', array $append = [], $with = null, $each = null) |
|
||||
{ |
|
||||
$page_params = $this->getPageParam(); |
|
||||
$page = $page_params['page']; |
|
||||
$limit = $page_params['limit']; |
|
||||
|
|
||||
$list = $model->where($where)->when($append, function ($query) use ($append) { |
|
||||
$query->append($append); |
|
||||
})->when($with, function ($query) use ($with) { |
|
||||
$query->withJoin($with); |
|
||||
})->field($field)->order($order)->paginate([ |
|
||||
'list_rows' => $limit, |
|
||||
'page' => $page, |
|
||||
]); |
|
||||
if (!empty($each)) { |
|
||||
$list = $list->each($each); |
|
||||
} |
|
||||
return $list->toArray(); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,46 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
declare (strict_types=1); |
|
||||
|
|
||||
namespace core\base; |
|
||||
|
|
||||
use think\Validate; |
|
||||
|
|
||||
/** |
|
||||
* 验证器器基类 |
|
||||
* Class BaseValidate |
|
||||
* @package core\base |
|
||||
*/ |
|
||||
class BaseValidate extends Validate |
|
||||
{ |
|
||||
|
|
||||
public function __construct() |
|
||||
{ |
|
||||
parent::__construct(); |
|
||||
$this->parseMsg(); |
|
||||
} |
|
||||
|
|
||||
public function parseMsg(){ |
|
||||
if(!empty($this->message)) |
|
||||
{ |
|
||||
foreach ($this->message as $key => $value) |
|
||||
{ |
|
||||
if(is_array($value)) |
|
||||
{ |
|
||||
$this->message[$key] = get_lang($value[0], $value[1]); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,38 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
class AdvPosition extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 广告位加载 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
$adv_position_files = []; |
|
||||
foreach ($addons as $v) { |
|
||||
$adv_position_path = $this->getAddonDictPath($v) . "web" . DIRECTORY_SEPARATOR . "adv_position.php"; |
|
||||
if (is_file($adv_position_path)) { |
|
||||
$adv_position_files[] = $adv_position_path; |
|
||||
} |
|
||||
} |
|
||||
$adv_position_file_data = $this->loadFiles($adv_position_files); |
|
||||
$adv_position = $data; |
|
||||
foreach ($adv_position_file_data as $file_data) { |
|
||||
$adv_position = empty($adv_position) ? $file_data : array_merge($adv_position, $file_data); |
|
||||
} |
|
||||
return $adv_position; |
|
||||
} |
|
||||
} |
|
||||
@ -1,162 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\dict; |
|
||||
|
|
||||
use app\service\core\addon\CoreAddonBaseService; |
|
||||
use core\loader\Storage; |
|
||||
use think\facade\Cache; |
|
||||
use think\facade\Db; |
|
||||
|
|
||||
/** |
|
||||
* Class BaseAddon |
|
||||
* @package |
|
||||
*/ |
|
||||
abstract class BaseDict extends Storage |
|
||||
{ |
|
||||
//插件整体缓存标识 |
|
||||
public static $cache_tag_name = 'addon_cash'; |
|
||||
|
|
||||
/** |
|
||||
* 初始化 |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取本地插件目录(已安装) |
|
||||
*/ |
|
||||
protected function getLocalAddons() |
|
||||
{ |
|
||||
if (!file_exists(root_path() . "install.lock")) { |
|
||||
//尚未安装不加载插件 |
|
||||
return []; |
|
||||
} |
|
||||
|
|
||||
$addons = Cache::get("local_install_addons"); |
|
||||
if (!is_null($addons)) return $addons; |
|
||||
|
|
||||
$addons = Db::name("addon")->column("key"); |
|
||||
Cache::tag(CoreAddonBaseService::$cache_tag_name)->set("local_install_addons", $addons); |
|
||||
|
|
||||
return $addons; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取所有本地插件(包括未安装,用于系统指令执行) |
|
||||
* @return array|false |
|
||||
*/ |
|
||||
public function getAllLocalAddons() |
|
||||
{ |
|
||||
$addon_dir = root_path() . 'addon'; |
|
||||
$addons = array_diff(scandir($addon_dir), ['.', '..']); |
|
||||
return $addons; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取插件目录 |
|
||||
* @param string $addon |
|
||||
* @return string |
|
||||
*/ |
|
||||
protected function getAddonPath(string $addon) |
|
||||
{ |
|
||||
return root_path() . 'addon' . DIRECTORY_SEPARATOR . $addon . DIRECTORY_SEPARATOR; |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取系统整体app目录 |
|
||||
* @return string |
|
||||
*/ |
|
||||
protected function getAppPath() |
|
||||
{ |
|
||||
return root_path() . "app" . DIRECTORY_SEPARATOR; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取插件对应app目录 |
|
||||
* @param string $addon |
|
||||
* @return string |
|
||||
*/ |
|
||||
protected function getAddonAppPath(string $addon) |
|
||||
{ |
|
||||
return $this->getAddonPath($addon) . "app" . DIRECTORY_SEPARATOR; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
*获取系统dict path |
|
||||
*/ |
|
||||
protected function getDictPath() |
|
||||
{ |
|
||||
return root_path() . 'app' . DIRECTORY_SEPARATOR . 'dict' . DIRECTORY_SEPARATOR; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
*获取插件对应的dict目录 |
|
||||
* @param string $addon |
|
||||
* @return string |
|
||||
*/ |
|
||||
protected function getAddonDictPath(string $addon) |
|
||||
{ |
|
||||
return $this->getAddonPath($addon) . 'app' . DIRECTORY_SEPARATOR . 'dict' . DIRECTORY_SEPARATOR; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
*获取插件对应的config目录 |
|
||||
* @param string $addon |
|
||||
* @return string |
|
||||
*/ |
|
||||
protected function getAddonConfigPath(string $addon) |
|
||||
{ |
|
||||
return $this->getAddonPath($addon) . 'config' . DIRECTORY_SEPARATOR; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 加载文件数据 |
|
||||
* @param $files |
|
||||
* @return array |
|
||||
*/ |
|
||||
protected function loadFiles($files) |
|
||||
{ |
|
||||
$default_sort = 100000; |
|
||||
$files_data = []; |
|
||||
if (!empty($files)) { |
|
||||
foreach ($files as $file) { |
|
||||
$config = include $file; |
|
||||
if (!empty($config)) { |
|
||||
if (isset($config['file_sort'])) { |
|
||||
$sort = $config['file_sort']; |
|
||||
unset($config['file_sort']); |
|
||||
$sort = $sort * 10; |
|
||||
while (array_key_exists($sort, $files_data)) { |
|
||||
$sort++; |
|
||||
} |
|
||||
$files_data[$sort] = $config; |
|
||||
} else { |
|
||||
$files_data[$default_sort] = $config; |
|
||||
$default_sort++; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
ksort($files_data); |
|
||||
return $files_data; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 加载 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract public function load(array $data); |
|
||||
} |
|
||||
@ -1,41 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
class Config extends BaseDict |
|
||||
{ |
|
||||
public function load(array $data) |
|
||||
{ |
|
||||
$config = $data['name']; |
|
||||
$system_config = $data['data'] ?? []; |
|
||||
|
|
||||
$addons = $this->getAllLocalAddons(); |
|
||||
$config_files = []; |
|
||||
|
|
||||
foreach ($addons as $v) { |
|
||||
$config_path = $this->getAddonAppPath($v) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $config . '.php'; |
|
||||
if (is_file($config_path)) { |
|
||||
$config_files[] = $config_path; |
|
||||
} |
|
||||
} |
|
||||
$files_data = $this->loadFiles($config_files); |
|
||||
|
|
||||
foreach ($files_data as $file_data) { |
|
||||
if(!empty($file_data)) |
|
||||
{ |
|
||||
$system_config = empty($system_config) ? $file_data : array_merge2($system_config, $file_data); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
return $system_config; |
|
||||
} |
|
||||
} |
|
||||
@ -1,45 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
class Console extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 加载事件 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data) |
|
||||
{ |
|
||||
$addons = $this->getAllLocalAddons(); |
|
||||
$console_files = []; |
|
||||
|
|
||||
foreach ($addons as $v) { |
|
||||
$console_path = $this->getAddonAppPath($v) . "/config/console.php"; |
|
||||
if (is_file($console_path)) { |
|
||||
$console_files[] = $console_path; |
|
||||
} |
|
||||
} |
|
||||
$files_data = $this->loadFiles($console_files); |
|
||||
|
|
||||
|
|
||||
$console = $data; |
|
||||
foreach ($files_data as $file_data) { |
|
||||
if(!empty($file_data)) |
|
||||
{ |
|
||||
$console = empty($console) ? $file_data : array_merge2($console, $file_data); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
return $console; |
|
||||
} |
|
||||
} |
|
||||
@ -1,41 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\dict; |
|
||||
|
|
||||
use core\loader\Loader; |
|
||||
|
|
||||
/** |
|
||||
* @see DictLoader |
|
||||
* @mixin BaseDict |
|
||||
* @method array|null load(array $data = []) |
|
||||
*/ |
|
||||
class DictLoader extends Loader |
|
||||
{ |
|
||||
|
|
||||
/** |
|
||||
* 空间名 |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $namespace = '\\core\\dict\\'; |
|
||||
|
|
||||
protected $config_name = 'dict'; |
|
||||
|
|
||||
/** |
|
||||
* 默认驱动 |
|
||||
* @return string |
|
||||
*/ |
|
||||
protected function getDefault() |
|
||||
{ |
|
||||
return "Event"; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,38 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
class DiyFormComponent extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 万能表单组件配置 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
$components_files = []; |
|
||||
|
|
||||
foreach ($addons as $v) { |
|
||||
$components_path = $this->getAddonDictPath($v) . "diy_form" . DIRECTORY_SEPARATOR . "components.php"; |
|
||||
if (is_file($components_path)) { |
|
||||
$components_files[] = $components_path; |
|
||||
} |
|
||||
} |
|
||||
$components_files_data = $this->loadFiles($components_files); |
|
||||
$components = $data; |
|
||||
foreach ($components_files_data as $file_data) { |
|
||||
$components = empty($components) ? $file_data : array_merge2($components, $file_data); |
|
||||
} |
|
||||
return $components; |
|
||||
} |
|
||||
} |
|
||||
@ -1,38 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
class DiyFormTemplate extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 万能表单模版 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
$components_files = []; |
|
||||
|
|
||||
foreach ($addons as $v) { |
|
||||
$components_path = $this->getAddonDictPath($v) . "diy_form" . DIRECTORY_SEPARATOR . "template.php"; |
|
||||
if (is_file($components_path)) { |
|
||||
$components_files[] = $components_path; |
|
||||
} |
|
||||
} |
|
||||
$components_files_data = $this->loadFiles($components_files); |
|
||||
$components = $data; |
|
||||
foreach ($components_files_data as $file_data) { |
|
||||
$components = empty($components) ? $file_data : array_merge2($components, $file_data); |
|
||||
} |
|
||||
return $components; |
|
||||
} |
|
||||
} |
|
||||
@ -1,38 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
class DiyFormType extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 万能表单组件配置 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
$components_files = []; |
|
||||
|
|
||||
foreach ($addons as $v) { |
|
||||
$components_path = $this->getAddonDictPath($v) . "diy_form" . DIRECTORY_SEPARATOR . "type.php"; |
|
||||
if (is_file($components_path)) { |
|
||||
$components_files[] = $components_path; |
|
||||
} |
|
||||
} |
|
||||
$components_files_data = $this->loadFiles($components_files); |
|
||||
$components = $data; |
|
||||
foreach ($components_files_data as $file_data) { |
|
||||
$components = empty($components) ? $file_data : array_merge2($components, $file_data); |
|
||||
} |
|
||||
return $components; |
|
||||
} |
|
||||
} |
|
||||
@ -1,42 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
class Event extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 加载事件 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
$event_files = []; |
|
||||
|
|
||||
foreach ($addons as $v) { |
|
||||
$event_path = $this->getAddonAppPath($v) . "event.php"; |
|
||||
if (is_file($event_path)) { |
|
||||
$event_files[] = $event_path; |
|
||||
} |
|
||||
} |
|
||||
$files_data = $this->loadFiles($event_files); |
|
||||
|
|
||||
$files_data[1] = $data; |
|
||||
|
|
||||
$events = []; |
|
||||
foreach ($files_data as $file_data) { |
|
||||
$events = empty($events) ? $file_data : array_merge2($events, $file_data); |
|
||||
} |
|
||||
return $events; |
|
||||
} |
|
||||
} |
|
||||
@ -1,45 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
class GrowthRule extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 加载事件 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data = []) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
$account_change_type_files = []; |
|
||||
$system_change_type_file = $this->getDictPath() . "member" . DIRECTORY_SEPARATOR . "growth_rule.php"; |
|
||||
|
|
||||
|
|
||||
if (is_file($system_change_type_file)) { |
|
||||
$account_change_type_files[] = $system_change_type_file; |
|
||||
} |
|
||||
foreach ($addons as $v) { |
|
||||
$addon_change_type_file = $this->getAddonDictPath($v) . "member" . DIRECTORY_SEPARATOR . "growth_rule.php"; |
|
||||
if (is_file($addon_change_type_file)) { |
|
||||
$account_change_type_files[] = $addon_change_type_file; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
$account_change_type_datas = $this->loadFiles($account_change_type_files); |
|
||||
|
|
||||
$account_change_type_array = []; |
|
||||
foreach ($account_change_type_datas as $account_change_type_data) { |
|
||||
$account_change_type_array = empty($account_change_type_array) ? $account_change_type_data : array_merge2($account_change_type_array, $account_change_type_data); |
|
||||
} |
|
||||
return $account_change_type_array; |
|
||||
} |
|
||||
} |
|
||||
@ -1,50 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 图标 |
|
||||
* Class Icon |
|
||||
* @package core\dict |
|
||||
*/ |
|
||||
class Icon extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* @param array $data |
|
||||
* @return array |
|
||||
*/ |
|
||||
public function load(array $data): array |
|
||||
{ |
|
||||
$sys_path = dirname(app()->getRootPath()) . str_replace('/', DIRECTORY_SEPARATOR, '/admin/src/styles/icon'); |
|
||||
$file_arr = getFileMap($sys_path); |
|
||||
$icon_arr = []; |
|
||||
if (!empty($file_arr)) { |
|
||||
foreach ($file_arr as $ck => $cv) { |
|
||||
if (str_contains($cv, '.json')) { |
|
||||
$json_string = file_get_contents($ck); |
|
||||
$icon = json_decode($json_string, true, 512, JSON_THROW_ON_ERROR); |
|
||||
$icon_arr[] = $icon; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
if (count($icon_arr) > 1) { |
|
||||
$last_icon = array_pop($icon_arr); // 最后一个 |
|
||||
$first_icon = array_shift($icon_arr); // 第一个 |
|
||||
|
|
||||
array_unshift($icon_arr, $last_icon); // 将系统图标放到第一位置 |
|
||||
$icon_arr[] = $first_icon; // 交换位置 |
|
||||
} |
|
||||
|
|
||||
return $icon_arr; |
|
||||
} |
|
||||
} |
|
||||
@ -1,56 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
class Lang extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 加载事件 |
|
||||
* @param array $data //传入语言类型 |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
$system_lang_path = $this->getAppPath() . "lang" . DIRECTORY_SEPARATOR . $data['lang_type'] . DIRECTORY_SEPARATOR; |
|
||||
$lang_files = [ |
|
||||
$system_lang_path . "api.php", |
|
||||
$system_lang_path . "dict.php", |
|
||||
$system_lang_path . "validate.php", |
|
||||
]; |
|
||||
|
|
||||
|
|
||||
foreach ($addons as $v) { |
|
||||
$lang_path = $this->getAddonAppPath($v) . "lang" . DIRECTORY_SEPARATOR . $data['lang_type'] . DIRECTORY_SEPARATOR; |
|
||||
|
|
||||
$api_path = $lang_path . "api.php"; |
|
||||
$dict_path = $lang_path . "dict.php"; |
|
||||
$validate_path = $lang_path . "validate.php"; |
|
||||
if (is_file($api_path)) { |
|
||||
$lang_files[] = $api_path; |
|
||||
|
|
||||
} |
|
||||
if (is_file($dict_path)) { |
|
||||
$lang_files[] = $dict_path; |
|
||||
} |
|
||||
if (is_file($validate_path)) { |
|
||||
$lang_files[] = $validate_path; |
|
||||
} |
|
||||
} |
|
||||
$files_data = $this->loadFiles($lang_files); |
|
||||
$lang = []; |
|
||||
foreach ($files_data as $file_data) { |
|
||||
$lang = empty($lang) ? $file_data : array_merge2($lang, $file_data); |
|
||||
} |
|
||||
return $lang; |
|
||||
} |
|
||||
} |
|
||||
@ -1,46 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
class MemberAccountChangeType extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 加载账户变动方式 |
|
||||
* @param array $data |
|
||||
* @return bool|mixed |
|
||||
*/ |
|
||||
public function load(array $data = []) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
$account_change_type_files = []; |
|
||||
$system_change_type_file = $this->getDictPath() . "member" . DIRECTORY_SEPARATOR . "account_change_type.php"; |
|
||||
|
|
||||
|
|
||||
if (is_file($system_change_type_file)) { |
|
||||
$account_change_type_files[] = $system_change_type_file; |
|
||||
} |
|
||||
foreach ($addons as $v) { |
|
||||
$addon_change_type_file = $this->getAddonDictPath($v) . "member" . DIRECTORY_SEPARATOR . "account_change_type.php"; |
|
||||
if (is_file($addon_change_type_file)) { |
|
||||
$account_change_type_files[] = $addon_change_type_file; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
$account_change_type_datas = $this->loadFiles($account_change_type_files); |
|
||||
|
|
||||
$account_change_type_array = []; |
|
||||
foreach ($account_change_type_datas as $account_change_type_data) { |
|
||||
$account_change_type_array = empty($account_change_type_array) ? $account_change_type_data : array_merge2($account_change_type_array, $account_change_type_data); |
|
||||
} |
|
||||
return $account_change_type_array; |
|
||||
} |
|
||||
} |
|
||||
@ -1,45 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
class MemberBenefits extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 加载事件 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data = []) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
$account_change_type_files = []; |
|
||||
$system_change_type_file = $this->getDictPath() . "member" . DIRECTORY_SEPARATOR . "benefits.php"; |
|
||||
|
|
||||
|
|
||||
if (is_file($system_change_type_file)) { |
|
||||
$account_change_type_files[] = $system_change_type_file; |
|
||||
} |
|
||||
foreach ($addons as $v) { |
|
||||
$addon_change_type_file = $this->getAddonDictPath($v) . "member" . DIRECTORY_SEPARATOR . "benefits.php"; |
|
||||
if (is_file($addon_change_type_file)) { |
|
||||
$account_change_type_files[] = $addon_change_type_file; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
$account_change_type_datas = $this->loadFiles($account_change_type_files); |
|
||||
|
|
||||
$account_change_type_array = []; |
|
||||
foreach ($account_change_type_datas as $account_change_type_data) { |
|
||||
$account_change_type_array = empty($account_change_type_array) ? $account_change_type_data : array_merge2($account_change_type_array, $account_change_type_data); |
|
||||
} |
|
||||
return $account_change_type_array; |
|
||||
} |
|
||||
} |
|
||||
@ -1,45 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
class MemberGift extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 加载事件 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data = []) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
$account_change_type_files = []; |
|
||||
$system_change_type_file = $this->getDictPath() . "member" . DIRECTORY_SEPARATOR . "gift.php"; |
|
||||
|
|
||||
|
|
||||
if (is_file($system_change_type_file)) { |
|
||||
$account_change_type_files[] = $system_change_type_file; |
|
||||
} |
|
||||
foreach ($addons as $v) { |
|
||||
$addon_change_type_file = $this->getAddonDictPath($v) . "member" . DIRECTORY_SEPARATOR . "gift.php"; |
|
||||
if (is_file($addon_change_type_file)) { |
|
||||
$account_change_type_files[] = $addon_change_type_file; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
$account_change_type_datas = $this->loadFiles($account_change_type_files); |
|
||||
|
|
||||
$account_change_type_array = []; |
|
||||
foreach ($account_change_type_datas as $account_change_type_data) { |
|
||||
$account_change_type_array = empty($account_change_type_array) ? $account_change_type_data : array_merge2($account_change_type_array, $account_change_type_data); |
|
||||
} |
|
||||
return $account_change_type_array; |
|
||||
} |
|
||||
} |
|
||||
@ -1,29 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
class Menu extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 加载菜单 |
|
||||
* @param array $data //传入插件,应用类型 |
|
||||
* @return array |
|
||||
*/ |
|
||||
public function load(array $data): array |
|
||||
{ |
|
||||
$menu_path = $this->getAddonDictPath($data['addon']) . "menu" . DIRECTORY_SEPARATOR . $data['app_type'] . ".php"; |
|
||||
if (is_file($menu_path)) { |
|
||||
return include $menu_path; |
|
||||
} |
|
||||
return []; |
|
||||
} |
|
||||
} |
|
||||
@ -1,43 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
class Notice extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 系统uniapp页面链接 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data) |
|
||||
{ |
|
||||
$template_files = []; |
|
||||
$system_path = $this->getDictPath() . "notice" . DIRECTORY_SEPARATOR . $data[ 'type' ] . ".php"; |
|
||||
if (is_file($system_path)) { |
|
||||
$template_files[] = $system_path; |
|
||||
} |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
foreach ($addons as $v) { |
|
||||
$template_path = $this->getAddonDictPath($v) . "notice" . DIRECTORY_SEPARATOR . $data[ 'type' ] . ".php"; |
|
||||
if (is_file($template_path)) { |
|
||||
$template_files[] = $template_path; |
|
||||
} |
|
||||
} |
|
||||
$template_files_data = $this->loadFiles($template_files); |
|
||||
|
|
||||
$template_data_array = []; |
|
||||
foreach ($template_files_data as $file_data) { |
|
||||
$template_data_array = empty($template_data_array) ? $file_data : array_merge($template_data_array, $file_data); |
|
||||
} |
|
||||
return $template_data_array; |
|
||||
} |
|
||||
} |
|
||||
@ -1 +0,0 @@ |
|||||
// | 官方网址:https://www.niucloud.com |
|
||||
@ -1,45 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
class PointRule extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 加载事件 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data = []) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
$account_change_type_files = []; |
|
||||
$system_change_type_file = $this->getDictPath() . "member" . DIRECTORY_SEPARATOR . "point_rule.php"; |
|
||||
|
|
||||
|
|
||||
if (is_file($system_change_type_file)) { |
|
||||
$account_change_type_files[] = $system_change_type_file; |
|
||||
} |
|
||||
foreach ($addons as $v) { |
|
||||
$addon_change_type_file = $this->getAddonDictPath($v) . "member" . DIRECTORY_SEPARATOR . "point_rule.php"; |
|
||||
if (is_file($addon_change_type_file)) { |
|
||||
$account_change_type_files[] = $addon_change_type_file; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
$account_change_type_datas = $this->loadFiles($account_change_type_files); |
|
||||
|
|
||||
$account_change_type_array = []; |
|
||||
foreach ($account_change_type_datas as $account_change_type_data) { |
|
||||
$account_change_type_array = empty($account_change_type_array) ? $account_change_type_data : array_merge2($account_change_type_array, $account_change_type_data); |
|
||||
} |
|
||||
return $account_change_type_array; |
|
||||
} |
|
||||
} |
|
||||
@ -1,95 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
class Poster extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 加载海报模板配置 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data = []) |
|
||||
{ |
|
||||
$addon = $data[ 'addon' ] ?? ''; |
|
||||
$type = $data[ 'type' ] ?? ''; |
|
||||
$schedule_files = []; |
|
||||
if (empty($addon)) { |
|
||||
$system_path = $this->getDictPath() . 'poster' . DIRECTORY_SEPARATOR . 'template.php'; |
|
||||
if (is_file($system_path)) { |
|
||||
$schedule_files[] = $system_path; |
|
||||
} |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
foreach ($addons as $v) { |
|
||||
$addon_path = $this->getAddonDictPath($v) . 'poster' . DIRECTORY_SEPARATOR . 'template.php'; |
|
||||
if (is_file($addon_path)) { |
|
||||
$schedule_files[] = $addon_path; |
|
||||
} |
|
||||
} |
|
||||
} else { |
|
||||
$schedule_files = []; |
|
||||
if ($addon == 'system') { |
|
||||
$system_path = $this->getDictPath() . 'poster' . DIRECTORY_SEPARATOR . 'template.php'; |
|
||||
if (is_file($system_path)) { |
|
||||
$schedule_files[] = $system_path; |
|
||||
} |
|
||||
} else { |
|
||||
$addon_path = $this->getAddonDictPath($addon) . 'poster' . DIRECTORY_SEPARATOR . 'template.php'; |
|
||||
if (is_file($addon_path)) { |
|
||||
$schedule_files[] = $addon_path; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
$schedule_files_data = $this->loadFiles($schedule_files); |
|
||||
$schedule_data_array = []; |
|
||||
foreach ($schedule_files_data as $file_data) { |
|
||||
$schedule_data_array = empty($schedule_data_array) ? $file_data : array_merge($schedule_data_array, $file_data); |
|
||||
} |
|
||||
|
|
||||
if (!empty($type)) { |
|
||||
foreach ($schedule_data_array as $k => $v) { |
|
||||
if ($v[ 'type' ] != $type) { |
|
||||
unset($schedule_data_array[ $k ]); |
|
||||
} |
|
||||
} |
|
||||
$schedule_data_array = array_values($schedule_data_array); |
|
||||
} |
|
||||
return $schedule_data_array; |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取海报组件 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function loadComponents(array $data = []) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
$components_files = []; |
|
||||
foreach ($addons as $v) { |
|
||||
$components_path = $this->getAddonDictPath($v) . "poster" . DIRECTORY_SEPARATOR . "components.php"; |
|
||||
if (is_file($components_path)) { |
|
||||
$components_files[] = $components_path; |
|
||||
} |
|
||||
} |
|
||||
$components_files_data = $this->loadFiles($components_files); |
|
||||
$components = $data; |
|
||||
foreach ($components_files_data as $file_data) { |
|
||||
$components = empty($components) ? $file_data : array_merge2($components, $file_data); |
|
||||
} |
|
||||
return $components; |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
@ -1,40 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
|
|
||||
class Printer extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 打印模板类型 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
$types_files = []; |
|
||||
|
|
||||
foreach ($addons as $v) { |
|
||||
$types_path = $this->getAddonDictPath($v) . "printer" . DIRECTORY_SEPARATOR . "type.php"; |
|
||||
if (is_file($types_path)) { |
|
||||
$types_files[] = $types_path; |
|
||||
} |
|
||||
} |
|
||||
$types_files_data = $this->loadFiles($types_files); |
|
||||
$types = $data; |
|
||||
foreach ($types_files_data as $file_data) { |
|
||||
$types = empty($types) ? $file_data : array_merge2($types, $file_data); |
|
||||
} |
|
||||
return $types; |
|
||||
} |
|
||||
} |
|
||||
@ -1,43 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
class RechargeGift extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 加载会员充值赠品组件 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data = []) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
foreach ($addons as $v) { |
|
||||
$addon_change_type_file = $this->getAddonDictPath($v) . "recharge" . DIRECTORY_SEPARATOR . "package_gift.php"; |
|
||||
if (is_file($addon_change_type_file)) { |
|
||||
$account_change_type_files[] = $addon_change_type_file; |
|
||||
} |
|
||||
} |
|
||||
$account_change_type_datas = $this->loadFiles($account_change_type_files); |
|
||||
$account_change_type_array = []; |
|
||||
foreach ($account_change_type_datas as $account_change_type_data) { |
|
||||
$account_change_type_array = empty($account_change_type_array) ? $account_change_type_data : array_merge2($account_change_type_array, $account_change_type_data); |
|
||||
} |
|
||||
foreach ($account_change_type_array as $key => &$value) { |
|
||||
$value[ 'key' ] = $key; |
|
||||
} |
|
||||
usort($account_change_type_array, function($list_one, $list_two) { |
|
||||
return $list_one[ 'sort' ] <=> $list_two[ 'sort' ]; |
|
||||
}); |
|
||||
return $account_change_type_array; |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
@ -1,33 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
class Route extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 加载路由 |
|
||||
* @param array $data 传入路由端口 |
|
||||
* @return true |
|
||||
*/ |
|
||||
public function load(array $data) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
|
|
||||
foreach ($addons as $k => $v) { |
|
||||
$route_path = $this->getAddonAppPath($v) . DIRECTORY_SEPARATOR . $data['app_type'] . DIRECTORY_SEPARATOR . "route" . DIRECTORY_SEPARATOR . "route.php"; |
|
||||
if (is_file($route_path)) { |
|
||||
include $route_path; |
|
||||
} |
|
||||
} |
|
||||
return true; |
|
||||
} |
|
||||
} |
|
||||
@ -1,60 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
class Schedule extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 加载计划任务调度 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data = []) |
|
||||
{ |
|
||||
$addon = $data['addon'] ?? ''; |
|
||||
$schedule_files = []; |
|
||||
if (empty($addon)) { |
|
||||
$system_path = $this->getDictPath() . 'schedule' . DIRECTORY_SEPARATOR . 'schedule.php'; |
|
||||
if (is_file($system_path)) { |
|
||||
$schedule_files[] = $system_path; |
|
||||
} |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
foreach ($addons as $v) { |
|
||||
$addon_path = $this->getAddonDictPath($v) . 'schedule' . DIRECTORY_SEPARATOR . 'schedule.php'; |
|
||||
if (is_file($addon_path)) { |
|
||||
$schedule_files[] = $addon_path; |
|
||||
} |
|
||||
} |
|
||||
} else { |
|
||||
$schedule_files = []; |
|
||||
if ($addon == 'system') { |
|
||||
$system_path = $this->getDictPath() . 'schedule' . DIRECTORY_SEPARATOR . 'schedule.php'; |
|
||||
if (is_file($system_path)) { |
|
||||
$schedule_files[] = $system_path; |
|
||||
} |
|
||||
} else { |
|
||||
$addon_path = $this->getAddonDictPath($addon) . 'schedule' . DIRECTORY_SEPARATOR . 'schedule.php'; |
|
||||
if (is_file($addon_path)) { |
|
||||
$schedule_files[] = $addon_path; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
$schedule_files_data = $this->loadFiles($schedule_files); |
|
||||
$schedule_data_array = []; |
|
||||
foreach ($schedule_files_data as $file_data) { |
|
||||
$schedule_data_array = empty($schedule_data_array) ? $file_data : array_merge($schedule_data_array, $file_data); |
|
||||
} |
|
||||
return $schedule_data_array; |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
@ -1,38 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
class UniappComponent extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 系统uniapp组件配置 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data) |
|
||||
{ |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
$components_files = []; |
|
||||
foreach ($addons as $v) { |
|
||||
$components_path = $this->getAddonDictPath($v) . "diy" . DIRECTORY_SEPARATOR . "components.php"; |
|
||||
if (is_file($components_path)) { |
|
||||
$components_files[] = $components_path; |
|
||||
} |
|
||||
} |
|
||||
$components_files_data = $this->loadFiles($components_files); |
|
||||
$components = $data; |
|
||||
foreach ($components_files_data as $file_data) { |
|
||||
$components = empty($components) ? $file_data : array_merge2($components, $file_data); |
|
||||
} |
|
||||
return $components; |
|
||||
} |
|
||||
} |
|
||||
@ -1,75 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
use app\service\admin\addon\AddonService; |
|
||||
|
|
||||
class UniappLink extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 系统uniapp页面链接 |
|
||||
* @param array $params |
|
||||
* @return array|false|mixed|string |
|
||||
* @throws \think\db\exception\DataNotFoundException |
|
||||
* @throws \think\db\exception\DbException |
|
||||
* @throws \think\db\exception\ModelNotFoundException |
|
||||
*/ |
|
||||
public function load(array $params = []) |
|
||||
{ |
|
||||
if (!empty($params[ 'params' ][ 'addon' ])) { |
|
||||
$addons = [ $params[ 'params' ][ 'addon' ] ]; |
|
||||
} else { |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
} |
|
||||
|
|
||||
$link_files = []; |
|
||||
|
|
||||
foreach ($addons as $v) { |
|
||||
$link_path = $this->getAddonDictPath($v) . "diy" . DIRECTORY_SEPARATOR . "links.php"; |
|
||||
if (is_file($link_path)) { |
|
||||
$link_files[ $v ] = $link_path; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
$addon_service = new AddonService(); |
|
||||
$addon_info_list = $addon_service->getAddonListByKeys(array_keys($link_files)); |
|
||||
|
|
||||
if (!empty($params[ 'params' ][ 'query' ]) && $params[ 'params' ][ 'query' ] == 'addon') { |
|
||||
$list_key = array_column($addon_info_list, 'key'); |
|
||||
$addon_info_list = array_combine($list_key, $addon_info_list); |
|
||||
return $addon_info_list; |
|
||||
} else { |
|
||||
|
|
||||
$links = $params[ 'data' ]; |
|
||||
|
|
||||
foreach ($link_files as $k => $v) { |
|
||||
$addon_link = include $v; |
|
||||
if (!empty($addon_link)) { |
|
||||
$addon_info = []; |
|
||||
foreach ($addon_info_list as $ck => $cv) { |
|
||||
if ($cv[ 'key' ] == $k) { |
|
||||
$addon_info = $cv; |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
foreach ($addon_link as $ck => $cv) { |
|
||||
$addon_link[ $ck ][ 'addon_info' ] = $addon_info; |
|
||||
} |
|
||||
$links = array_merge($links, $addon_link); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return $links; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,52 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
class UniappPages extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 系统uniapp页面 |
|
||||
* @param array $data |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function load(array $data = []) |
|
||||
{ |
|
||||
// 筛选插件 |
|
||||
if (!empty($data[ 'addon' ])) { |
|
||||
$addons = [ $data[ 'addon' ] ]; |
|
||||
} else { |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
} |
|
||||
|
|
||||
$page_files = []; |
|
||||
foreach ($addons as $v) { |
|
||||
$page_path = $this->getAddonDictPath($v) . "diy" . DIRECTORY_SEPARATOR . "pages.php"; |
|
||||
if (is_file($page_path)) { |
|
||||
$page_files[] = $page_path; |
|
||||
} |
|
||||
} |
|
||||
$page_files_data = $this->loadFiles($page_files); |
|
||||
if (!empty($data[ 'addon' ])) { |
|
||||
$pages = []; |
|
||||
} else { |
|
||||
$pages = $data; |
|
||||
} |
|
||||
foreach ($page_files_data as $file_data) { |
|
||||
if (empty($pages)) { |
|
||||
$pages = $file_data; |
|
||||
} else { |
|
||||
$pages = array_merge2($pages, $file_data); |
|
||||
} |
|
||||
} |
|
||||
return $pages; |
|
||||
} |
|
||||
} |
|
||||
@ -1,95 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
use app\service\admin\addon\AddonService; |
|
||||
|
|
||||
class UniappTemplate extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 系统uniapp页面模板 |
|
||||
* @param array $params |
|
||||
* @return array|false|mixed|string |
|
||||
*/ |
|
||||
public function load(array $params) |
|
||||
{ |
|
||||
if (!empty($params[ 'params' ][ 'addon' ])) { |
|
||||
$addons = [ $params[ 'params' ][ 'addon' ] ]; |
|
||||
} else { |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
} |
|
||||
|
|
||||
$app_keys = []; // 应用插件key集合 |
|
||||
$apps = []; // 应用插件集合 |
|
||||
$page_files = []; // 模板页面文件集合 |
|
||||
|
|
||||
// 筛选插件 |
|
||||
if (!empty($params[ 'params' ]) && !empty($params[ 'params' ][ 'addon' ])) { |
|
||||
$is_pass = true; |
|
||||
foreach ($addons as $k => $v) { |
|
||||
if ($params[ 'params' ][ 'addon' ] == $v) { |
|
||||
$addons = [ $v ]; |
|
||||
$is_pass = false; |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// 如果没有匹配到,则返回系统的 |
|
||||
if ($is_pass) { |
|
||||
return $params[ 'data' ]; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
foreach ($addons as $v) { |
|
||||
$page_path = $this->getAddonDictPath($v) . "diy" . DIRECTORY_SEPARATOR . "template.php"; |
|
||||
if (is_file($page_path)) { |
|
||||
if (!empty($params[ 'params' ][ 'query' ]) && $params[ 'params' ][ 'query' ] == 'addon') { |
|
||||
$file = include $page_path; |
|
||||
if (!empty($file)) { |
|
||||
$app_keys[] = $v; |
|
||||
$apps[ $v ] = $file; |
|
||||
} |
|
||||
} else { |
|
||||
$page_files[] = $page_path; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// 查询存在模板页面的应用插件列表 |
|
||||
if (!empty($params[ 'params' ][ 'query' ]) && $params[ 'params' ][ 'query' ] == 'addon') { |
|
||||
$addon_service = new AddonService(); |
|
||||
$list = $addon_service->getAddonListByKeys($app_keys); |
|
||||
$list_key = array_column($list, 'key'); |
|
||||
$list = array_combine($list_key, $list); |
|
||||
foreach ($list as $k => $v) { |
|
||||
$list[ $k ][ 'list' ] = $apps[ $k ]; |
|
||||
} |
|
||||
return $list; |
|
||||
} else { |
|
||||
// 查询应用插件下的模板页面数据 |
|
||||
$page_files_data = $this->loadFiles($page_files); |
|
||||
if (!empty($params[ 'params' ]) && !empty($params[ 'params' ][ 'addon' ])) { |
|
||||
$pages = []; |
|
||||
} else { |
|
||||
$pages = $params[ 'data' ]; |
|
||||
} |
|
||||
foreach ($page_files_data as $file_data) { |
|
||||
if (empty($pages)) { |
|
||||
$pages = $file_data; |
|
||||
} else { |
|
||||
$pages = array_merge($pages, $file_data); |
|
||||
} |
|
||||
} |
|
||||
return $pages; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,75 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\dict; |
|
||||
|
|
||||
|
|
||||
use app\service\admin\addon\AddonService; |
|
||||
|
|
||||
class WebLink extends BaseDict |
|
||||
{ |
|
||||
/** |
|
||||
* 系统weblink页面链接 |
|
||||
* @param array $params |
|
||||
* @return array|false|mixed|string |
|
||||
* @throws \think\db\exception\DataNotFoundException |
|
||||
* @throws \think\db\exception\DbException |
|
||||
* @throws \think\db\exception\ModelNotFoundException |
|
||||
*/ |
|
||||
public function load(array $params = []) |
|
||||
{ |
|
||||
if (!empty($params[ 'params' ][ 'addon' ])) { |
|
||||
$addons = [ $params[ 'params' ][ 'addon' ] ]; |
|
||||
} else { |
|
||||
$addons = $this->getLocalAddons(); |
|
||||
} |
|
||||
|
|
||||
$link_files = []; |
|
||||
|
|
||||
foreach ($addons as $v) { |
|
||||
$link_path = $this->getAddonDictPath($v) . "web" . DIRECTORY_SEPARATOR . "web_links.php"; |
|
||||
if (is_file($link_path)) { |
|
||||
$link_files[ $v ] = $link_path; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
$addon_service = new AddonService(); |
|
||||
$addon_info_list = $addon_service->getAddonListByKeys(array_keys($link_files)); |
|
||||
|
|
||||
if (!empty($params[ 'params' ][ 'query' ]) && $params[ 'params' ][ 'query' ] == 'addon') { |
|
||||
$list_key = array_column($addon_info_list, 'key'); |
|
||||
$addon_info_list = array_combine($list_key, $addon_info_list); |
|
||||
return $addon_info_list; |
|
||||
} else { |
|
||||
|
|
||||
$links = $params[ 'data' ]; |
|
||||
|
|
||||
foreach ($link_files as $k => $v) { |
|
||||
$addon_link = include $v; |
|
||||
if (!empty($addon_link)) { |
|
||||
$addon_info = []; |
|
||||
foreach ($addon_info_list as $ck => $cv) { |
|
||||
if ($cv[ 'key' ] == $k) { |
|
||||
$addon_info = $cv; |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
foreach ($addon_link as $ck => $cv) { |
|
||||
$addon_link[ $ck ][ 'addon_info' ] = $addon_info; |
|
||||
} |
|
||||
$links = array_merge($links, $addon_link); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return $links; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,17 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\exception; |
|
||||
|
|
||||
use RuntimeException; |
|
||||
use Throwable; |
|
||||
|
|
||||
/** |
|
||||
* 插件错误异常处理类 |
|
||||
*/ |
|
||||
class AddonException extends RuntimeException |
|
||||
{ |
|
||||
public function __construct($message = "", $code = 0, Throwable $previous = null) |
|
||||
{ |
|
||||
parent::__construct($message, $code, $previous); |
|
||||
} |
|
||||
} |
|
||||
@ -1,17 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\exception; |
|
||||
|
|
||||
use RuntimeException; |
|
||||
use Throwable; |
|
||||
|
|
||||
/** |
|
||||
* 平台管理端错误异常处理类 |
|
||||
*/ |
|
||||
class AdminException extends RuntimeException |
|
||||
{ |
|
||||
public function __construct($message = "", $code = 0, Throwable $previous = null) |
|
||||
{ |
|
||||
parent::__construct($message, $code, $previous); |
|
||||
} |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\exception; |
|
||||
|
|
||||
use RuntimeException; |
|
||||
use Throwable; |
|
||||
|
|
||||
/** |
|
||||
* 前端错误异常处理类 |
|
||||
*/ |
|
||||
class ApiException extends RuntimeException |
|
||||
{ |
|
||||
public function __construct($message = "", $code = 0, Throwable $previous = null) |
|
||||
{ |
|
||||
|
|
||||
parent::__construct($message, $code, $previous); |
|
||||
} |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\exception; |
|
||||
|
|
||||
use RuntimeException; |
|
||||
use Throwable; |
|
||||
|
|
||||
/** |
|
||||
* 授权错误异常处理类 |
|
||||
*/ |
|
||||
class AuthException extends RuntimeException |
|
||||
{ |
|
||||
public function __construct($message = "", $code = 0, Throwable $previous = null) |
|
||||
{ |
|
||||
|
|
||||
parent::__construct($message, $code, $previous); |
|
||||
} |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\exception; |
|
||||
|
|
||||
use RuntimeException; |
|
||||
use Throwable; |
|
||||
|
|
||||
/** |
|
||||
* 平台管理端错误异常处理类 |
|
||||
*/ |
|
||||
class CaptchaException extends RuntimeException |
|
||||
{ |
|
||||
public function __construct($message = "", $code = 0, Throwable $previous = null) |
|
||||
{ |
|
||||
|
|
||||
parent::__construct($message, $code, $previous); |
|
||||
} |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\exception; |
|
||||
|
|
||||
use RuntimeException; |
|
||||
use Throwable; |
|
||||
|
|
||||
/** |
|
||||
* 平台管理端错误异常处理类 |
|
||||
*/ |
|
||||
class CommonException extends RuntimeException |
|
||||
{ |
|
||||
public function __construct($message = "", $code = 0, Throwable $previous = null) |
|
||||
{ |
|
||||
|
|
||||
parent::__construct($message, $code, $previous); |
|
||||
} |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\exception; |
|
||||
|
|
||||
use RuntimeException; |
|
||||
use Throwable; |
|
||||
|
|
||||
/** |
|
||||
* 插件错误异常处理类 |
|
||||
*/ |
|
||||
class NiucloudException extends RuntimeException |
|
||||
{ |
|
||||
public function __construct($message = "", $code = 0, Throwable $previous = null) |
|
||||
{ |
|
||||
|
|
||||
parent::__construct($message, $code, $previous); |
|
||||
} |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\exception; |
|
||||
|
|
||||
use RuntimeException; |
|
||||
use Throwable; |
|
||||
|
|
||||
/** |
|
||||
* 消息错误异常处理类 |
|
||||
*/ |
|
||||
class NoticeException extends RuntimeException |
|
||||
{ |
|
||||
public function __construct($message = "", $code = 0, Throwable $previous = null) |
|
||||
{ |
|
||||
|
|
||||
parent::__construct($message, $code, $previous); |
|
||||
} |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\exception; |
|
||||
|
|
||||
use RuntimeException; |
|
||||
use Throwable; |
|
||||
|
|
||||
/** |
|
||||
* 支付错误异常处理类 |
|
||||
*/ |
|
||||
class PayException extends RuntimeException |
|
||||
{ |
|
||||
public function __construct($message = "", $code = 0, Throwable $previous = null) |
|
||||
{ |
|
||||
|
|
||||
parent::__construct($message, $code, $previous); |
|
||||
} |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\exception; |
|
||||
|
|
||||
use RuntimeException; |
|
||||
use Throwable; |
|
||||
|
|
||||
/** |
|
||||
* 服务器异常处理类 |
|
||||
*/ |
|
||||
class ServerException extends RuntimeException |
|
||||
{ |
|
||||
public function __construct($message = "", $code = 409, Throwable $previous = null) |
|
||||
{ |
|
||||
|
|
||||
parent::__construct($message, $code, $previous); |
|
||||
} |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\exception; |
|
||||
|
|
||||
use RuntimeException; |
|
||||
use Throwable; |
|
||||
|
|
||||
/** |
|
||||
* 附件管理错误异常处理类 |
|
||||
*/ |
|
||||
class UploadFileException extends RuntimeException |
|
||||
{ |
|
||||
public function __construct($message = "", $code = 0, Throwable $previous = null) |
|
||||
{ |
|
||||
|
|
||||
parent::__construct($message, $code, $previous); |
|
||||
} |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\exception; |
|
||||
|
|
||||
use RuntimeException; |
|
||||
use Throwable; |
|
||||
|
|
||||
/** |
|
||||
* 微信错误异常处理类 |
|
||||
*/ |
|
||||
class WechatException extends RuntimeException |
|
||||
{ |
|
||||
public function __construct($message = "", $code = 0, Throwable $previous = null) |
|
||||
{ |
|
||||
|
|
||||
parent::__construct($message, $code, $previous); |
|
||||
} |
|
||||
} |
|
||||
@ -1,57 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\job; |
|
||||
|
|
||||
use core\util\Queue; |
|
||||
|
|
||||
/** |
|
||||
* 任务派遣队列 |
|
||||
*/ |
|
||||
class Dispatch |
|
||||
{ |
|
||||
|
|
||||
/** |
|
||||
* 加入队列 |
|
||||
* @param $action |
|
||||
* @param array $data |
|
||||
* @param int $secs |
|
||||
* @param string|null $queue_name |
|
||||
* @param bool $is_async |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public static function dispatch($action, array $data = [], int $secs = 0, string $queue_name = null, bool $is_async = true) |
|
||||
{ |
|
||||
$class = static::class;//调用主调类 |
|
||||
if (env('queue.state', false) && $is_async) { |
|
||||
$queue = Queue::instance()->job($class)->secs($secs); |
|
||||
if (is_array($action)) { |
|
||||
$queue->data(...$action); |
|
||||
} else if (is_string($action)) { |
|
||||
$queue->method($action)->data(...$data); |
|
||||
} |
|
||||
if ($queue_name) { |
|
||||
$queue->setQueueName($queue_name); |
|
||||
} |
|
||||
return $queue->push(); |
|
||||
} else { |
|
||||
if($secs == 0){ |
|
||||
$class_name = '\\' . $class; |
|
||||
$res = new $class_name(); |
|
||||
if (is_array($action)) { |
|
||||
return $res->doJob(...$action); |
|
||||
} else { |
|
||||
return $res->$action(...$data); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,118 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\loader; |
|
||||
|
|
||||
use Exception; |
|
||||
use think\DbManager; |
|
||||
use think\Facade; |
|
||||
use think\helper\Str; |
|
||||
|
|
||||
abstract class Loader extends Facade |
|
||||
{ |
|
||||
protected $config_name = null;//配置文件名 |
|
||||
|
|
||||
protected $name = null; |
|
||||
protected $namespace = null; |
|
||||
|
|
||||
protected $class = null; |
|
||||
protected $config = null; |
|
||||
protected $config_file = null; |
|
||||
|
|
||||
/** |
|
||||
* @param string $name |
|
||||
* @param array $config |
|
||||
*/ |
|
||||
public function __construct($name = '', array $config = []) |
|
||||
{ |
|
||||
if (is_array($name)) { |
|
||||
$config = $name; |
|
||||
$name = null; |
|
||||
} |
|
||||
if ($name) { |
|
||||
$this->name = $name; |
|
||||
} |
|
||||
$this->config = $config; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取默认驱动 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function getDefault(); |
|
||||
|
|
||||
/** |
|
||||
* 创建实例对象 |
|
||||
* @param string $type |
|
||||
* @return object|DbManager |
|
||||
* @throws Exception |
|
||||
*/ |
|
||||
public function create(string $type) |
|
||||
{ |
|
||||
$class = $this->getClass($type); |
|
||||
return self::createFacade($class, [ |
|
||||
$this->name, |
|
||||
$this->config, |
|
||||
$this->config_file |
|
||||
], true); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取类 |
|
||||
* @param string $type |
|
||||
* @return mixed|string |
|
||||
* @throws Exception |
|
||||
*/ |
|
||||
public function getClass(string $type) |
|
||||
{ |
|
||||
$class = config($this->config_name . '.drivers.' . $type . '.driver'); |
|
||||
if (!empty($class) && class_exists($class)) { |
|
||||
return $class; |
|
||||
} else { |
|
||||
if ($this->namespace || str_contains($type, '\\')) { |
|
||||
$class = str_contains($type, '\\') ? $type : $this->namespace . $type; |
|
||||
if (class_exists($class)) { |
|
||||
return $class; |
|
||||
} else { |
|
||||
$class = str_contains($type, '\\') ? $type : $this->namespace . Str::studly($type); |
|
||||
if (class_exists($class)) { |
|
||||
return $class; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
throw new Exception("Driver [$type] not supported."); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 通过装载器获取实例 |
|
||||
* @return object|DbManager |
|
||||
* @throws Exception |
|
||||
*/ |
|
||||
public function getLoader() |
|
||||
{ |
|
||||
|
|
||||
if (empty($this->class)) { |
|
||||
$this->name = $this->name ?: $this->getDefault(); |
|
||||
if (!$this->name) { |
|
||||
throw new Exception(sprintf( |
|
||||
'could not find driver [%s].', static::class |
|
||||
)); |
|
||||
} |
|
||||
$this->class = $this->create($this->name); |
|
||||
} |
|
||||
return $this->class; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 动态调用 |
|
||||
* @param $method |
|
||||
* @param $arguments |
|
||||
* @return mixed |
|
||||
* @throws Exception |
|
||||
*/ |
|
||||
public function __call($method, $arguments) |
|
||||
{ |
|
||||
return $this->getLoader()->{$method}(...$arguments); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,69 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\loader; |
|
||||
|
|
||||
|
|
||||
abstract class Storage |
|
||||
{ |
|
||||
|
|
||||
/** |
|
||||
* 驱动名称 |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $name; |
|
||||
|
|
||||
/** |
|
||||
* 驱动配置文件名 |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $config_file; |
|
||||
|
|
||||
/** |
|
||||
* 错误信息 |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $error; |
|
||||
|
|
||||
/** |
|
||||
* BaseStorage constructor. |
|
||||
* @param string $name 驱动名 |
|
||||
* @param array $config 其他配置 |
|
||||
* @param string|null $config_file 驱动配置名 |
|
||||
*/ |
|
||||
public function __construct(string $name, array $config = [], string $config_file = null) |
|
||||
{ |
|
||||
$this->name = $name; |
|
||||
$this->config_file = $config_file; |
|
||||
$this->initialize($config); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置错误信息 |
|
||||
* @param string|null $error |
|
||||
* @return bool |
|
||||
*/ |
|
||||
protected function setError(?string $error = null) |
|
||||
{ |
|
||||
$this->error = $error; |
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取错误信息 |
|
||||
* @return string |
|
||||
*/ |
|
||||
public function getError() |
|
||||
{ |
|
||||
$error = $this->error; |
|
||||
$this->error = null; |
|
||||
return $error; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 初始化 |
|
||||
* @param array $config |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function initialize(array $config); |
|
||||
|
|
||||
} |
|
||||
@ -1,42 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\oauth; |
|
||||
|
|
||||
use core\loader\Storage; |
|
||||
|
|
||||
/** |
|
||||
* 第三方授权基类 |
|
||||
* Class BaseOauth |
|
||||
* @package core\oauth |
|
||||
*/ |
|
||||
abstract class BaseOauth extends Storage |
|
||||
{ |
|
||||
protected $config;//配置 |
|
||||
|
|
||||
/** |
|
||||
* 初始化 |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取粉丝信息 |
|
||||
* @param string|null $openid |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract public function getFansInfo(string $openid = null); |
|
||||
|
|
||||
/** |
|
||||
* 授权 |
|
||||
* @param string|null $code |
|
||||
* @param array $options |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract public function oauth(string $code = null, array $options = []); |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -1,38 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\oauth; |
|
||||
|
|
||||
use core\loader\Loader; |
|
||||
|
|
||||
/** |
|
||||
* @see OauthLoader |
|
||||
* @package think\facade |
|
||||
*/ |
|
||||
class OauthLoader extends Loader |
|
||||
{ |
|
||||
/** |
|
||||
* 空间名 |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $namespace = '\\core\\oauth\\'; |
|
||||
|
|
||||
protected $config_name = 'oauth'; |
|
||||
|
|
||||
/** |
|
||||
* 默认驱动 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
protected function getDefault() |
|
||||
{ |
|
||||
return config('oauth.default'); |
|
||||
} |
|
||||
} |
|
||||
@ -1,32 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\oauth; |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 微信小程序授权 |
|
||||
* Class Weapp |
|
||||
* @package core\oauth |
|
||||
*/ |
|
||||
class Weapp extends BaseOauth |
|
||||
{ |
|
||||
|
|
||||
/** |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
parent::initialize($config); |
|
||||
} |
|
||||
|
|
||||
public function getFansInfo(string $openid = null) |
|
||||
{ |
|
||||
// TODO: Implement getFansInfo() method. |
|
||||
} |
|
||||
|
|
||||
public function oauth(string $code = null, array $options = []) |
|
||||
{ |
|
||||
// TODO: Implement oauth() method. |
|
||||
} |
|
||||
} |
|
||||
@ -1,40 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\oauth; |
|
||||
|
|
||||
|
|
||||
use app\service\core\wechat\CoreWechatService; |
|
||||
|
|
||||
/** |
|
||||
* 微信公众号登录 |
|
||||
* Class Wechat |
|
||||
* @package core\oauth |
|
||||
*/ |
|
||||
class Wechat extends BaseOauth |
|
||||
{ |
|
||||
|
|
||||
/** |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
parent::initialize($config); |
|
||||
} |
|
||||
|
|
||||
public function getFansInfo(string $openid = null) |
|
||||
{ |
|
||||
// TODO: Implement getFansInfo() method. |
|
||||
} |
|
||||
|
|
||||
public function instance() |
|
||||
{ |
|
||||
return CoreWechatService::app()->oauth; |
|
||||
} |
|
||||
|
|
||||
public function oauth(string $code = null, array $options = []) |
|
||||
{ |
|
||||
// $this->instance()-> |
|
||||
// TODO: Implement oauth() method. |
|
||||
} |
|
||||
} |
|
||||
@ -1,389 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\pay; |
|
||||
|
|
||||
use app\dict\pay\OnlinePayDict; |
|
||||
use app\dict\pay\RefundDict; |
|
||||
use app\dict\pay\TransferDict; |
|
||||
use core\exception\PayException; |
|
||||
use Psr\Http\Message\ResponseInterface; |
|
||||
use Throwable; |
|
||||
use Yansongda\Pay\Exception\ContainerException; |
|
||||
use Yansongda\Pay\Exception\InvalidParamsException; |
|
||||
use Yansongda\Pay\Exception\ServiceNotFoundException; |
|
||||
use Yansongda\Pay\Pay; |
|
||||
use Yansongda\Supports\Collection; |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 文件管理驱动类 |
|
||||
* Class FileDriver |
|
||||
* @package core\file |
|
||||
*/ |
|
||||
class Alipay extends BasePay |
|
||||
{ |
|
||||
|
|
||||
/** |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
* @throws ContainerException |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
parent::initialize($config); |
|
||||
$config['app_public_cert_path'] = url_to_path($config['app_public_cert_path'] ?? ''); |
|
||||
$config['alipay_public_cert_path'] = url_to_path($config['alipay_public_cert_path'] ?? ''); |
|
||||
$config['alipay_root_cert_path'] = url_to_path($config['alipay_root_cert_path'] ?? ''); |
|
||||
$config['mode'] = Pay::MODE_NORMAL; |
|
||||
$this->config = $this->payConfig($config, 'alipay'); |
|
||||
Pay::config($this->config); |
|
||||
} |
|
||||
|
|
||||
public function mp(array $params) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 网页支付 |
|
||||
* @param array $params |
|
||||
* @return array |
|
||||
*/ |
|
||||
public function web(array $params) |
|
||||
{ |
|
||||
return $this->returnFormat(Pay::alipay()->web([ |
|
||||
'out_trade_no' => $params['out_trade_no'], |
|
||||
'total_amount' => $params['money'], |
|
||||
'subject' => $params['body'], |
|
||||
'_method' => 'get', |
|
||||
])); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 手机网页支付 |
|
||||
* @param array $params |
|
||||
* @return array |
|
||||
*/ |
|
||||
public function wap(array $params) |
|
||||
{ |
|
||||
$response = Pay::alipay()->h5([ |
|
||||
'out_trade_no' => $params['out_trade_no'], |
|
||||
'total_amount' => $params['money'], |
|
||||
'subject' => $params['body'], |
|
||||
'quit_url' => $params['quit_url'] ?? '',//用户付款中途退出返回商户网站的地址, 一般是商品详情页或购物车页 |
|
||||
'_method' => 'get', |
|
||||
]); |
|
||||
|
|
||||
$redirects = $response->getHeader('Location'); |
|
||||
$effective_url = end($redirects); |
|
||||
return ['url' => $effective_url]; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* app支付 |
|
||||
* @param array $params |
|
||||
* @return array |
|
||||
*/ |
|
||||
public function app(array $params) |
|
||||
|
|
||||
{ |
|
||||
return $this->returnFormat(Pay::alipay()->app([ |
|
||||
'out_trade_no' => $params['out_trade_no'], |
|
||||
'total_amount' => $params['money'], |
|
||||
'subject' => $params['body'],//用户付款中途退出返回商户网站的地址, 一般是商品详情页或购物车页 |
|
||||
])); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 小程序支付 |
|
||||
* @param array $params |
|
||||
* @return Collection |
|
||||
*/ |
|
||||
public function mini(array $params) |
|
||||
{ |
|
||||
return Pay::alipay()->mini([ |
|
||||
'out_trade_no' => $params['out_trade_no'], |
|
||||
'total_amount' => $params['money'], |
|
||||
'subject' => $params['body'], |
|
||||
'buyer_id' => $params['buyer_id'],//买家支付宝用户ID 注:交易的买家与卖家不能相同。 |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 付款码支付 |
|
||||
* @param array $params |
|
||||
* @return Collection |
|
||||
*/ |
|
||||
public function pos(array $params) |
|
||||
{ |
|
||||
return Pay::alipay()->pos([ |
|
||||
'out_trade_no' => $params['out_trade_no'], |
|
||||
'auth_code' => $params['auth_code'],//付授权码。 当面付场景传买家的付款码(25~30开头的长度为16~24位的数字,实际字符串长度以开发者获取的付款码长度为准)或者刷脸标识串(fp开头的35位字符串)。 |
|
||||
'total_amount' => $params['money'], |
|
||||
'subject' => $params['body'], |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 扫码支付 |
|
||||
* @param array $params |
|
||||
* @return Collection |
|
||||
*/ |
|
||||
public function scan(array $params) |
|
||||
{ |
|
||||
return Pay::alipay()->scan([ |
|
||||
'out_trade_no' => $params['out_trade_no'], |
|
||||
'total_amount' => $params['money'], |
|
||||
'subject' => $params['body'], |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 转账 |
|
||||
* @param array $params |
|
||||
* @return array |
|
||||
*/ |
|
||||
public function transfer(array $params) |
|
||||
{ |
|
||||
|
|
||||
$result = $this->returnFormat(Pay::alipay()->transfer([ |
|
||||
'out_biz_no' => $params['transfer_no'], |
|
||||
'trans_amount' => $params['money'], |
|
||||
'product_code' => $params['product_code'] ?: 'TRANS_ACCOUNT_NO_PWD',//业务产品码,单笔无密转账到支付宝账户固定为 : TRANS_ACCOUNT_NO_PWD; 收发现金红包固定为 : STD_RED_PACKET; |
|
||||
'biz_scene' => $params['scene'] ?: 'DIRECT_TRANSFER',//描述特定的业务场景,可传的参数如下:DIRECT_TRANSFER:单笔无密转账到支付宝,B2C现金红包;PERSONAL_COLLECTION:C2C现金红包-领红包 |
|
||||
'payee_info' => [//收款方信息 |
|
||||
'identity' => $params['to_no'],//参与方的唯一标识 |
|
||||
'identity_type' => $params['to_type'] ?: 'ALIPAY_LOGON_ID',//参与方的标识类型,目前支持如下类型:1、ALIPAY_USER_ID 支付宝的会员ID2、ALIPAY_LOGON_ID:支付宝登录号,支持邮箱和手机号格式3、ALIPAY_OPEN_ID:支付宝openid |
|
||||
'name' => $params['to_name'],//参与方真实姓名,如果非空,将校验收款支付宝账号姓名一致性。当identity_type=ALIPAY_LOGON_ID时,本字段必填。 |
|
||||
], |
|
||||
])); |
|
||||
if (!empty($result['msg']) && $result['msg'] != 'Success') { |
|
||||
throw new PayException($result['sub_msg']); |
|
||||
} else { |
|
||||
$status = $result['status']; |
|
||||
$status_array = [ |
|
||||
'SUCCESS' => TransferDict::SUCCESS, |
|
||||
'WAIT_PAY' => TransferDict::WAIT, |
|
||||
'CLOSED' => TransferDict::FAIL, |
|
||||
'FAIL' => TransferDict::FAIL |
|
||||
]; |
|
||||
$res = [ |
|
||||
'status' => $status_array[$status], |
|
||||
]; |
|
||||
if ($status == 'FAIL') { |
|
||||
$res['fail_reason'] = $result['fail_reason']; |
|
||||
} |
|
||||
} |
|
||||
return $res; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 支付关闭 |
|
||||
* @param string $out_trade_no |
|
||||
* @return bool |
|
||||
* @throws ContainerException |
|
||||
* @throws InvalidParamsException |
|
||||
* @throws ServiceNotFoundException |
|
||||
*/ |
|
||||
public function close(string $out_trade_no) |
|
||||
{ |
|
||||
$result = $this->returnFormat(Pay::alipay()->close([ |
|
||||
'out_trade_no' => $out_trade_no, |
|
||||
])); |
|
||||
//todo 支付宝关闭异步回调 |
|
||||
if (isset($result['sub_code']) && in_array($result['sub_code'], ['ACQ.REASON_ILLEGAL_STATUS', 'ACQ.REASON_TRADE_STATUS_INVALID', 'ACQ.TRADE_NOT_EXIST', 'ACQ.TRADE_STATUS_ERROR'])) { |
|
||||
return true; |
|
||||
} |
|
||||
if (!empty($result['msg']) && $result['msg'] == 'Success') { |
|
||||
return true; |
|
||||
} else { |
|
||||
return false; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 退款 |
|
||||
* @param array $params |
|
||||
* @return array|false |
|
||||
* @throws ContainerException |
|
||||
* @throws InvalidParamsException |
|
||||
* @throws ServiceNotFoundException |
|
||||
*/ |
|
||||
public function refund(array $params) |
|
||||
{ |
|
||||
$out_trade_no = $params['out_trade_no']; |
|
||||
$money = $params['money']; |
|
||||
// $total = $params['total']; |
|
||||
$refund_no = $params['refund_no']; |
|
||||
$result = $this->returnFormat(Pay::alipay()->refund([ |
|
||||
'out_trade_no' => $out_trade_no, |
|
||||
'refund_amount' => $money, |
|
||||
'out_request_no' => $refund_no |
|
||||
])); |
|
||||
if (!empty($result['msg']) && $result['msg'] == 'Success') { |
|
||||
$fund_change = $result['fund_change'];//退款是否成功可以根据同步响应的 fund_change 参数来判断,fund_change 表示本次退款是否发生了资金变化,返回 Y 表示退款成功,返回 N 则表示本次退款未发生资金变动 。 |
|
||||
if ($fund_change == 'Y') { |
|
||||
$status = RefundDict::SUCCESS; |
|
||||
} else { |
|
||||
$status = RefundDict::DEALING; |
|
||||
} |
|
||||
return [ |
|
||||
'status' => $status, |
|
||||
'refund_no' => $refund_no, |
|
||||
'out_trade_no' => $out_trade_no |
|
||||
]; |
|
||||
} else { |
|
||||
//todo 这儿可以抛出错误 |
|
||||
return false; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 支部异步回调 |
|
||||
* @param string $action |
|
||||
* @param callable $callback |
|
||||
* @return ResponseInterface|string |
|
||||
*/ |
|
||||
public function notify(string $action, callable $callback) |
|
||||
{ |
|
||||
try { |
|
||||
$result = Pay::alipay()->callback(); |
|
||||
//通过返回的值 |
|
||||
if (!empty($result)) {//成功 |
|
||||
if ($action == 'pay') { |
|
||||
//todo 这儿需要具体设计 |
|
||||
$temp_data = array( |
|
||||
'mchid' => $result['seller_id'], |
|
||||
'trade_no' => $result['trade_no'], |
|
||||
'result' => $result, |
|
||||
'status' => OnlinePayDict::getAliPayStatus($result['trade_status']) |
|
||||
); |
|
||||
$callback_result = $callback($result['out_trade_no'], $temp_data); |
|
||||
if (is_bool($callback_result) && $callback_result) { |
|
||||
return Pay::alipay()->success(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
return $this->fail(); |
|
||||
} catch ( Throwable $e ) { |
|
||||
return $this->fail(); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 查询普通支付订单 |
|
||||
* @param array $params |
|
||||
* @return array |
|
||||
* @throws ContainerException |
|
||||
* @throws InvalidParamsException |
|
||||
* @throws ServiceNotFoundException |
|
||||
*/ |
|
||||
public function getOrder(array $params = []) |
|
||||
{ |
|
||||
$out_trade_no = $params['out_trade_no']; |
|
||||
$order = [ |
|
||||
'out_trade_no' => $out_trade_no, |
|
||||
]; |
|
||||
$result = $this->returnFormat(Pay::alipay()->query($order)); |
|
||||
if (!empty($result['msg']) && $result['msg'] == 'Success') { |
|
||||
return [ |
|
||||
'status' => OnlinePayDict::getAliPayStatus($result['trade_status']) |
|
||||
]; |
|
||||
} else { |
|
||||
if (!empty($result['sub_code']) && $result['sub_code'] == 'ACQ.ACQ.SYSTEM_ERROR') { |
|
||||
throw new PayException($result['msg']); |
|
||||
} else { |
|
||||
return []; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 查询退款单据 |
|
||||
* @param string $out_trade_no |
|
||||
* @param string|null $refund_no |
|
||||
* @return array |
|
||||
* @throws ContainerException |
|
||||
* @throws InvalidParamsException |
|
||||
* @throws ServiceNotFoundException |
|
||||
*/ |
|
||||
public function getRefund(string $out_trade_no, ?string $refund_no) |
|
||||
{ |
|
||||
$order = [ |
|
||||
'out_trade_no' => $out_trade_no, |
|
||||
'out_request_no' => $refund_no, |
|
||||
'_action' => 'refund', // 默认值,查询退款网页订单 |
|
||||
]; |
|
||||
|
|
||||
$result = $this->returnFormat(Pay::alipay()->query($order)); |
|
||||
if (!empty($result['msg']) && $result['msg'] == 'Success') { |
|
||||
$refund_status = $result['refund_status'] ?? ''; |
|
||||
if ($refund_status == 'REFUND_SUCCESS') { |
|
||||
$status = RefundDict::SUCCESS; |
|
||||
} else { |
|
||||
$status = RefundDict::DEALING; |
|
||||
} |
|
||||
return [ |
|
||||
'status' => $status, |
|
||||
'refund_no' => $refund_no, |
|
||||
'out_trade_no' => $out_trade_no |
|
||||
]; |
|
||||
} else { |
|
||||
if (!empty($result['sub_code']) && $result['sub_code'] == 'ACQ.ACQ.SYSTEM_ERROR') { |
|
||||
throw new PayException($result['msg']); |
|
||||
} else { |
|
||||
return []; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取转账订单 |
|
||||
* @param string $transfer_no |
|
||||
* @return array |
|
||||
* @throws ContainerException |
|
||||
* @throws InvalidParamsException |
|
||||
* @throws ServiceNotFoundException |
|
||||
*/ |
|
||||
public function getTransfer(string $transfer_no, $out_transfer_no = '') |
|
||||
{ |
|
||||
$order = [ |
|
||||
'out_biz_no' => $transfer_no, |
|
||||
'_action' => 'transfer' |
|
||||
]; |
|
||||
$result = $this->returnFormat(Pay::alipay()->query($order)); |
|
||||
if (!empty($result['msg']) && $result['msg'] == 'Success') { |
|
||||
$status = $result['SUCCESS'] ?? ''; |
|
||||
$status_array = array( |
|
||||
'SUCCESS' => TransferDict::SUCCESS, |
|
||||
'WAIT_PAY' => TransferDict::WAIT, |
|
||||
'CLOSED' => TransferDict::FAIL, |
|
||||
'FAIL' => TransferDict::FAIL |
|
||||
); |
|
||||
return [ |
|
||||
'status' => $status_array[$status], |
|
||||
'transfer_no' => $transfer_no |
|
||||
]; |
|
||||
} else { |
|
||||
if (!empty($result['sub_code']) && $result['sub_code'] == 'ACQ.ACQ.SYSTEM_ERROR') { |
|
||||
throw new PayException($result['msg']); |
|
||||
} else { |
|
||||
return []; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public function fail() |
|
||||
{ |
|
||||
return 'fail'; |
|
||||
} |
|
||||
|
|
||||
public function returnUrl($params) |
|
||||
{ |
|
||||
return ['url' => $params->getHeader('Location')[0] ?? '']; |
|
||||
} |
|
||||
} |
|
||||
@ -1,203 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\pay; |
|
||||
|
|
||||
use core\loader\Storage; |
|
||||
use GuzzleHttp\Psr7\Response; |
|
||||
use Psr\Http\Message\MessageInterface; |
|
||||
use Yansongda\Supports\Collection; |
|
||||
|
|
||||
/** |
|
||||
* 文件管理驱动类 |
|
||||
* Class BasePay |
|
||||
*/ |
|
||||
abstract class BasePay extends Storage |
|
||||
{ |
|
||||
protected $config;//配置 |
|
||||
|
|
||||
/** |
|
||||
* 初始化 |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 网页支付 |
|
||||
* @param array $params |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function web(array $params); |
|
||||
|
|
||||
/** |
|
||||
* 手机网站支付 |
|
||||
* @param array $params |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function wap(array $params); |
|
||||
|
|
||||
/** |
|
||||
* app支付 |
|
||||
* @param array $params |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function app(array $params); |
|
||||
|
|
||||
/** |
|
||||
* 小程序支付 |
|
||||
* @param array $params |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function mini(array $params); |
|
||||
|
|
||||
/** |
|
||||
* 付款码支付 |
|
||||
* @param array $params |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function pos(array $params); |
|
||||
|
|
||||
/** |
|
||||
* 扫码支付 |
|
||||
* @param array $params |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function scan(array $params); |
|
||||
|
|
||||
/** |
|
||||
* 转账 |
|
||||
* @param array $params |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function transfer(array $params); |
|
||||
|
|
||||
/** |
|
||||
* 公众号支付 |
|
||||
* @param array $params |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function mp(array $params); |
|
||||
|
|
||||
/** |
|
||||
* 支付关闭 |
|
||||
* @param string $out_trade_no |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function close(string $out_trade_no); |
|
||||
|
|
||||
/** |
|
||||
* 退款 |
|
||||
* @param array $params |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function refund(array $params); |
|
||||
|
|
||||
/** |
|
||||
* 支付通知 |
|
||||
* @param string $action |
|
||||
* @param callable $callback |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function notify(string $action, callable $callback); |
|
||||
|
|
||||
/** |
|
||||
* 查询支付订单 |
|
||||
* @param array $params |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function getOrder(array $params); |
|
||||
|
|
||||
/** |
|
||||
* 查询退款订单 |
|
||||
* @param string $out_trade_no |
|
||||
* @param string|null $refund_no |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function getRefund(string $out_trade_no, ?string $refund_no); |
|
||||
|
|
||||
/** |
|
||||
* 查询转账订单 |
|
||||
* @param string $transfer_no |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function getTransfer(string $transfer_no, $out_transfer_no = ''); |
|
||||
|
|
||||
/** |
|
||||
* 初始化 |
|
||||
* @param array $config |
|
||||
* @param string $type |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
protected function payConfig(array $config, string $type) |
|
||||
{ |
|
||||
return array_merge( |
|
||||
[ |
|
||||
'logger' => [ |
|
||||
'enable' => true, |
|
||||
'file' => root_path('runtime') . 'paylog' . DIRECTORY_SEPARATOR . date('Ym') . DIRECTORY_SEPARATOR . date('d') . '.log', |
|
||||
'level' => env('app_debug') ? 'debug' : 'info', // 建议生产环境等级调整为 info,开发环境为 debug |
|
||||
'type' => 'single', // optional, 可选 daily. |
|
||||
'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天 |
|
||||
], |
|
||||
'http' => [ // optional |
|
||||
'timeout' => 5.0, |
|
||||
] |
|
||||
], |
|
||||
[ |
|
||||
$type => [ |
|
||||
'default' => $config |
|
||||
] |
|
||||
], |
|
||||
['_force' => true] |
|
||||
); |
|
||||
} |
|
||||
|
|
||||
public function returnFormat($param) |
|
||||
{ |
|
||||
if ($param instanceof MessageInterface || $param instanceof Response) { |
|
||||
$return_value = $param->getBody()->getContents(); |
|
||||
} else if ($param instanceof Collection) { |
|
||||
$return_value = $param->toArray(); |
|
||||
} else { |
|
||||
$return_value = $param; |
|
||||
} |
|
||||
return $return_value; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 解析退款返回数据并解析 |
|
||||
* @param $our_trade_no |
|
||||
* @param $refund_no |
|
||||
* @param $status |
|
||||
* @param int $success_time |
|
||||
* @param string $reason |
|
||||
* @return array |
|
||||
*/ |
|
||||
public function getRefundData($our_trade_no, $refund_no, $status, $success_time = 0, $reason = '') |
|
||||
{ |
|
||||
return [ |
|
||||
'our_trade_no' => $our_trade_no, |
|
||||
'refund_no' => $refund_no, |
|
||||
'status' => $status, |
|
||||
'success_time' => $success_time, |
|
||||
'reason' => $reason |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取转账数据并解析 |
|
||||
* @param $transfer_no |
|
||||
* @param $status |
|
||||
* @param $reason |
|
||||
* @return void |
|
||||
*/ |
|
||||
public function getTransferData($transfer_no, $status, $reason) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -1,42 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\pay; |
|
||||
|
|
||||
use core\loader\Loader; |
|
||||
|
|
||||
/** |
|
||||
* @see PayLoader |
|
||||
* @package think\facade |
|
||||
* @mixin Wechatpay |
|
||||
* @method string|null upload(string $dir) 附件上传 |
|
||||
* @method array fetch(string $url, ?string $key) 抓取远程附件 |
|
||||
* @method mixed delete(string $file_name) 附件删除 |
|
||||
*/ |
|
||||
class PayLoader extends Loader |
|
||||
{ |
|
||||
/** |
|
||||
* 空间名 |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $namespace = '\\core\\pay\\'; |
|
||||
|
|
||||
protected $config_name = 'pay'; |
|
||||
|
|
||||
/** |
|
||||
* 默认驱动 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
protected function getDefault() |
|
||||
{ |
|
||||
return config('pay.default'); |
|
||||
} |
|
||||
} |
|
||||
@ -1,538 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\pay; |
|
||||
|
|
||||
use app\dict\common\ChannelDict; |
|
||||
use app\dict\pay\OnlinePayDict; |
|
||||
use app\dict\pay\RefundDict; |
|
||||
use app\dict\pay\TransferDict; |
|
||||
use core\exception\PayException; |
|
||||
use Psr\Http\Message\MessageInterface; |
|
||||
use Psr\Http\Message\ResponseInterface; |
|
||||
use think\Response; |
|
||||
use Throwable; |
|
||||
use Yansongda\Artful\Exception\InvalidResponseException; |
|
||||
use Yansongda\Pay\Exception\ContainerException; |
|
||||
use Yansongda\Pay\Exception\InvalidParamsException; |
|
||||
use Yansongda\Pay\Exception\ServiceNotFoundException; |
|
||||
use Yansongda\Pay\Pay; |
|
||||
use Yansongda\Supports\Collection; |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 微信支付管理驱动类 todo 注意:暂时不考虑合单类业务 |
|
||||
* Class FileDriver |
|
||||
* @package core\file |
|
||||
*/ |
|
||||
class Wechatpay extends BasePay |
|
||||
{ |
|
||||
|
|
||||
/** |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
* @throws ContainerException |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
$this->config = $config; |
|
||||
$config['mch_secret_cert'] = url_to_path($config['mch_secret_cert'] ?? ''); |
|
||||
$config['mch_public_cert_path'] = url_to_path($config['mch_public_cert_path'] ?? ''); |
|
||||
// 选填-默认为正常模式。可选为: MODE_NORMAL, MODE_SERVICE |
|
||||
$config['mode'] = Pay::MODE_NORMAL; |
|
||||
if (!empty($config['wechat_public_cert_path']) && !empty($config['wechat_public_cert_id'])) { |
|
||||
$config['wechat_public_cert_path'] = [ |
|
||||
$config['wechat_public_cert_id'] => url_to_path($config['wechat_public_cert_path']) |
|
||||
]; |
|
||||
} else { |
|
||||
unset($config['wechat_public_cert_path']); |
|
||||
unset($config['wechat_public_cert_id']); |
|
||||
} |
|
||||
Pay::config($this->payConfig($config, 'wechat')); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 公众号支付 |
|
||||
* @param array $params |
|
||||
* @return mixed|Collection |
|
||||
*/ |
|
||||
public function mp(array $params) |
|
||||
{ |
|
||||
try { |
|
||||
$result = $this->returnFormat(Pay::wechat()->mp([ |
|
||||
'out_trade_no' => $params['out_trade_no'], |
|
||||
'description' => $params['body'], |
|
||||
'amount' => [ |
|
||||
'total' => $params['money'], |
|
||||
], |
|
||||
'payer' => [ |
|
||||
'openid' => $params['openid'], |
|
||||
], |
|
||||
])); |
|
||||
$code = $result['code'] ?? 0; |
|
||||
if ($code == 0) return $result; |
|
||||
//支付错误抛出 |
|
||||
throw new PayException($result['message']); |
|
||||
} catch (\Exception $e) { |
|
||||
if ($e instanceof InvalidResponseException) { |
|
||||
throw new PayException($e->response->all()['message'] ?? ''); |
|
||||
} |
|
||||
throw new PayException($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 手机网页支付 |
|
||||
* @param array $params |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function wap(array $params) |
|
||||
{ |
|
||||
try { |
|
||||
$order = [ |
|
||||
'out_trade_no' => $params['out_trade_no'], |
|
||||
'description' => $params['body'], |
|
||||
'amount' => [ |
|
||||
'total' => $params['money'], |
|
||||
], |
|
||||
'scene_info' => [ |
|
||||
'payer_client_ip' => request()->ip(), |
|
||||
'h5_info' => [ |
|
||||
'type' => 'Wap', |
|
||||
] |
|
||||
], |
|
||||
]; |
|
||||
//这儿有些特殊, 默认情况下,H5 支付所使用的 appid 是微信公众号的 appid,即配置文件中的 mp_app_id 参数,如果想使用关联的小程序的 appid,则只需要在调用参数中增加 ['_type' => 'mini'] 即可 |
|
||||
if (!empty($order['type'])) { |
|
||||
$order['_type'] = 'mini'; // 注意这一行 |
|
||||
} |
|
||||
return $this->returnFormat(Pay::wechat()->h5($order)); |
|
||||
} catch (\Exception $e) { |
|
||||
if ($e instanceof InvalidResponseException) { |
|
||||
throw new PayException($e->response->all()['message'] ?? ''); |
|
||||
} |
|
||||
throw new PayException($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public function web(array $params) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* app支付 |
|
||||
* @param array $params |
|
||||
* @return mixed|ResponseInterface |
|
||||
*/ |
|
||||
public function app(array $params) |
|
||||
{ |
|
||||
try { |
|
||||
return $this->returnFormat(Pay::wechat()->app([ |
|
||||
'out_trade_no' => $params['out_trade_no'], |
|
||||
'description' => $params['body'], |
|
||||
'amount' => [ |
|
||||
'total' => $params['money'], |
|
||||
], |
|
||||
])); |
|
||||
} catch (\Exception $e) { |
|
||||
if ($e instanceof InvalidResponseException) { |
|
||||
throw new PayException($e->response->all()['message'] ?? ''); |
|
||||
} |
|
||||
throw new PayException($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 小程序支付 |
|
||||
* @param array $params |
|
||||
* @return mixed|ResponseInterface |
|
||||
*/ |
|
||||
public function mini(array $params) |
|
||||
{ |
|
||||
try { |
|
||||
return $this->returnFormat(Pay::wechat()->mini([ |
|
||||
'out_trade_no' => $params['out_trade_no'], |
|
||||
'description' => $params['body'], |
|
||||
'amount' => [ |
|
||||
'total' => $params['money'], |
|
||||
'currency' => 'CNY',//一般是人民币 |
|
||||
], |
|
||||
'payer' => [ |
|
||||
'openid' => $params['openid'], |
|
||||
] |
|
||||
])); |
|
||||
} catch (\Exception $e) { |
|
||||
if ($e instanceof InvalidResponseException) { |
|
||||
throw new PayException($e->response->all()['message'] ?? ''); |
|
||||
} |
|
||||
throw new PayException($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 付款码支付 |
|
||||
* @param array $params |
|
||||
* @return mixed|Collection |
|
||||
*/ |
|
||||
public function pos(array $params) |
|
||||
{ |
|
||||
try { |
|
||||
$order = [ |
|
||||
'out_trade_no' => $params['out_trade_no'], |
|
||||
'body' => $params['body'], |
|
||||
'total_fee' => $params['money'], |
|
||||
'spbill_create_ip' => request()->ip(), |
|
||||
'auth_code' => $params["auth_code"], |
|
||||
]; |
|
||||
$result = Pay::wechat()->pos($order); |
|
||||
return $this->returnFormat($result); |
|
||||
} catch (\Exception $e) { |
|
||||
if ($e instanceof InvalidResponseException) { |
|
||||
throw new PayException($e->response->all()['message'] ?? ''); |
|
||||
} |
|
||||
throw new PayException($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 扫码支付 |
|
||||
* @param array $params |
|
||||
* @return mixed|Collection |
|
||||
*/ |
|
||||
public function scan(array $params) |
|
||||
{ |
|
||||
try { |
|
||||
return $this->returnFormat(Pay::wechat()->scan([ |
|
||||
'out_trade_no' => $params['out_trade_no'], |
|
||||
'description' => $params['body'], |
|
||||
'amount' => [ |
|
||||
'total' => $params['money'], |
|
||||
], |
|
||||
])); |
|
||||
} catch (\Exception $e) { |
|
||||
if ($e instanceof InvalidResponseException) { |
|
||||
throw new PayException($e->response->all()['message'] ?? ''); |
|
||||
} |
|
||||
throw new PayException($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 转账(微信的转账是很多笔的) |
|
||||
* @param array $params |
|
||||
* @return array |
|
||||
*/ |
|
||||
public function transfer(array $params) |
|
||||
{ |
|
||||
|
|
||||
$to_data = $params['to_no'];//收款人数据 |
|
||||
$channel = $to_data['channel'] ?? '';//渠道 |
|
||||
$open_id = $to_data['open_id'] ?? '';//openid |
|
||||
|
|
||||
if(empty($this->config['mch_id']) || empty($this->config['mch_secret_key']) || empty($this->config['mch_secret_cert']) || empty($this->config['mch_public_cert_path'])){ |
|
||||
throw new PayException('WECHAT_TRANSFER_CONFIG_NOT_EXIST'); |
|
||||
} |
|
||||
//这儿的批次信息可能是这儿生成的,但依然需要记录 |
|
||||
$order = [ |
|
||||
'out_batch_no' => ($to_data['out_batch_no'] ?? '') . '',// |
|
||||
'batch_name' => $params['remark'] ?? '', |
|
||||
'batch_remark' => $params['remark'] ?? '', |
|
||||
]; |
|
||||
if($channel == ChannelDict::WEAPP){ |
|
||||
$order['_type'] = 'mini'; |
|
||||
} |
|
||||
$transfer_list = $params['transfer_list']; |
|
||||
//单笔转账 |
|
||||
if (empty($transfer_list)) { |
|
||||
$transfer_list = [ |
|
||||
[ |
|
||||
'transfer_no' => $params['transfer_no'], |
|
||||
'money' => (int)$params['money'], |
|
||||
'remark' => $params['remark'], |
|
||||
'openid' => $open_id |
|
||||
] |
|
||||
]; |
|
||||
} |
|
||||
$total_amount = 0; |
|
||||
$total_num = 0; |
|
||||
|
|
||||
foreach ($transfer_list as $k => $v) { |
|
||||
$item_transfer = [ |
|
||||
'out_detail_no' => $params['transfer_no'], |
|
||||
'transfer_amount' => (int)$v['money'], |
|
||||
'transfer_remark' => $v['remark'], |
|
||||
'openid' => $v['openid'], |
|
||||
]; |
|
||||
$total_amount += (int)$v['money']; |
|
||||
$total_num++; |
|
||||
if (!empty($v['user_name'])) { |
|
||||
$item_transfer['user_name'] = $v['user_name'];// 明文传参即可,sdk 会自动加密 |
|
||||
} |
|
||||
$order['transfer_detail_list'][] = $item_transfer; |
|
||||
} |
|
||||
$order['total_amount'] = $total_amount; |
|
||||
$order['total_num'] = $total_num; |
|
||||
$tran_status_list = [ |
|
||||
'PROCESSING' => TransferDict::DEALING, |
|
||||
'ACCEPTED' => TransferDict::DEALING, |
|
||||
'CLOSED' => TransferDict::FAIL, |
|
||||
'FINISHED' => TransferDict::SUCCESS, |
|
||||
]; |
|
||||
try { |
|
||||
$result = $this->returnFormat(Pay::wechat()->transfer($order)); |
|
||||
if (!empty($result['code'])) { |
|
||||
// if($result['code'] == 'PARAM_ERROR'){ |
|
||||
// throw new PayException(); |
|
||||
// }else if($result['code'] == 'INVALID_REQUEST'){ |
|
||||
// throw new PayException(); |
|
||||
// } |
|
||||
if ($result['code'] == 'INVALID_REQUEST') { |
|
||||
throw new PayException(700010); |
|
||||
} |
|
||||
throw new PayException($result['message']); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
return ['batch_id' => $result['batch_id'], 'out_batch_no' => $result['out_batch_no'], 'status' => $tran_status_list[$result['batch_status']]]; |
|
||||
} catch (\Exception $e) { |
|
||||
if($e->getCode() == 9402){ |
|
||||
return ['batch_id' => '', 'out_batch_no' => $order['out_batch_no'], 'status' => TransferDict::DEALING]; |
|
||||
} |
|
||||
if ($e instanceof InvalidResponseException) { |
|
||||
throw new PayException($e->response->all()['message'] ?? ''); |
|
||||
} |
|
||||
throw new PayException($e->getMessage()); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 支付关闭 |
|
||||
* @param string $out_trade_no |
|
||||
* @return void |
|
||||
* @throws ContainerException |
|
||||
* @throws InvalidParamsException |
|
||||
* @throws ServiceNotFoundException |
|
||||
*/ |
|
||||
public function close(string $out_trade_no) |
|
||||
{ |
|
||||
try { |
|
||||
$result = Pay::wechat()->close([ |
|
||||
'out_trade_no' => $out_trade_no, |
|
||||
]); |
|
||||
return $this->returnFormat($result); |
|
||||
}catch(Throwable $e){ |
|
||||
return false; |
|
||||
} |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 退款 |
|
||||
* @param array $params |
|
||||
* @return array |
|
||||
* @throws ContainerException |
|
||||
* @throws InvalidParamsException |
|
||||
* @throws ServiceNotFoundException |
|
||||
*/ |
|
||||
public function refund(array $params) |
|
||||
{ |
|
||||
$out_trade_no = $params['out_trade_no']; |
|
||||
$money = $params['money']; |
|
||||
$total = $params['total']; |
|
||||
$refund_no = $params['refund_no']; |
|
||||
$result = Pay::wechat()->refund([ |
|
||||
'out_trade_no' => $out_trade_no, |
|
||||
'out_refund_no' => $refund_no, |
|
||||
'amount' => [ |
|
||||
'refund' => $money, |
|
||||
'total' => $total, |
|
||||
'currency' => 'CNY', |
|
||||
], |
|
||||
]); |
|
||||
$result = $this->returnFormat($result); |
|
||||
|
|
||||
$refund_status_array = [ |
|
||||
'SUCCESS' => RefundDict::SUCCESS, |
|
||||
'CLOSED' => RefundDict::FAIL, |
|
||||
'PROCESSING' => RefundDict::DEALING, |
|
||||
'ABNORMAL' => RefundDict::FAIL, |
|
||||
]; |
|
||||
return [ |
|
||||
'status' => $refund_status_array[$result['status']], |
|
||||
'refund_no' => $refund_no, |
|
||||
'out_trade_no' => $out_trade_no, |
|
||||
'pay_refund_no' => $result['refund_id'] |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 异步回调 |
|
||||
* @param string $action |
|
||||
* @param callable $callback |
|
||||
* @return ResponseInterface|Response |
|
||||
*/ |
|
||||
public function notify(string $action, callable $callback) |
|
||||
{ |
|
||||
try { |
|
||||
$result = $this->returnFormat(Pay::wechat()->callback()); |
|
||||
if ($action == 'pay') {//支付 |
|
||||
if ($result['event_type'] == 'TRANSACTION.SUCCESS') { |
|
||||
$pay_trade_data = $result['resource']['ciphertext']; |
|
||||
|
|
||||
$temp_params = [ |
|
||||
'trade_no' => $pay_trade_data['transaction_id'], |
|
||||
'mch_id' => $pay_trade_data['mchid'], |
|
||||
'status' => OnlinePayDict::getWechatPayStatus($pay_trade_data['trade_state']) |
|
||||
]; |
|
||||
|
|
||||
$callback_result = $callback($pay_trade_data['out_trade_no'], $temp_params); |
|
||||
if (is_bool($callback_result) && $callback_result) { |
|
||||
return Pay::wechat()->success(); |
|
||||
} |
|
||||
} |
|
||||
} else if ($action == 'refund') {//退款 |
|
||||
if ($result['event_type'] == 'REFUND.SUCCESS') { |
|
||||
$refund_trade_data = $result['resource']['ciphertext']; |
|
||||
$refund_status_array = [ |
|
||||
'SUCCESS' => RefundDict::SUCCESS, |
|
||||
'CLOSED' => RefundDict::FAIL, |
|
||||
'PROCESSING' => RefundDict::DEALING, |
|
||||
'ABNORMAL' => RefundDict::FAIL, |
|
||||
]; |
|
||||
$temp_params = [ |
|
||||
'trade_no' => $refund_trade_data['transaction_id'], |
|
||||
'mch_id' => $refund_trade_data['mchid'], |
|
||||
'refund_no' => $refund_trade_data['out_refund_no'], |
|
||||
'status' => $refund_status_array[$refund_trade_data['refund_status']], |
|
||||
]; |
|
||||
|
|
||||
$callback_result = $callback($refund_trade_data['out_trade_no'], $temp_params); |
|
||||
if (is_bool($callback_result) && $callback_result) { |
|
||||
return Pay::wechat()->success(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
return $this->fail(); |
|
||||
|
|
||||
} catch ( Throwable $e ) { |
|
||||
// throw new PayException($e->getMessage()); |
|
||||
return $this->fail($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 查询普通支付订单 |
|
||||
* @param array $params |
|
||||
* @return array|MessageInterface|Collection|null |
|
||||
* @throws ContainerException |
|
||||
* @throws InvalidParamsException |
|
||||
* @throws ServiceNotFoundException |
|
||||
*/ |
|
||||
public function getOrder(array $params = []) |
|
||||
{ |
|
||||
|
|
||||
$out_trade_no = $params['out_trade_no']; |
|
||||
$transaction_id = $params['transaction_id'] ?? ''; |
|
||||
$order = [ |
|
||||
|
|
||||
]; |
|
||||
if (!empty($out_trade_no)) { |
|
||||
$order['out_trade_no'] = $out_trade_no; |
|
||||
} |
|
||||
if (!empty($transaction_id)) { |
|
||||
$order['transaction_id'] = $transaction_id; |
|
||||
} |
|
||||
$result = Pay::wechat()->query($order); |
|
||||
if (empty($result)) |
|
||||
return $result; |
|
||||
$result = $this->returnFormat($result); |
|
||||
return [ |
|
||||
'status' => OnlinePayDict::getWechatPayStatus($result['trade_state']), |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 查询退款单据 |
|
||||
* @param string|null $out_trade_no |
|
||||
* @param string|null $refund_no |
|
||||
* @return array|Collection|MessageInterface|null |
|
||||
* @throws ContainerException |
|
||||
* @throws InvalidParamsException |
|
||||
* @throws ServiceNotFoundException |
|
||||
*/ |
|
||||
public function getRefund(?string $out_trade_no, ?string $refund_no = '') |
|
||||
{ |
|
||||
$order = [ |
|
||||
'_action' => 'refund', |
|
||||
'transaction_id' => $out_trade_no, |
|
||||
'out_refund_no' => $refund_no, |
|
||||
'' |
|
||||
]; |
|
||||
$result = Pay::wechat()->query($order); |
|
||||
if (empty($result)) |
|
||||
return $result; |
|
||||
$result = $this->returnFormat($result); |
|
||||
$refund_status_array = [ |
|
||||
'SUCCESS' => RefundDict::SUCCESS, |
|
||||
'CLOSED' => RefundDict::FAIL, |
|
||||
'PROCESSING' => RefundDict::DEALING, |
|
||||
'ABNORMAL' => RefundDict::FAIL, |
|
||||
]; |
|
||||
return [ |
|
||||
'status' => $refund_status_array[$result['status']], |
|
||||
'refund_no' => $refund_no, |
|
||||
'out_trade_no' => $out_trade_no |
|
||||
]; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取转账订单(todo 切勿调用) |
|
||||
* @param string $transfer_no |
|
||||
* @return array |
|
||||
* @throws ContainerException |
|
||||
* @throws InvalidParamsException |
|
||||
*/ |
|
||||
public function getTransfer(string $transfer_no, $out_batch_no = '') |
|
||||
{ |
|
||||
$order = [ |
|
||||
'out_batch_no' => $out_batch_no, |
|
||||
'out_detail_no' => $transfer_no, |
|
||||
'_action' => 'transfer', |
|
||||
]; |
|
||||
|
|
||||
try { |
|
||||
$result = Pay::wechat()->query($order); |
|
||||
$result = $this->returnFormat($result); |
|
||||
//微信转账状态 |
|
||||
$transfer_status_array = [ |
|
||||
'INIT' => TransferDict::DEALING,//初始态。 系统转账校验中 |
|
||||
'WAIT_PAY' => TransferDict::DEALING, |
|
||||
'PROCESSING' => TransferDict::DEALING, |
|
||||
'FAIL' => TransferDict::FAIL, |
|
||||
'SUCCESS' => TransferDict::SUCCESS, |
|
||||
]; |
|
||||
return [ |
|
||||
'status' => $transfer_status_array[$result['detail_status']], |
|
||||
'transfer_no' => $transfer_no |
|
||||
]; |
|
||||
}catch(Throwable $e){ |
|
||||
return [ |
|
||||
'status' => TransferDict::DEALING, |
|
||||
'transfer_no' => $transfer_no |
|
||||
]; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public function fail($message = '') |
|
||||
{ |
|
||||
$response = [ |
|
||||
'code' => 'FAIL', |
|
||||
'message' => $message ?: '失败', |
|
||||
]; |
|
||||
return response($response, 400, [], 'json'); |
|
||||
} |
|
||||
} |
|
||||
@ -1,41 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\poster; |
|
||||
|
|
||||
use core\loader\Storage; |
|
||||
|
|
||||
/** |
|
||||
* Class BasePoster |
|
||||
* @package |
|
||||
*/ |
|
||||
abstract class BasePoster extends Storage |
|
||||
{ |
|
||||
/** |
|
||||
* 初始化 |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 创建海报 |
|
||||
* @param array $poster |
|
||||
* @param string $dir |
|
||||
* @param string $file_path |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract public function createPoster(array $poster, string $dir, string $file_path); |
|
||||
|
|
||||
} |
|
||||
@ -1,205 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\poster; |
|
||||
|
|
||||
use Kkokk\Poster\Facades\Poster as PosterInstance; |
|
||||
|
|
||||
class Poster extends BasePoster |
|
||||
{ |
|
||||
|
|
||||
/** |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
parent::initialize($config); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 创建海报 |
|
||||
* @param array $poster_data |
|
||||
* @param string $dir |
|
||||
* @param string $file_path |
|
||||
* @return mixed|string |
|
||||
* @throws \Exception |
|
||||
*/ |
|
||||
public function createPoster(array $poster_data, string $dir, string $file_path) |
|
||||
{ |
|
||||
$bg_type = $poster_data[ 'global' ][ 'bgType' ]; |
|
||||
$instance = PosterInstance::extension('gd')->config([ 'path' => realpath($dir) . DIRECTORY_SEPARATOR . $file_path ]); |
|
||||
$bg_width = $poster_data[ 'global' ][ 'width' ]; |
|
||||
$bg_height = $poster_data[ 'global' ][ 'height' ]; |
|
||||
if ($bg_type == 'url' && !empty($poster_data[ 'global' ][ 'bgUrl' ]) && is_file($poster_data[ 'global' ][ 'bgUrl' ])) { |
|
||||
$im = $instance->buildIm($bg_width, $bg_height)->buildImage([ |
|
||||
'src' => $poster_data[ 'global' ][ 'bgUrl' ], |
|
||||
// 'angle' => 80 |
|
||||
], 0, 0, 0, 0, $bg_width, $bg_height); |
|
||||
} else { |
|
||||
$im = $instance->buildIm($bg_width, $bg_height, $this->getRgbColor($poster_data[ 'global' ][ 'bgColor' ])); |
|
||||
} |
|
||||
$align_array = [ |
|
||||
'center', 'left', 'right', 'top', 'bottom' |
|
||||
]; |
|
||||
foreach ($poster_data[ 'value' ] as $k => $v) { |
|
||||
$type = $v[ 'type' ]; |
|
||||
switch ($type) { |
|
||||
case 'text': |
|
||||
$font_size = ceil($v[ 'fontSize' ]); |
|
||||
$default_font = 'static' . DIRECTORY_SEPARATOR . 'font' . DIRECTORY_SEPARATOR . 'SourceHanSansCN-Regular.ttf'; |
|
||||
$font = $v[ 'fontFamily' ] ? : $default_font; |
|
||||
$content_list = $this->getText($v[ 'value' ], $font_size, $font, $v[ 'space' ] ?? 0, $v[ 'width' ], $v[ 'height' ], $v[ 'lineHeight' ] + $font_size); |
|
||||
$base_y = $this->getX($v[ 'y' ]); |
|
||||
if (is_array($base_y)) { |
|
||||
$diff_height = count($content_list) * ( $v[ 'lineHeight' ] + $font_size ); |
|
||||
$again_y = $base_y[ 0 ]; |
|
||||
if ($again_y == 'center') { |
|
||||
$base_y_num = ( $bg_height - $diff_height ) > 0 ? ( $bg_height - $diff_height ) / 2 : 0; |
|
||||
} else if ($again_y == 'top') { |
|
||||
$base_y_num = 0; |
|
||||
} else { |
|
||||
$base_y_num = $bg_height - $v[ 'height' ]; |
|
||||
} |
|
||||
|
|
||||
} else { |
|
||||
$base_y_num = $base_y; |
|
||||
} |
|
||||
// if(in_array($base_y, $align_array)){ |
|
||||
// $diff_height = count($content_list)*($v[ 'lineHeight' ]+$font_size); |
|
||||
// $base_y_num = ($bg_height-$diff_height) > 0 ? ($bg_height-$diff_height)/2 : 0; |
|
||||
// }else{ |
|
||||
// $base_y_num = $base_y[0]; |
|
||||
// } |
|
||||
foreach ($content_list as $ck => $content) { |
|
||||
if ($ck == 0) { |
|
||||
if ($v[ 'lineHeight' ] > 0) { |
|
||||
$item_line = $v[ 'lineHeight' ] / 2; |
|
||||
} else { |
|
||||
$item_line = 0; |
|
||||
} |
|
||||
} else { |
|
||||
$item_line = $v[ 'lineHeight' ] + $font_size; |
|
||||
} |
|
||||
$base_y_num += $item_line; |
|
||||
//计算文本框宽度 |
|
||||
$im = $im->buildText($content, $this->getX($v[ 'x' ]), $base_y_num, $font_size, $this->getRgbColor($v[ 'fontColor' ]), $v[ 'width' ], $font, $v[ 'weight' ] ? 10 : null); # 合成文字 |
|
||||
} |
|
||||
break; |
|
||||
case 'image': |
|
||||
if (is_file($v[ 'value' ])) { |
|
||||
$im = $im->buildImage($v[ 'value' ], $this->getX($v[ 'x' ]), $this->getY($v[ 'y' ]), 0, 0, $v[ 'width' ], $v[ 'height' ], false, $v[ 'shape' ] ?? 'normal'); # 合成图片 |
|
||||
} |
|
||||
break; |
|
||||
case 'draw': |
|
||||
if (!empty($v[ 'draw_type' ]) && $v[ 'draw_type' ] == 'Polygon') { |
|
||||
$points = $v[ 'points' ]; |
|
||||
$im = $im->buildLine($points[ 0 ][ 0 ], $points[ 0 ][ 1 ], $points[ 2 ][ 0 ], $points[ 2 ][ 1 ], $this->getRgbColor($v[ 'bgColor' ]), 'filled_rectangle'); |
|
||||
} |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
$path = $im->getPoster(); |
|
||||
|
|
||||
return str_replace(DIRECTORY_SEPARATOR, '/', str_replace(realpath(''), '', $path[ 'url' ])); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public function getX($dst_x) |
|
||||
{ |
|
||||
if (is_int($dst_x)) { |
|
||||
return $dst_x; |
|
||||
} else { |
|
||||
return [ $dst_x, 0 ]; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public function getY($dst_y) |
|
||||
{ |
|
||||
if (is_int($dst_y)) { |
|
||||
return $dst_y; |
|
||||
} else { |
|
||||
return [ $dst_y, 0 ]; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public function getRgbColor($color) |
|
||||
{ |
|
||||
$color = $color ? : '#FFFFFF'; |
|
||||
if (!str_contains($color, '#')) { |
|
||||
$color = str_replace('rgba(', '', $color); |
|
||||
$color = str_replace(')', '', $color); |
|
||||
list($r, $g, $b) = explode(',', $color); |
|
||||
list($r, $g, $b) = array_map(function($v) { return (int) $v; }, [ $r, $g, $b ]); |
|
||||
} else { |
|
||||
list($r, $g, $b) = sscanf($color, "#%02x%02x%02x"); |
|
||||
} |
|
||||
return [ $r, $g, $b, 1 ]; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取高度限制过后的文本 |
|
||||
* @param $content |
|
||||
* @param $fontSize |
|
||||
* @param $font |
|
||||
* @param $space |
|
||||
* @param $max_ws |
|
||||
* @param $max_hs |
|
||||
* @param $line_height |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function getText($content, $fontSize, $font, $space, $max_ws, $max_hs, $line_height) |
|
||||
{ |
|
||||
$calcSpace = $space > $fontSize ? ( $space - $fontSize ) : 0; // 获取间距计算值 |
|
||||
|
|
||||
$fontSize = ( $fontSize * 3 ) / 4; // px 转化为 pt |
|
||||
|
|
||||
mb_internal_encoding('UTF-8'); // 设置编码 |
|
||||
// 这几个变量分别是 字体大小, 角度, 字体名称, 字符串, 预设宽度 |
|
||||
$contents = ''; |
|
||||
$contentsArr = []; |
|
||||
$letter = []; |
|
||||
$line = 1; |
|
||||
$calcSpaceRes = 0; |
|
||||
// 将字符串拆分成一个个单字 保存到数组 letter 中 |
|
||||
for ($i = 0; $i < mb_strlen($content); $i++) { |
|
||||
$letter[] = mb_substr($content, $i, 1); |
|
||||
} |
|
||||
$textWidthArr = []; |
|
||||
$contentStr = ''; |
|
||||
$line_num = 1; |
|
||||
$total_width = 0; |
|
||||
$content_list = []; |
|
||||
foreach ($letter as $l) { |
|
||||
$textStr = $contentStr . $l; |
|
||||
$fontBox = imagettfbbox($fontSize, 0, $font, $textStr); |
|
||||
$textWidth = abs($fontBox[ 2 ]) + $calcSpaceRes; |
|
||||
$textWidthArr[ $line ] = $textWidth; |
|
||||
// 判断拼接后的字符串是否超过预设的宽度 |
|
||||
if (( $textWidth > $max_ws ) && ( $contents !== '' )) { |
|
||||
$line_num++; |
|
||||
if (( $line_num * $line_height ) > $max_hs) { |
|
||||
break; |
|
||||
} |
|
||||
$contents .= "\n"; |
|
||||
$contentStr = ""; |
|
||||
$line++; |
|
||||
} |
|
||||
if (empty($content_list[ $line_num - 1 ])) $content_list[ $line_num - 1 ] = ''; |
|
||||
$content_list[ $line_num - 1 ] .= $l; |
|
||||
$contents .= $l; |
|
||||
$contentStr .= $l; |
|
||||
$line === 1 && $calcSpaceRes += $calcSpace; |
|
||||
$text_width = max(array_values($textWidthArr)); |
|
||||
} |
|
||||
return $content_list; |
|
||||
} |
|
||||
} |
|
||||
@ -1,42 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\poster; |
|
||||
|
|
||||
use core\loader\Loader; |
|
||||
|
|
||||
/** |
|
||||
* @see PosterLoader |
|
||||
* @package think\facade |
|
||||
* @mixin BasePoster |
|
||||
* @method string|null createPoster( array $poster, string $dir, string $file_path ) 创建海报 |
|
||||
*/ |
|
||||
class PosterLoader extends Loader |
|
||||
{ |
|
||||
|
|
||||
/** |
|
||||
* 空间名 |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $namespace = '\\core\\poster\\'; |
|
||||
|
|
||||
protected $config_name = 'poster'; |
|
||||
|
|
||||
/** |
|
||||
* 默认驱动 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
protected function getDefault() |
|
||||
{ |
|
||||
return config('poster.default'); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,39 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\printer; |
|
||||
|
|
||||
use core\loader\Storage; |
|
||||
|
|
||||
/** |
|
||||
* Class BasePrinter |
|
||||
* @package core\printer |
|
||||
*/ |
|
||||
abstract class BasePrinter extends Storage |
|
||||
{ |
|
||||
/** |
|
||||
* 初始化 |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 打印小票 |
|
||||
* @param array $data |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function printTicket(array $data); |
|
||||
|
|
||||
} |
|
||||
@ -1,37 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\printer; |
|
||||
|
|
||||
|
|
||||
class KdniaoPrinter extends BasePrinter |
|
||||
{ |
|
||||
|
|
||||
protected $config; |
|
||||
|
|
||||
/** |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
parent::initialize($config); |
|
||||
$this->config = $config; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 打印小票 |
|
||||
* @param array $data |
|
||||
* @return mixed|void |
|
||||
*/ |
|
||||
public function printTicket(array $data) |
|
||||
{ |
|
||||
} |
|
||||
} |
|
||||
@ -1,39 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\printer; |
|
||||
|
|
||||
use core\loader\Loader; |
|
||||
|
|
||||
/** |
|
||||
* Class PrinterLoader |
|
||||
* @package core\printer |
|
||||
*/ |
|
||||
class PrinterLoader extends Loader |
|
||||
{ |
|
||||
|
|
||||
/** |
|
||||
* 空间名 |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $namespace = '\\core\\printer\\'; |
|
||||
|
|
||||
protected $config_name = 'printer'; |
|
||||
|
|
||||
/** |
|
||||
* 默认驱动 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
protected function getDefault() |
|
||||
{ |
|
||||
return 'kdbird'; |
|
||||
} |
|
||||
} |
|
||||
@ -1,32 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\printer\sdk\yilianyun; |
|
||||
|
|
||||
class Autoloader{ |
|
||||
|
|
||||
public static function loadByNamespace($name) |
|
||||
{ |
|
||||
$class_path = str_replace('\\', DIRECTORY_SEPARATOR, $name); |
|
||||
if (strpos($name, 'App\\') === 0) { |
|
||||
$class_file = __DIR__ . substr($class_path, strlen('App')) . '.php'; |
|
||||
}elseif(empty($class_file) || !is_file($class_file)){ |
|
||||
$class_file = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $class_path . ".php"; |
|
||||
} |
|
||||
if (is_file($class_file)) { |
|
||||
require_once ($class_file); |
|
||||
if (class_exists($name, false)) { |
|
||||
return true; |
|
||||
} |
|
||||
} |
|
||||
return false; |
|
||||
|
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
spl_autoload_register('\core\printer\sdk\yilianyun\Autoloader::loadByNamespace'); |
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
@ -1,36 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\printer\sdk\yilianyun\api; |
|
||||
|
|
||||
class ExpressPrintService extends RpcService{ |
|
||||
|
|
||||
/** |
|
||||
*面单打印接口 |
|
||||
*不支持机型: k4-wh, k4-wa, m1 (k4系列机型不建议使用不干胶热敏纸) |
|
||||
* |
|
||||
* @param $machineCode |
|
||||
* @param $content |
|
||||
* @param $originId |
|
||||
* @param int $sandbox |
|
||||
* @return mixed |
|
||||
* @throws \Exception |
|
||||
*/ |
|
||||
public function index($machineCode, $content, $originId, $sandbox = 0) |
|
||||
{ |
|
||||
return $this->client->call('expressprint/index', array('machine_code' => $machineCode, 'content' => $content, 'origin_id' => $originId, 'sandbox' => $sandbox)); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 面单取消接口 |
|
||||
* |
|
||||
* @param $machineCode |
|
||||
* @param $content |
|
||||
* @return mixed |
|
||||
* @throws \Exception |
|
||||
*/ |
|
||||
public function cancel($machineCode, $content) |
|
||||
{ |
|
||||
return $this->client->call('expressprint/cancel', array('machine_code' => $machineCode, 'content' => $content)); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,22 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\printer\sdk\yilianyun\api; |
|
||||
|
|
||||
class OauthService extends RpcService{ |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 设置推送URL接口 |
|
||||
* |
|
||||
* @param $cmd string 推送队列键 |
|
||||
* @param $url string 推送地址 |
|
||||
* @param $status string 推送开关 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function setPushUrl($cmd, $url, $status = 'open') |
|
||||
{ |
|
||||
return $this->client->call('oauth/setpushurl', array('cmd' => $cmd, 'url' => $url, 'status' => $status)); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
@ -1,22 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\printer\sdk\yilianyun\api; |
|
||||
|
|
||||
class PicturePrintService extends RpcService{ |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 图形打印接口 |
|
||||
* 不支持机型: k4-wh, k4-wa, m1 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @param $pictureUrl string 图片链接地址 |
|
||||
* @param $originId string 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母 |
|
||||
* @param $idempotence int 幂等处理 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function index($machineCode, $pictureUrl, $originId, $idempotence = 0) |
|
||||
{ |
|
||||
return $this->client->call('pictureprint/index', array('machine_code' => $machineCode, 'picture_url' => $pictureUrl, 'origin_id' => $originId, $idempotence => $idempotence)); |
|
||||
} |
|
||||
} |
|
||||
@ -1,19 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\printer\sdk\yilianyun\api; |
|
||||
|
|
||||
class PrintMenuService extends RpcService{ |
|
||||
|
|
||||
/** |
|
||||
* 添加应用菜单接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @param $content string 菜单详情(json) |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function addPrintMenu($machineCode, $content) |
|
||||
{ |
|
||||
return $this->client->call('printmenu/addprintmenu', array('machine_code' => $machineCode, 'content' => $content)); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,20 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\printer\sdk\yilianyun\api; |
|
||||
|
|
||||
class PrintService extends RpcService{ |
|
||||
|
|
||||
/** |
|
||||
* 打印接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @param $content string 打印内容 |
|
||||
* @param $originId string 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母 |
|
||||
* @param $idempotence int 幂等处理 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function index($machineCode, $content, $originId, $idempotence = 0) |
|
||||
{ |
|
||||
return $this->client->call('print/index', array('machine_code' => $machineCode, 'content' => $content, 'origin_id' => $originId, 'idempotence' => $idempotence)); |
|
||||
} |
|
||||
} |
|
||||
@ -1,313 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\printer\sdk\yilianyun\api; |
|
||||
|
|
||||
class PrinterService extends RpcService{ |
|
||||
|
|
||||
/** |
|
||||
* 自有型应用授权终端 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @param $mSign string 机器密钥 |
|
||||
* @param string $printName 打印机昵称 |
|
||||
* @param string $phone gprs卡号 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function addPrinter($machineCode, $mSign, $printName = '', $phone = '') |
|
||||
{ |
|
||||
$params = array( |
|
||||
'machine_code' => $machineCode, |
|
||||
'msign' => $mSign, |
|
||||
); |
|
||||
if (!empty($phone)) { |
|
||||
$params['phone'] = $phone; |
|
||||
} |
|
||||
if (!empty($printName)) { |
|
||||
$params['print_name'] = $printName; |
|
||||
} |
|
||||
return $this->client->call('printer/addprinter', $params); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 设置内置语音接口 |
|
||||
* 注意: 仅支持K4-WA、K4-GAD、K4-WGEAD型号 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @param $content string 在线语音地址链接 or 自定义语音内容 |
|
||||
* @param bool $isFile true or false |
|
||||
* @param string $aid int 0~9 , 定义需设置的语音编号,若不提交,默认升序 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function setVoice($machineCode, $content, $isFile = false, $aid = '') |
|
||||
{ |
|
||||
$params = array( |
|
||||
'machine_code' => $machineCode, |
|
||||
'content' => $content, |
|
||||
'is_file' => $isFile, |
|
||||
); |
|
||||
if (!empty($aid)){ |
|
||||
$params ['aid'] = $aid; |
|
||||
} |
|
||||
return $this->client->call('printer/setvoice', $params); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 删除内置语音接口 |
|
||||
* 注意: 仅支持K4-WA、K4-GAD、K4-WGEAD型号 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @param $aid int 0 ~ 9 编号 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function deleteVoice($machineCode, $aid) |
|
||||
{ |
|
||||
return $this->client->call('printer/deletevoice', array('machine_code' => $machineCode, 'aid' => $aid)); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 删除终端授权接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function deletePrinter($machineCode) |
|
||||
{ |
|
||||
return $this->client->call('printer/deleteprinter', array('machine_code' => $machineCode)); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 关机重启接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @param $responseType string restart or shutdown |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function shutdownRestart($machineCode, $responseType) |
|
||||
{ |
|
||||
return $this->client->call('printer/shutdownrestart', array('machine_code' => $machineCode, 'response_type' => $responseType)); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 声音调节接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @param $voice string 音量 0 or 1 or 2 or 3 |
|
||||
* @param $responseType string buzzer (蜂鸣器) or horn (喇叭) |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function setsound($machineCode, $voice, $responseType) |
|
||||
{ |
|
||||
return $this->client->call('printer/setsound', array('machine_code' => $machineCode, 'voice' => $voice, 'response_type' => $responseType)); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 获取机型打印宽度接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function printInfo($machineCode) |
|
||||
{ |
|
||||
return $this->client->call('printer/printinfo', array('machine_code' => $machineCode)); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 获取机型软硬件版本接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function getVersion($machineCode) |
|
||||
{ |
|
||||
return $this->client->call('printer/getversion', array('machine_code' => $machineCode)); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 取消所有未打印订单接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function cancelAll($machineCode) |
|
||||
{ |
|
||||
return $this->client->call('printer/cancelall', array('machine_code' => $machineCode)); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 取消单条未打印订单接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @param $orderId string 未打印的易联云ID |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function cancelOne($machineCode, $orderId) |
|
||||
{ |
|
||||
return $this->client->call('printer/cancelone', array('machine_code' => $machineCode, 'order_id' => $orderId)); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 设置logo接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @param $imgUrl string logo链接地址 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function setIcon($machineCode, $imgUrl) |
|
||||
{ |
|
||||
return $this->client->call('printer/seticon', array('machine_code' => $machineCode, 'img_url' => $imgUrl)); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 取消logo接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function deleteIcon($machineCode) |
|
||||
{ |
|
||||
return $this->client->call('printer/deleteicon', array('machine_code' => $machineCode)); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 打印方式接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @param $responseType string btnopen or btnclose |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function btnPrint($machineCode, $responseType) |
|
||||
{ |
|
||||
return $this->client->call('printer/btnprint', array('machine_code' => $machineCode, 'response_type' => $responseType)); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 接单拒单设置接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @param $responseType string open or close |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function getOrder($machineCode, $responseType) |
|
||||
{ |
|
||||
return $this->client->call('printer/getorder', array('machine_code' => $machineCode, 'response_type' => $responseType)); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 获取订单状态接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @param $orderId string 易联云订单id |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function getOrderStatus($machineCode, $orderId) |
|
||||
{ |
|
||||
return $this->client->call('printer/getorderstatus', array('machine_code' => $machineCode, 'order_id' => $orderId)); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 获取订单列表接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @param $pageIndex int 第几页 |
|
||||
* @param $pageSize int 查询条数 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function getOrderPagingList($machineCode, $pageIndex = 1 , $pageSize = 10) |
|
||||
{ |
|
||||
return $this->client->call('printer/getorderpaginglist', array('machine_code' => $machineCode, 'page_index' => $pageIndex, 'page_size' => $pageSize)); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取终端状态接口 |
|
||||
* |
|
||||
* @param $machineCode string 机器码 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function getPrintStatus($machineCode) |
|
||||
{ |
|
||||
return $this->client->call('printer/getprintstatus', array('machine_code' => $machineCode)); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 订单重打(单订单) |
|
||||
* |
|
||||
* @param $machineCode |
|
||||
* @param $orderId |
|
||||
* @return mixed |
|
||||
* @throws \Exception |
|
||||
*/ |
|
||||
public function reprintOrder($machineCode, $orderId) |
|
||||
{ |
|
||||
return $this->client->call('printer/reprintorder', array('machine_code' => $machineCode, 'order_id' => $orderId)); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* K8 推送开关设置 |
|
||||
* |
|
||||
* @param $machineCode |
|
||||
* @param $status |
|
||||
* @param $mode |
|
||||
* @return mixed |
|
||||
* @throws \Exception |
|
||||
*/ |
|
||||
public function pushSwitch($machineCode, $status, $mode = 1) |
|
||||
{ |
|
||||
return $this->client->call('printer/pushswitch', array('machine_code' => $machineCode, 'status' => $status, $mode)); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* K8 关键词设置接口 |
|
||||
* |
|
||||
* @param $machineCode |
|
||||
* @param $keys |
|
||||
* @param $type |
|
||||
* @param $content |
|
||||
* @return mixed |
|
||||
* @throws \Exception |
|
||||
*/ |
|
||||
public function setKeyWords($machineCode, $keys, $type, $content) |
|
||||
{ |
|
||||
return $this->client->call('printer/setkeywords', array('machine_code' => $machineCode, 'keys' => $keys, 'type' => $type, 'content' => $content)); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* K8 高级设置接口 |
|
||||
* |
|
||||
* @param $machineCode |
|
||||
* @param null $usbPrintMode |
|
||||
* @param null $usbInputMode |
|
||||
* @param null $cameraDecodeTxMode |
|
||||
* @return mixed |
|
||||
* @throws \Exception |
|
||||
*/ |
|
||||
public function setting($machineCode, $usbPrintMode = null, $usbInputMode = null, $cameraDecodeTxMode = null) |
|
||||
{ |
|
||||
$params = array('machine_code' => $machineCode); |
|
||||
if (!is_null($usbPrintMode) && in_array($usbPrintMode, [0, 1])) { |
|
||||
$params['usb_print_mode'] = (int)$usbInputMode; |
|
||||
} |
|
||||
if (!is_null($usbInputMode) && in_array($usbInputMode, [0, 1])) { |
|
||||
$params['usb_input_mode'] = (int)$usbInputMode; |
|
||||
} |
|
||||
if (!is_null($cameraDecodeTxMode) && in_array($cameraDecodeTxMode, [0, 1])) { |
|
||||
$params['camera_decode_tx_mode'] = (int)$cameraDecodeTxMode; |
|
||||
} |
|
||||
return $this->client->call('printer/setting', $params); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,19 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\printer\sdk\yilianyun\api; |
|
||||
|
|
||||
|
|
||||
use core\printer\sdk\yilianyun\config\YlyConfig; |
|
||||
use core\printer\sdk\yilianyun\protocol\YlyRpcClient; |
|
||||
|
|
||||
class RpcService |
|
||||
{ |
|
||||
|
|
||||
protected $client; |
|
||||
|
|
||||
public function __construct($token, YlyConfig $config) |
|
||||
{ |
|
||||
$this->client = new YlyRpcClient($token, $config); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,68 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
|
|
||||
namespace core\printer\sdk\yilianyun\config; |
|
||||
|
|
||||
use InvalidArgumentException; |
|
||||
|
|
||||
class YlyConfig |
|
||||
{ |
|
||||
|
|
||||
private $clientId = ''; |
|
||||
private $clientSecret = ''; |
|
||||
private $requestUrl = "https://open-api.10ss.net"; |
|
||||
private $log; |
|
||||
|
|
||||
public function __construct($clientId, $clientSecret) |
|
||||
{ |
|
||||
|
|
||||
if ($clientId == null || $clientId == "") { |
|
||||
throw new InvalidArgumentException("clientId is required"); |
|
||||
} |
|
||||
|
|
||||
if ($clientSecret == null || $clientSecret == "") { |
|
||||
throw new InvalidArgumentException("clientSecret is required"); |
|
||||
} |
|
||||
|
|
||||
$this->clientId = $clientId; |
|
||||
$this->clientSecret = $clientSecret; |
|
||||
} |
|
||||
|
|
||||
public function getClientId() |
|
||||
{ |
|
||||
return $this->clientId; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public function getClientSecret() |
|
||||
{ |
|
||||
return $this->clientSecret; |
|
||||
} |
|
||||
|
|
||||
public function getRequestUrl() |
|
||||
{ |
|
||||
return $this->requestUrl; |
|
||||
} |
|
||||
|
|
||||
public function setRequestUrl($requestUrl) |
|
||||
{ |
|
||||
$this->requestUrl = $requestUrl; |
|
||||
} |
|
||||
|
|
||||
public function getLog() |
|
||||
{ |
|
||||
return $this->log; |
|
||||
} |
|
||||
|
|
||||
public function setLog($log) |
|
||||
{ |
|
||||
if (!method_exists($log, "info")) { |
|
||||
throw new InvalidArgumentException("logger need have method 'info(\$message)'"); |
|
||||
} |
|
||||
if (!method_exists($log, "error")) { |
|
||||
throw new InvalidArgumentException("logger need have method 'error(\$message)'"); |
|
||||
} |
|
||||
$this->log = $log; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,141 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
use core\printer\sdk\yilianyun\oauth\YlyOauthClient; |
|
||||
use core\printer\sdk\yilianyun\api\PrintService; |
|
||||
|
|
||||
|
|
||||
$client = new YlyOauthClient($config); |
|
||||
|
|
||||
$code = ''; //开放型应用商户授权码 获取请看 http://doc2.10ss.net/371769#Code_5 |
|
||||
if (empty($code)) { |
|
||||
echo 'The authorization code cannot be empty'; |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
try { |
|
||||
$token = $client->getToken($code); |
|
||||
} catch (Exception $e) { |
|
||||
echo $e->getMessage() . "\n"; |
|
||||
print_r(json_decode($e->getMessage(), true)); |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
$access_token = $token->access_token; //调用API凭证AccessToken |
|
||||
$refresh_token = $token->refresh_token; //刷新AccessToken凭证 失效时间35天 |
|
||||
$machine_code = $token->machine_code; //商户授权机器码 |
|
||||
$expires_in = $token->expires_in; //AccessToken失效时间30天 |
|
||||
$refresh_expires_in = $token->refresh_expires_in; //RefreshToken失效时间35天 |
|
||||
$origin_id = ''; //内部订单号(32位以内) |
|
||||
|
|
||||
|
|
||||
if (empty($machine_code)) { |
|
||||
echo 'The machine_code cannot be empty'; |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
if (empty($origin_id)) { |
|
||||
echo 'The origin_id cannot be empty'; |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
/**文本接口开始**/ |
|
||||
$print = new PrintService($access_token, $config); |
|
||||
//58mm排版 排版指令详情请看 http://doc2.10ss.net/332006 |
|
||||
$content = "<FS2><center>**#1 美团**</center></FS2>"; |
|
||||
$content .= str_repeat('.', 32); |
|
||||
$content .= "<FS2><center>--在线支付--</center></FS2>"; |
|
||||
$content .= "<FS><center>张周兄弟烧烤</center></FS>"; |
|
||||
$content .= "订单时间:" . date("Y-m-d H:i") . "\n"; |
|
||||
$content .= "订单编号:40807050607030\n"; |
|
||||
$content .= str_repeat('*', 14) . "商品" . str_repeat("*", 14); |
|
||||
$content .= "<table>"; |
|
||||
$content .= "<tr><td>烤土豆(超级辣)</td><td>x3</td><td>5.96</td></tr>"; |
|
||||
$content .= "<tr><td>烤豆干(超级辣)</td><td>x2</td><td>3.88</td></tr>"; |
|
||||
$content .= "<tr><td>烤鸡翅(超级辣)</td><td>x3</td><td>17.96</td></tr>"; |
|
||||
$content .= "<tr><td>烤排骨(香辣)</td><td>x3</td><td>12.44</td></tr>"; |
|
||||
$content .= "<tr><td>烤韭菜(超级辣)</td><td>x3</td><td>8.96</td></tr>"; |
|
||||
$content .= "</table>"; |
|
||||
$content .= str_repeat('.', 32); |
|
||||
$content .= "<QR>这是二维码内容</QR>"; |
|
||||
$content .= "小计:¥82\n"; |
|
||||
$content .= "折扣:¥4 \n"; |
|
||||
$content .= str_repeat('*', 32); |
|
||||
$content .= "订单总价:¥78 \n"; |
|
||||
$content .= "<FS2><center>**#1 完**</center></FS2>"; |
|
||||
|
|
||||
try { |
|
||||
var_dump($print->index($machine_code, $content, $origin_id)); |
|
||||
} catch (Exception $e) { |
|
||||
echo $e->getMessage(); |
|
||||
} |
|
||||
/**文本接口结束**/ |
|
||||
|
|
||||
|
|
||||
///**图形接口开始**/ |
|
||||
//$picturePrint = new PicturePrintService($access_token, $config); |
|
||||
//$content = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1497000905083&di=7c3cffef1dd40edffbd0a37c4eabb277&imgtype=0&src=http://img1.touxiang.cn/uploads/20131114/14-054929_462.jpg"; |
|
||||
//try{ |
|
||||
// var_dump($picturePrint->index($machine_code, $content, $origin_id)); |
|
||||
//}catch (Exception $e) { |
|
||||
// echo $e->getMessage(); |
|
||||
//} |
|
||||
///**图形接口结束**/ |
|
||||
|
|
||||
|
|
||||
///**面单接口开始**/ //打印机型必须为k5; |
|
||||
//$expressPrint = new ExpressPrintService($access_token, $config); |
|
||||
//$content = array( |
|
||||
// "OrderCode"=> "0126578665784971", |
|
||||
// "ShipperCode"=> "SF", //SF YZPY HTKY YD |
|
||||
// "PayType"=> 1, |
|
||||
// "ExpType"=> 1, |
|
||||
// "Cost"=>6.0, |
|
||||
// "OtherCost"=> 7.0, |
|
||||
// "CustomerName" => '1264546', |
|
||||
// "CustomerPwd" => '4545454', |
|
||||
// "MonthCode" => '', |
|
||||
// "Sender"=> array( |
|
||||
// "Company" => "5645645", |
|
||||
// "Name" => "Taylor", |
|
||||
// "Mobile" => "15018442396", |
|
||||
// "ProvinceName" => "上海", |
|
||||
// "CityName" => "上海", |
|
||||
// "PostCode" => '61000', |
|
||||
// "ExpAreaName" => "青浦区", |
|
||||
// "Address" => "明珠路73号" |
|
||||
// ), |
|
||||
// "Receiver"=> array( |
|
||||
// "Company"=> "789789", |
|
||||
// "Name"=> "Yann", |
|
||||
// "Mobile"=> "15018442396", |
|
||||
// "ProvinceName"=> "北京", |
|
||||
// "CityName"=> "北京", |
|
||||
// "PostCode" => '61000', |
|
||||
// "ExpAreaName"=> "朝阳区", |
|
||||
// "Address"=> "三里屯街道雅秀大厦" |
|
||||
// ), |
|
||||
// "Commodity" => array( |
|
||||
// array( |
|
||||
// "GoodsName"=> "鞋子", |
|
||||
// ) |
|
||||
// ), |
|
||||
// "AddService"=> array( |
|
||||
// array( |
|
||||
// "Name"=> "COD", |
|
||||
// "Value"=> "1020", |
|
||||
// "CustomerID" => "44564" |
|
||||
// ) |
|
||||
// ), |
|
||||
// "StartDate" => date("y-M-d H:i:s",time() + 7200), |
|
||||
// "Weight"=> 1.0, |
|
||||
// "Quantity"=> 1, |
|
||||
// "Volume"=> 0.0, |
|
||||
// "Remark"=> "小心轻放", |
|
||||
//); |
|
||||
// |
|
||||
//try{ |
|
||||
// var_dump($expressPrint->index($machine_code, $content, $origin_id)); |
|
||||
//}catch (Exception $e) { |
|
||||
// echo $e->getMessage(); |
|
||||
//} |
|
||||
///**面单接口结束**/ |
|
||||
@ -1,136 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
use core\printer\sdk\yilianyun\oauth\YlyOauthClient; |
|
||||
use core\printer\sdk\yilianyun\api\PrintService; |
|
||||
use core\printer\sdk\yilianyun\api\PicturePrintService; |
|
||||
use core\printer\sdk\yilianyun\api\ExpressPrintService; |
|
||||
|
|
||||
$client = new YlyOauthClient($config); |
|
||||
try { |
|
||||
// |
|
||||
$token = $client->getToken(); |
|
||||
} catch (Exception $e) { |
|
||||
echo $e->getMessage() . "\n"; |
|
||||
print_r(json_decode($e->getMessage(), true)); |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
$access_token = $token->access_token; //调用API凭证AccessToken 永久有效,请妥善保存. |
|
||||
$refresh_token = $token->refresh_token; //刷新AccessToken凭证 失效时间35天 |
|
||||
$expires_in = $token->expires_in; //自有型应用可忽略此回调参数, AccessToken失效时间30天 |
|
||||
$refresh_expires_in = $token->refresh_expires_in; //自有型应用可忽略此回调参数, RefreshToken失效时间35天 |
|
||||
$machine_code = ''; //机器码 |
|
||||
$origin_id = ''; //内部订单号(32位以内) |
|
||||
|
|
||||
if (empty($machine_code)) { |
|
||||
echo 'The machine_code cannot be empty'; |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
if (empty($origin_id)) { |
|
||||
echo 'The origin_id cannot be empty'; |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/**文本接口开始**/ |
|
||||
$print = new PrintService($access_token, $config); |
|
||||
//58mm排版 排版指令详情请看 http://doc2.10ss.net/332006 |
|
||||
$content = "<FS2><center>**#1 美团**</center></FS2>"; |
|
||||
$content .= str_repeat('.', 32); |
|
||||
$content .= "<FS2><center>--在线支付--</center></FS2>"; |
|
||||
$content .= "<FS><center>张周兄弟烧烤</center></FS>"; |
|
||||
$content .= "订单时间:" . date("Y-m-d H:i") . "\n"; |
|
||||
$content .= "订单编号:40807050607030\n"; |
|
||||
$content .= str_repeat('*', 14) . "商品" . str_repeat("*", 14); |
|
||||
$content .= "<table>"; |
|
||||
$content .= "<tr><td>烤土豆(超级辣)</td><td>x3</td><td>5.96</td></tr>"; |
|
||||
$content .= "<tr><td>烤豆干(超级辣)</td><td>x2</td><td>3.88</td></tr>"; |
|
||||
$content .= "<tr><td>烤鸡翅(超级辣)</td><td>x3</td><td>17.96</td></tr>"; |
|
||||
$content .= "<tr><td>烤排骨(香辣)</td><td>x3</td><td>12.44</td></tr>"; |
|
||||
$content .= "<tr><td>烤韭菜(超级辣)</td><td>x3</td><td>8.96</td></tr>"; |
|
||||
$content .= "</table>"; |
|
||||
$content .= str_repeat('.', 32); |
|
||||
$content .= "<QR>这是二维码内容</QR>"; |
|
||||
$content .= "小计:¥82\n"; |
|
||||
$content .= "折扣:¥4 \n"; |
|
||||
$content .= str_repeat('*', 32); |
|
||||
$content .= "订单总价:¥78 \n"; |
|
||||
$content .= "<FS2><center>**#1 完**</center></FS2>"; |
|
||||
|
|
||||
try { |
|
||||
var_dump($print->index($machine_code, $content, $origin_id)); |
|
||||
} catch (Exception $e) { |
|
||||
echo $e->getMessage(); |
|
||||
} |
|
||||
/**文本接口结束**/ |
|
||||
|
|
||||
|
|
||||
///**图形接口开始**/ |
|
||||
//$picturePrint = new PicturePrintService($access_token, $config); |
|
||||
//$content = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1497000905083&di=7c3cffef1dd40edffbd0a37c4eabb277&imgtype=0&src=http://img1.touxiang.cn/uploads/20131114/14-054929_462.jpg"; |
|
||||
//try{ |
|
||||
// var_dump($picturePrint->index($machine_code, $content, $origin_id)); |
|
||||
//}catch (Exception $e) { |
|
||||
// echo $e->getMessage(); |
|
||||
//} |
|
||||
///**图形接口结束**/ |
|
||||
|
|
||||
|
|
||||
///**面单接口开始**/ //打印机型必须为k5; |
|
||||
//$expressPrint = new ExpressPrintService($access_token, $config); |
|
||||
//$content = array( |
|
||||
// "OrderCode"=> "0126578665784971", |
|
||||
// "ShipperCode"=> "SF", //SF YZPY HTKY YD |
|
||||
// "PayType"=> 1, |
|
||||
// "ExpType"=> 1, |
|
||||
// "Cost"=>6.0, |
|
||||
// "OtherCost"=> 7.0, |
|
||||
// "CustomerName" => '1264546', |
|
||||
// "CustomerPwd" => '4545454', |
|
||||
// "MonthCode" => '', |
|
||||
// "Sender"=> array( |
|
||||
// "Company" => "5645645", |
|
||||
// "Name" => "Taylor", |
|
||||
// "Mobile" => "15018442396", |
|
||||
// "ProvinceName" => "上海", |
|
||||
// "CityName" => "上海", |
|
||||
// "PostCode" => '61000', |
|
||||
// "ExpAreaName" => "青浦区", |
|
||||
// "Address" => "明珠路73号" |
|
||||
// ), |
|
||||
// "Receiver"=> array( |
|
||||
// "Company"=> "789789", |
|
||||
// "Name"=> "Yann", |
|
||||
// "Mobile"=> "15018442396", |
|
||||
// "ProvinceName"=> "北京", |
|
||||
// "CityName"=> "北京", |
|
||||
// "PostCode" => '61000', |
|
||||
// "ExpAreaName"=> "朝阳区", |
|
||||
// "Address"=> "三里屯街道雅秀大厦" |
|
||||
// ), |
|
||||
// "Commodity" => array( |
|
||||
// array( |
|
||||
// "GoodsName"=> "鞋子", |
|
||||
// ) |
|
||||
// ), |
|
||||
// "AddService"=> array( |
|
||||
// array( |
|
||||
// "Name"=> "COD", |
|
||||
// "Value"=> "1020", |
|
||||
// "CustomerID" => "44564" |
|
||||
// ) |
|
||||
// ), |
|
||||
// "StartDate" => date("y-M-d H:i:s",time() + 7200), |
|
||||
// "Weight"=> 1.0, |
|
||||
// "Quantity"=> 1, |
|
||||
// "Volume"=> 0.0, |
|
||||
// "Remark"=> "小心轻放", |
|
||||
//); |
|
||||
// |
|
||||
//try{ |
|
||||
// var_dump($expressPrint->index($machine_code, $content, $origin_id)); |
|
||||
//}catch (Exception $e) { |
|
||||
// echo $e->getMessage(); |
|
||||
//} |
|
||||
///**面单接口结束**/ |
|
||||
@ -1,11 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
include __DIR__ . '/init.php'; |
|
||||
|
|
||||
if (GRANTTYPE == 'client_credentials') { |
|
||||
include_once __DIR__ . '/client_mode/callback.php'; |
|
||||
} |
|
||||
|
|
||||
if (GRANTTYPE == 'authorization_code') { |
|
||||
include_once __DIR__ . '/authorization_code_mode/callback.php'; |
|
||||
} |
|
||||
@ -1,15 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
include dirname(__DIR__) . '/core/printer/sdk/yilianyun/Autoloader.php'; |
|
||||
|
|
||||
use core\printer\sdk\yilianyun\config\YlyConfig; |
|
||||
|
|
||||
$grantType = 'client_credentials'; //'client_credentials' 自有型应用; 'authorization_code' 开放型应用 |
|
||||
define('GRANTTYPE', $grantType); |
|
||||
|
|
||||
$clientId = '';//应用id |
|
||||
$clientSecret = '';//应用密钥 |
|
||||
|
|
||||
$config = new YlyConfig($clientId, $clientSecret); |
|
||||
//设置接口v2.0 |
|
||||
$config->setRequestUrl('https://open-api.10ss.net/v2'); |
|
||||
@ -1,152 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\printer\sdk\yilianyun\oauth; |
|
||||
|
|
||||
use core\printer\sdk\yilianyun\config\YlyConfig; |
|
||||
use Exception; |
|
||||
|
|
||||
class YlyOauthClient |
|
||||
{ |
|
||||
|
|
||||
private $clientId; |
|
||||
private $clientSecret; |
|
||||
private $requestUrl; |
|
||||
private $log; |
|
||||
|
|
||||
|
|
||||
public function __construct(YlyConfig $config) |
|
||||
{ |
|
||||
$this->clientId = $config->getClientId(); |
|
||||
$this->clientSecret = $config->getClientSecret(); |
|
||||
$this->requestUrl = $config->getRequestUrl(); |
|
||||
$this->log = $config->getLog(); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public function getToken($code = '') |
|
||||
{ |
|
||||
$time = time(); |
|
||||
$params = array( |
|
||||
'client_id' => $this->clientId, |
|
||||
'timestamp' => $time, |
|
||||
'sign' => $this->getSign($time), |
|
||||
'id' => $this->uuid4(), |
|
||||
'scope' => 'all' |
|
||||
); |
|
||||
$params[ 'grant_type' ] = 'client_credentials'; |
|
||||
if (!empty($code)) { |
|
||||
$params[ 'code' ] = $code; |
|
||||
$params[ 'grant_type' ] = 'authorization_code'; |
|
||||
} |
|
||||
|
|
||||
$url = sprintf("%s/%s", $this->requestUrl, 'oauth/oauth'); |
|
||||
return $this->send($params, $url); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public function getTokenBySecret($machineCode, $secret, $secretType = 0) |
|
||||
{ |
|
||||
$time = time(); |
|
||||
$params = array( |
|
||||
'client_id' => $this->clientId, |
|
||||
'timestamp' => $time, |
|
||||
'sign' => $this->getSign($time), |
|
||||
'id' => $this->uuid4(), |
|
||||
'machine_code' => $machineCode, |
|
||||
'scope' => 'all' |
|
||||
); |
|
||||
if ($secretType == 1) { |
|
||||
$params[ 'qr_key' ] = $secret; |
|
||||
} else { |
|
||||
$params[ 'msign' ] = $secret; |
|
||||
} |
|
||||
|
|
||||
$url = sprintf("%s/%s", $this->requestUrl, 'oauth/scancodemodel'); |
|
||||
return $this->send($params, $url); |
|
||||
} |
|
||||
|
|
||||
public function refreshToken($refreshToken) |
|
||||
{ |
|
||||
$time = time(); |
|
||||
$params = array( |
|
||||
'client_id' => $this->clientId, |
|
||||
'timestamp' => $time, |
|
||||
'sign' => $this->getSign($time), |
|
||||
'id' => $this->uuid4(), |
|
||||
'scope' => 'all', |
|
||||
'grant_type' => 'refresh_token', |
|
||||
'refresh_token' => $refreshToken, |
|
||||
); |
|
||||
|
|
||||
$url = sprintf("%s/%s", $this->requestUrl, 'oauth/oauth'); |
|
||||
return $this->send($params, $url); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public function getSign($timestamp) |
|
||||
{ |
|
||||
return md5( |
|
||||
$this->clientId . |
|
||||
$timestamp . |
|
||||
$this->clientSecret |
|
||||
); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public function uuid4() |
|
||||
{ |
|
||||
mt_srand(mt_rand()); |
|
||||
$charid = strtolower(md5(uniqid(rand(), true))); |
|
||||
$hyphen = '-'; |
|
||||
$uuidV4 = |
|
||||
substr($charid, 0, 8) . $hyphen . |
|
||||
substr($charid, 8, 4) . $hyphen . |
|
||||
substr($charid, 12, 4) . $hyphen . |
|
||||
substr($charid, 16, 4) . $hyphen . |
|
||||
substr($charid, 20, 12); |
|
||||
return $uuidV4; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public function send($data, $url) |
|
||||
{ |
|
||||
$requestInfo = http_build_query($data); |
|
||||
$log = $this->log; |
|
||||
if ($log != null) { |
|
||||
$log->info("request data: " . $requestInfo); |
|
||||
} |
|
||||
$curl = curl_init(); // 启动一个CURL会话 |
|
||||
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 |
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检测 |
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Expect:' )); // 解决数据包大不能提交 |
|
||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 |
|
||||
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer |
|
||||
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求 |
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestInfo); // Post提交的数据包 |
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循 |
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 |
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 |
|
||||
$requestResponse = curl_exec($curl); // 执行操作 |
|
||||
$response = json_decode($requestResponse); |
|
||||
if (curl_errno($curl)) { |
|
||||
if ($log != null) { |
|
||||
$log->error("error: " . curl_error($curl)); |
|
||||
} |
|
||||
throw new Exception(curl_error($curl)); |
|
||||
} |
|
||||
if (is_null($response)) { |
|
||||
throw new Exception("illegal response :" . $requestResponse); |
|
||||
} |
|
||||
|
|
||||
if ($response->error != 0 && $response->error_description != 'success') { |
|
||||
throw new Exception($response->error_description); |
|
||||
} |
|
||||
if ($this->log != null) { |
|
||||
$this->log->info("response: " . json_encode($response)); |
|
||||
} |
|
||||
curl_close($curl); // 关键CURL会话 |
|
||||
return $response->body; // 返回数据 |
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -1,104 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\printer\sdk\yilianyun\protocol; |
|
||||
|
|
||||
use core\printer\sdk\yilianyun\config\YlyConfig; |
|
||||
use Exception; |
|
||||
|
|
||||
class YlyRpcClient |
|
||||
{ |
|
||||
|
|
||||
private $clientId; |
|
||||
private $clientSecret; |
|
||||
private $requestUrl; |
|
||||
private $token; |
|
||||
private $log; |
|
||||
|
|
||||
|
|
||||
public function __construct($token, YlyConfig $config) |
|
||||
{ |
|
||||
$this->clientId = $config->getClientId(); |
|
||||
$this->clientSecret = $config->getClientSecret(); |
|
||||
$this->requestUrl = $config->getRequestUrl(); |
|
||||
$this->log = $config->getLog(); |
|
||||
$this->token = $token; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public function call($action, array $params) |
|
||||
{ |
|
||||
$time = time(); |
|
||||
$params = array_merge(array( |
|
||||
'client_id' => $this->clientId, |
|
||||
'timestamp' => $time, |
|
||||
'sign' => $this->getSign($time), |
|
||||
'id' => $this->uuid4(), |
|
||||
'access_token' => $this->token, |
|
||||
), $params); |
|
||||
|
|
||||
$result = $this->send($params, $this->requestUrl . '/' . $action); |
|
||||
$response = json_decode($result, false, 512, JSON_BIGINT_AS_STRING); |
|
||||
|
|
||||
return $response; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public function getSign($timestamp) |
|
||||
{ |
|
||||
return md5( |
|
||||
$this->clientId . |
|
||||
$timestamp . |
|
||||
$this->clientSecret |
|
||||
); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public function uuid4() |
|
||||
{ |
|
||||
mt_srand(mt_rand()); |
|
||||
$charid = strtolower(md5(uniqid(rand(), true))); |
|
||||
$hyphen = '-'; |
|
||||
$uuidV4 = |
|
||||
substr($charid, 0, 8) . $hyphen . |
|
||||
substr($charid, 8, 4) . $hyphen . |
|
||||
substr($charid, 12, 4) . $hyphen . |
|
||||
substr($charid, 16, 4) . $hyphen . |
|
||||
substr($charid, 20, 12); |
|
||||
return $uuidV4; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public function send($data, $url) |
|
||||
{ |
|
||||
$requestInfo = http_build_query($data); |
|
||||
$log = $this->log; |
|
||||
if ($log != null) { |
|
||||
$log->info("request data: " . $requestInfo); |
|
||||
} |
|
||||
$curl = curl_init(); // 启动一个CURL会话 |
|
||||
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 |
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检测 |
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Expect:' )); // 解决数据包大不能提交 |
|
||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 |
|
||||
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer |
|
||||
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求 |
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestInfo); // Post提交的数据包 |
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循 |
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 |
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 |
|
||||
$response = curl_exec($curl); // 执行操作 |
|
||||
if (curl_errno($curl)) { |
|
||||
if ($log != null) { |
|
||||
$log->error("error: " . curl_error($curl)); |
|
||||
} |
|
||||
throw new Exception(curl_error($curl)); |
|
||||
} |
|
||||
if ($log != null) { |
|
||||
$log->info("response: " . $response); |
|
||||
} |
|
||||
curl_close($curl); // 关键CURL会话 |
|
||||
return $response; // 返回数据 |
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -1,98 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\sms; |
|
||||
|
|
||||
use AlibabaCloud\Client\AlibabaCloud; |
|
||||
use core\exception\NoticeException; |
|
||||
use Exception; |
|
||||
|
|
||||
|
|
||||
class Aliyun extends BaseSms |
|
||||
{ |
|
||||
|
|
||||
protected $app_key = ''; |
|
||||
protected $secret_key = ''; |
|
||||
protected $sign = ''; |
|
||||
|
|
||||
/** |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
parent::initialize($config); |
|
||||
$this->app_key = $config[ 'app_key' ] ?? ''; |
|
||||
$this->secret_key = $config[ 'secret_key' ] ?? ''; |
|
||||
$this->sign = $config[ 'sign' ] ?? ''; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 发送短信 |
|
||||
* @param string $mobile |
|
||||
* @param string $template_id |
|
||||
* @param array $data |
|
||||
* @return array |
|
||||
*/ |
|
||||
public function send(string $mobile, string $template_id, array $data = []) |
|
||||
{ |
|
||||
try { |
|
||||
AlibabaCloud::accessKeyClient($this->app_key, $this->secret_key) |
|
||||
->regionId('cn-hangzhou') |
|
||||
->asDefaultClient(); |
|
||||
$result = AlibabaCloud::rpcRequest() |
|
||||
->product('Dysmsapi') |
|
||||
->host('dysmsapi.aliyuncs.com') |
|
||||
->version('2017-05-25') |
|
||||
->action('SendSms') |
|
||||
->method('POST') |
|
||||
->debug(false) |
|
||||
->options([ |
|
||||
'query' => [ |
|
||||
'PhoneNumbers' => $mobile, |
|
||||
'SignName' => $this->sign, |
|
||||
'TemplateCode' => $template_id, |
|
||||
'TemplateParam' => json_encode($data, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE), |
|
||||
], |
|
||||
]) |
|
||||
->request(); |
|
||||
|
|
||||
$res = $result->toArray(); |
|
||||
if (isset($res[ 'Code' ]) && $res[ 'Code' ] == 'OK') { |
|
||||
return $res; |
|
||||
} |
|
||||
$message = $res[ 'Message' ] ?? $res; |
|
||||
throw new NoticeException($message); |
|
||||
} catch (Exception $e) { |
|
||||
throw new NoticeException($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public function modify(string $sign, string $mobile, string $code) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public function template(int $page = 0, int $limit = 10, int $type = 1) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public function apply(string $title, string $content, int $type) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public function localTemplate(int $type, int $page, int $limit) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public function record($id) |
|
||||
{ |
|
||||
} |
|
||||
} |
|
||||
@ -1,83 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\sms; |
|
||||
|
|
||||
use core\loader\Storage; |
|
||||
|
|
||||
/** |
|
||||
* Class BaseSms |
|
||||
* @package |
|
||||
*/ |
|
||||
abstract class BaseSms extends Storage |
|
||||
{ |
|
||||
/** |
|
||||
* 初始化 |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 发送短信 |
|
||||
* @param string $mobile |
|
||||
* @param string $template_id |
|
||||
* @param array $data |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract public function send(string $mobile, string $template_id, array $data); |
|
||||
|
|
||||
/** |
|
||||
* 编辑签名 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract public function modify(string $sign, string $mobile, string $code); |
|
||||
|
|
||||
/** |
|
||||
* 短信模板 |
|
||||
* @param int $page |
|
||||
* @param int $limit |
|
||||
* @param int $type |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract public function template(int $page, int $limit, int $type); |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 申请短信 |
|
||||
* @param string $title |
|
||||
* @param string $content |
|
||||
* @param int $type |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract public function apply(string $title, string $content, int $type); |
|
||||
|
|
||||
/** |
|
||||
* 模板列表 |
|
||||
* @param int $type |
|
||||
* @param int $page |
|
||||
* @param int $limit |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract public function localTemplate(int $type, int $page, int $limit); |
|
||||
|
|
||||
/** |
|
||||
* 记录 |
|
||||
* @param $id |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract public function record($id); |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -1,44 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\sms; |
|
||||
|
|
||||
use core\loader\Loader; |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* Class SmsLoader |
|
||||
* @package core\sms |
|
||||
* @method string|null send( string $mobile, string $template_id, array $data ) 发送短信 |
|
||||
*/ |
|
||||
class SmsLoader extends Loader |
|
||||
{ |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 空间名 |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $namespace = '\\core\\sms\\'; |
|
||||
|
|
||||
protected $config_name = 'sms'; |
|
||||
|
|
||||
/** |
|
||||
* 默认驱动 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
protected function getDefault() |
|
||||
{ |
|
||||
return config('sms.default'); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -1,106 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\sms; |
|
||||
|
|
||||
use core\exception\CommonException; |
|
||||
use core\exception\NoticeException; |
|
||||
use Exception; |
|
||||
use TencentCloud\Common\Credential; |
|
||||
use TencentCloud\Common\Profile\ClientProfile; |
|
||||
use TencentCloud\Common\Profile\HttpProfile; |
|
||||
use TencentCloud\Sms\V20190711\Models\SendSmsRequest; |
|
||||
use TencentCloud\Sms\V20190711\SmsClient; |
|
||||
|
|
||||
/** |
|
||||
* 腾讯云短信 |
|
||||
* Class Tencent |
|
||||
* @package app\core\sms\driver |
|
||||
*/ |
|
||||
class Tencent extends BaseSms |
|
||||
{ |
|
||||
|
|
||||
|
|
||||
protected $secret_id = ''; |
|
||||
protected $secret_key = ''; |
|
||||
protected $sign = ''; |
|
||||
protected $app_id = ''; |
|
||||
|
|
||||
/** |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
parent::initialize($config); |
|
||||
$this->secret_id = $config[ 'secret_id' ] ?? ''; |
|
||||
$this->secret_key = $config[ 'secret_key' ] ?? ''; |
|
||||
$this->sign = $config[ 'sign' ] ?? ''; |
|
||||
$this->app_id = $config[ 'app_id' ] ?? ''; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 发送短信 |
|
||||
* @return bool|mixed |
|
||||
*/ |
|
||||
public function send(string $mobile, string $template_id, array $data = []) |
|
||||
{ |
|
||||
try { |
|
||||
$cred = new Credential($this->secret_id, $this->secret_key); |
|
||||
$httpProfile = new HttpProfile(); |
|
||||
$httpProfile->setEndpoint("sms.tencentcloudapi.com"); |
|
||||
|
|
||||
$clientProfile = new ClientProfile(); |
|
||||
$clientProfile->setHttpProfile($httpProfile); |
|
||||
|
|
||||
$client = new SmsClient($cred, 'ap-guangzhou', $clientProfile); |
|
||||
$params = [ |
|
||||
'PhoneNumberSet' => [ '+86' . $mobile ], |
|
||||
'TemplateID' => $template_id, |
|
||||
'Sign' => $this->sign, |
|
||||
'TemplateParamSet' => $data, |
|
||||
'SmsSdkAppid' => $this->app_id, |
|
||||
]; |
|
||||
$req = new SendSmsRequest(); |
|
||||
$req->fromJsonString(json_encode($params, JSON_THROW_ON_ERROR)); |
|
||||
$resp = json_decode($client->SendSms($req)->toJsonString(), true, 512, JSON_THROW_ON_ERROR); |
|
||||
if (isset($resp[ 'SendStatusSet' ]) && $resp[ 'SendStatusSet' ][ 0 ][ 'Code' ] == 'Ok') { |
|
||||
return $resp; |
|
||||
} else { |
|
||||
$message = $res[ 'SendStatusSet' ][ 0 ][ 'Message' ] ?? json_encode($resp, JSON_THROW_ON_ERROR); |
|
||||
throw new CommonException($message); |
|
||||
} |
|
||||
} catch (Exception $e) { |
|
||||
throw new NoticeException($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public function modify(string $sign, string $mobile, string $code) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public function template(int $page = 0, int $limit = 15, int $type = 1) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public function apply(string $title, string $content, int $type) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public function localTemplate(int $type, int $page, int $limit) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public function record($id) |
|
||||
{ |
|
||||
} |
|
||||
} |
|
||||
@ -1,60 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\template; |
|
||||
|
|
||||
use core\loader\Storage; |
|
||||
|
|
||||
/** |
|
||||
* Class BaseTemplate |
|
||||
* @package |
|
||||
*/ |
|
||||
abstract class BaseTemplate extends Storage |
|
||||
{ |
|
||||
/** |
|
||||
* 初始化 |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 发送模板消息 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function send(array $data); |
|
||||
|
|
||||
/** |
|
||||
* 增加模板消息 |
|
||||
* @param array $data |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function addTemplate(array $data); |
|
||||
|
|
||||
/** |
|
||||
* 删除消息模板 |
|
||||
* @param array $data |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function delete(array $data); |
|
||||
|
|
||||
/** |
|
||||
* 获取消息模板列表 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function get(); |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -1,47 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\template; |
|
||||
|
|
||||
use core\loader\Loader; |
|
||||
|
|
||||
/** |
|
||||
* @see TemplateLoader |
|
||||
* @package think\facade |
|
||||
* @mixin Wechat |
|
||||
* @method string|null send(array $data) 发送 |
|
||||
* @method mixed addTemplate(array $data) 增加 |
|
||||
* @method mixed delete(array $data) 删除 |
|
||||
* @method mixed get() 模板记录 |
|
||||
*/ |
|
||||
class TemplateLoader extends Loader |
|
||||
{ |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 空间名 |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $namespace = '\\core\\template\\'; |
|
||||
|
|
||||
protected $config_name = 'template'; |
|
||||
|
|
||||
/** |
|
||||
* 默认驱动 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
protected function getDefault() |
|
||||
{ |
|
||||
return config('template.default'); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -1,93 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\template; |
|
||||
|
|
||||
use app\service\core\weapp\CoreWeappService; |
|
||||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|
||||
use EasyWeChat\Kernel\Exceptions\InvalidConfigException; |
|
||||
use EasyWeChat\Kernel\Support\Collection; |
|
||||
use GuzzleHttp\Exception\GuzzleException; |
|
||||
use Psr\Http\Message\ResponseInterface; |
|
||||
|
|
||||
|
|
||||
class Weapp extends BaseTemplate |
|
||||
{ |
|
||||
|
|
||||
/** |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
parent::initialize($config); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 消息发送 |
|
||||
* @param array $data |
|
||||
* @return array|Collection|object|ResponseInterface|string |
|
||||
* @throws GuzzleException |
|
||||
* @throws InvalidArgumentException |
|
||||
* @throws InvalidConfigException |
|
||||
*/ |
|
||||
public function send(array $data) |
|
||||
{ |
|
||||
$api = CoreWeappService::appApiClient(); |
|
||||
$api->postJson('cgi-bin/message/subscribe/send', [ |
|
||||
'template_id' => $data['template_id'], // 所需下发的订阅模板id |
|
||||
'touser' => $data['openid'], // 接收者(用户)的 openid |
|
||||
'page' => $data['page'], // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。 |
|
||||
'data' => $data['data'], |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 添加模板消息 |
|
||||
* @param array $data |
|
||||
* @return array|Collection|object|ResponseInterface|string |
|
||||
* @throws GuzzleException |
|
||||
* @throws InvalidConfigException |
|
||||
*/ |
|
||||
public function addTemplate(array $data) |
|
||||
{ |
|
||||
$api = CoreWeappService::appApiClient(); |
|
||||
return $api->postJson('wxaapi/newtmpl/addtemplate', [ |
|
||||
'tid' => $data['tid'], |
|
||||
'kidList' => $data['kid_list'], |
|
||||
'sceneDesc' => $data['scene_desc'], |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 删除 |
|
||||
* @param array $data |
|
||||
* @return array|Collection|object|ResponseInterface|string |
|
||||
* @throws GuzzleException |
|
||||
* @throws InvalidConfigException |
|
||||
*/ |
|
||||
public function delete(array $data) |
|
||||
{ |
|
||||
$api = CoreWeappService::appApiClient(); |
|
||||
return $api->postJson('wxaapi/newtmpl/deltemplate', [ |
|
||||
'priTmplId' => $data['template_id'], |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取 |
|
||||
* @return void |
|
||||
*/ |
|
||||
public function get() |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
@ -1,111 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\template; |
|
||||
|
|
||||
use app\service\core\wechat\CoreWechatService; |
|
||||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|
||||
use EasyWeChat\Kernel\Exceptions\InvalidConfigException; |
|
||||
use EasyWeChat\Kernel\Support\Collection; |
|
||||
use GuzzleHttp\Exception\GuzzleException; |
|
||||
use Psr\Http\Message\ResponseInterface; |
|
||||
|
|
||||
|
|
||||
class Wechat extends BaseTemplate |
|
||||
{ |
|
||||
/** |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
parent::initialize($config); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 消息发送 |
|
||||
* @param array $data |
|
||||
* @return array|Collection|object|ResponseInterface|string |
|
||||
* @throws GuzzleException |
|
||||
* @throws InvalidArgumentException |
|
||||
* @throws InvalidConfigException |
|
||||
*/ |
|
||||
public function send(array $data) |
|
||||
{ |
|
||||
$openid = $data[ 'openid' ]; |
|
||||
$template_id = $data[ 'template_id' ]; |
|
||||
$template_data = $data[ 'data' ]; |
|
||||
$first = $data[ 'first' ]; |
|
||||
$remark = $data[ 'remark' ]; |
|
||||
$url = $data[ 'url' ]; |
|
||||
$miniprogram = $data[ 'miniprogram' ] ?? []; |
|
||||
$temp_data = []; |
|
||||
foreach($template_data as $k => $v){ |
|
||||
$temp_data[$k] = ['value' => $v]; |
|
||||
} |
|
||||
|
|
||||
if (!empty($first)) $data[ 'first' ] = $first; |
|
||||
if (!empty($remark)) $data[ 'remark' ] = $remark; |
|
||||
$api = CoreWechatService::appApiClient(); |
|
||||
$param = [ |
|
||||
'touser' => $openid, |
|
||||
'template_id' => $template_id, |
|
||||
'url' => $url, |
|
||||
'miniprogram' => $miniprogram, |
|
||||
'data' => $temp_data, |
|
||||
]; |
|
||||
if(!empty($client_msg_id)){ |
|
||||
$param['client_msg_id'] = $client_msg_id; |
|
||||
} |
|
||||
return $api->postJson('cgi-bin/message/template/send', $param); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 添加模板消息 |
|
||||
* @param array $data |
|
||||
* @return array|Collection|object|ResponseInterface|string |
|
||||
* @throws GuzzleException |
|
||||
* @throws InvalidConfigException |
|
||||
*/ |
|
||||
public function addTemplate(array $data) |
|
||||
{ |
|
||||
$api = CoreWechatService::appApiClient(); |
|
||||
return $api->postJson('cgi-bin/template/api_add_template', [ |
|
||||
'template_id_short' => $data[ 'shortId' ], |
|
||||
'keyword_name_list' => $data[ 'keyword_name_list' ] |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 删除 |
|
||||
* @param array $data |
|
||||
* @return array|Collection|object|ResponseInterface|string |
|
||||
* @throws GuzzleException |
|
||||
* @throws InvalidConfigException |
|
||||
*/ |
|
||||
public function delete(array $data) |
|
||||
{ |
|
||||
$api = CoreWechatService::appApiClient(); |
|
||||
|
|
||||
return $api->postJson('cgi-bin/template/del_private_template', [ |
|
||||
'template_id' => $data[ 'templateId' ], |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取 |
|
||||
* @return void |
|
||||
*/ |
|
||||
public function get() |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
@ -1,133 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\upload; |
|
||||
|
|
||||
use core\exception\UploadFileException; |
|
||||
use OSS\Core\OssException; |
|
||||
use OSS\OssClient; |
|
||||
|
|
||||
/** |
|
||||
* 阿里云存储引擎 (OSS) |
|
||||
*/ |
|
||||
class Aliyun extends BaseUpload |
|
||||
{ |
|
||||
|
|
||||
|
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
parent::initialize($config); |
|
||||
} |
|
||||
|
|
||||
public function client() |
|
||||
{ |
|
||||
// true为开启CNAME。CNAME是指将自定义域名绑定到存储空间上。 |
|
||||
// $is_cname = false; |
|
||||
$access_key_id = $this->config['access_key']; |
|
||||
$access_key_secret = $this->config['secret_key']; |
|
||||
|
|
||||
$endpoint = $this->config['endpoint'];// yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。 |
|
||||
return new OssClient($access_key_id, $access_key_secret, $endpoint); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 执行上传 |
|
||||
* @param string $dir |
|
||||
* @return true |
|
||||
*/ |
|
||||
public function upload(string $dir) |
|
||||
{ |
|
||||
$this->validate(); |
|
||||
$bucket = $this->config['bucket']; |
|
||||
try { |
|
||||
$this->client()->uploadFile( |
|
||||
$bucket, |
|
||||
$this->getFullPath($dir), |
|
||||
$this->getRealPath() |
|
||||
); |
|
||||
return true; |
|
||||
} catch ( OssException $e ) { |
|
||||
throw new UploadFileException($e->getMessage()); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* base64上云 |
|
||||
* @param string $base64_data |
|
||||
* @param string|null $key |
|
||||
* @return true |
|
||||
*/ |
|
||||
public function base64(string $base64_data, ?string $key = null) |
|
||||
{ |
|
||||
$bucket = $this->config['bucket']; |
|
||||
try { |
|
||||
$base64_file = base64_decode($base64_data); |
|
||||
if (!$base64_file) throw new UploadFileException('FILE_ERROR'); |
|
||||
$this->client()->putObject( |
|
||||
$bucket, |
|
||||
$key, |
|
||||
$base64_file |
|
||||
); |
|
||||
return true; |
|
||||
} catch ( OssException $e ) { |
|
||||
throw new UploadFileException($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
/** |
|
||||
* Notes: 抓取远程资源 |
|
||||
* @param string $url |
|
||||
* @param string|null $key |
|
||||
* @return true |
|
||||
*/ |
|
||||
public function fetch(string $url, ?string $key = null) |
|
||||
{ |
|
||||
$bucket = $this->config['bucket']; |
|
||||
try { |
|
||||
$content = file_get_contents($url); |
|
||||
$this->client()->putObject( |
|
||||
$bucket, |
|
||||
$key, |
|
||||
$content |
|
||||
); |
|
||||
return true; |
|
||||
} catch ( OssException $e ) { |
|
||||
throw new UploadFileException($e->getMessage()); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 删除文件 |
|
||||
* @param string $file_name |
|
||||
* @return true |
|
||||
*/ |
|
||||
public function delete(string $file_name) |
|
||||
{ |
|
||||
$bucket = $this->config['bucket']; |
|
||||
try { |
|
||||
$this->client()->deleteObject($bucket, $file_name); |
|
||||
return true; |
|
||||
} catch ( OssException $e ) { |
|
||||
throw new UploadFileException($e->getMessage()); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
public function thumb($file_path, $thumb_type) |
|
||||
{ |
|
||||
$thumb_config = config('upload.thumb.thumb_type'); |
|
||||
$thumb_data = []; |
|
||||
foreach ($thumb_config as $k => $v) { |
|
||||
if ($thumb_type == 'all' || $thumb_type == $k || (is_array($thumb_type) && in_array($k, $thumb_type))) { |
|
||||
$width = $v['width']; |
|
||||
$height = $v['height']; |
|
||||
//拼装缩略路径 |
|
||||
$item_thumb = $file_path . '?x-oss-process=image/resize,h_' . $height . ',w_' . $width; |
|
||||
$thumb_data[$k] = $item_thumb; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return $thumb_data; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,240 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
namespace core\upload; |
|
||||
|
|
||||
use core\exception\UploadFileException; |
|
||||
use core\loader\Storage; |
|
||||
|
|
||||
/** |
|
||||
* Class BaseUpload |
|
||||
*/ |
|
||||
abstract class BaseUpload extends Storage |
|
||||
{ |
|
||||
|
|
||||
protected $file;//上传的文件对象 |
|
||||
protected $file_info;//上传的文件属性参数 |
|
||||
protected $file_name;//新文件名 |
|
||||
protected $name; |
|
||||
protected $full_file;//完整的文件地址 |
|
||||
protected $full_path; |
|
||||
protected $validate; |
|
||||
protected $type; |
|
||||
|
|
||||
protected $config; |
|
||||
//可能还需要一个完整路径 |
|
||||
protected $storage_type; |
|
||||
|
|
||||
/** |
|
||||
* 初始化 |
|
||||
* @param array $config |
|
||||
* @return void |
|
||||
*/ |
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
$this->config = $config; |
|
||||
$this->storage_type = $config['storage_type']; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 附件上传 |
|
||||
* @param string $dir |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function upload(string $dir); |
|
||||
|
|
||||
/** |
|
||||
* 抓取远程附件 |
|
||||
* @param string $url |
|
||||
* @param string|null $key |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function fetch(string $url, ?string $key); |
|
||||
|
|
||||
/** |
|
||||
* base64文件上云 |
|
||||
* @param string $base64_data |
|
||||
* @param string|null $key |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function base64(string $base64_data, ?string $key = null); |
|
||||
/** |
|
||||
* 附件删除 |
|
||||
* @param string $file_name |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function delete(string $file_name); |
|
||||
|
|
||||
/** |
|
||||
* 缩略图 |
|
||||
* @param string $file_path |
|
||||
* @param $thumb_type |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
abstract protected function thumb(string $file_path, $thumb_type); |
|
||||
|
|
||||
/** |
|
||||
* 读取文件 |
|
||||
* @param string $name |
|
||||
* @param bool $is_rename |
|
||||
*/ |
|
||||
public function read(string $name, bool $is_rename = true) |
|
||||
{ |
|
||||
$this->name = $name; |
|
||||
$this->file = request()->file($name); |
|
||||
if (empty($this->file)) |
|
||||
throw new UploadFileException(100012); |
|
||||
$this->file_info = [ |
|
||||
'name' => $this->file->getOriginalName(),//文件原始名称 |
|
||||
'mime' => $this->file->getOriginalMime(),//上传文件类型信息 |
|
||||
'real_path' => $this->file->getRealPath(),//上传文件真实路径 |
|
||||
'ext' => $this->file->getOriginalExtension(),//上传文件后缀 |
|
||||
'size' => $this->file->getSize(),//上传文件大小 |
|
||||
]; |
|
||||
if ($is_rename) { |
|
||||
$this->file_name = $this->createFileName(); |
|
||||
} else { |
|
||||
$this->file_name = $this->file_info['name']; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置文件类型 |
|
||||
* @param string $type |
|
||||
* @return $this |
|
||||
*/ |
|
||||
public function setType(string $type) |
|
||||
{ |
|
||||
$this->type = $type; |
|
||||
return $this; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 校验文件是否合法 |
|
||||
*/ |
|
||||
public function check() |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 生成新的文件名 |
|
||||
* @return string |
|
||||
*/ |
|
||||
public function createFileName(string $key = '', string $ext = '') |
|
||||
{ |
|
||||
//DIRECTORY_SEPARATOR 常量 |
|
||||
$storage_tag = '_' . $this->storage_type; |
|
||||
if (empty($key)) { |
|
||||
return time() . md5($this->file_info['real_path']) . $storage_tag . '.' . $this->file_info['ext']; |
|
||||
} else { |
|
||||
return time() . md5($key) . $storage_tag . '.' . $ext; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取原始附件信息 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function getFileInfo() |
|
||||
{ |
|
||||
return $this->file_info; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取上传文件的真实完整路径 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function getRealPath() |
|
||||
{ |
|
||||
return $this->file_info['real_path']; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取生成的文件完整地址 |
|
||||
* @return string |
|
||||
*/ |
|
||||
public function getFullPath(string $dir = '') |
|
||||
{ |
|
||||
return $this->full_path ?: $this->concatFullPath($dir); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 合并路径和文件名 |
|
||||
* @param string $dir |
|
||||
* @return string |
|
||||
*/ |
|
||||
public function concatFullPath(string $dir = '') |
|
||||
{ |
|
||||
$this->full_path = implode('/', array_filter([$dir, $this->getFileName()])); |
|
||||
return $this->full_path; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取文件名 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
public function getFileName() |
|
||||
{ |
|
||||
return $this->file_name; |
|
||||
} |
|
||||
|
|
||||
public function getUrl(string $path = '') |
|
||||
{ |
|
||||
$path = !empty($path) ? $path : $this->getFullPath(); |
|
||||
$domain = $this->config['domain'] ?? ''; |
|
||||
$domain = empty($domain) ? '' : $domain . '/'; |
|
||||
return $domain . $path; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 验证 |
|
||||
* @param array $validate |
|
||||
* @return $this |
|
||||
*/ |
|
||||
public function setValidate(array $validate = []) |
|
||||
{ |
|
||||
$this->validate = $validate ?: config('upload.rules')[$this->type] ?? []; |
|
||||
return $this; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 根据上传文件的类型来校验文件是否符合配置 |
|
||||
* @return void |
|
||||
*/ |
|
||||
public function validate() |
|
||||
{ |
|
||||
if (empty($this->file)) |
|
||||
throw new UploadFileException('UPLOAD_FAIL'); |
|
||||
$config['file_ext'] = $this->validate['ext'] ?? []; |
|
||||
$config['file_mime'] = $this->validate['mime'] ?? []; |
|
||||
$config['file_size'] = $this->validate['size'] ?? 0; |
|
||||
$rule = []; |
|
||||
$file_size = $config['file_size'] ?? 0; |
|
||||
if ($file_size > 0) { |
|
||||
$rule[] = 'fileSize:' . $file_size; |
|
||||
} |
|
||||
//验证上传文件类型 |
|
||||
$file_mime = $config['file_mime'] ?? []; |
|
||||
$file_ext = $config['file_ext'] ?? []; |
|
||||
if (!empty($file_ext)) { |
|
||||
$rule[] = 'fileExt:' . implode(',', $file_ext); |
|
||||
} |
|
||||
if (!empty($rule)) { |
|
||||
if (!in_array($this->file->getOriginalMime(), $file_mime)) { |
|
||||
throw new UploadFileException('UPLOAD_TYPE_NOT_SUPPORT'); |
|
||||
} |
|
||||
validate([$this->name => implode('|', $rule)])->check([$this->name => $this->file]); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
@ -1,253 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\upload; |
|
||||
|
|
||||
use core\exception\UploadFileException; |
|
||||
use Exception; |
|
||||
use Grafika\Color; |
|
||||
use Grafika\Grafika; |
|
||||
use Grafika\Position; |
|
||||
|
|
||||
/** |
|
||||
* 文件管理驱动类 |
|
||||
*/ |
|
||||
class Local extends BaseUpload |
|
||||
{ |
|
||||
//位置 |
|
||||
private $position = array( |
|
||||
'top-left' => 'top-left', |
|
||||
'top-center' => 'top-center', |
|
||||
'top-right' => 'top-right', |
|
||||
'center-left' => 'center-left', |
|
||||
'center' => 'center', |
|
||||
'center-right' => 'center-right', |
|
||||
'bottom-left' => 'bottom-left', |
|
||||
'bottom-center' => 'bottom-center', |
|
||||
'bottom-right' => 'bottom-right', |
|
||||
); |
|
||||
|
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
parent::initialize($config); |
|
||||
|
|
||||
} |
|
||||
|
|
||||
public function upload(string $dir) |
|
||||
{ |
|
||||
$this->validate(); |
|
||||
|
|
||||
mkdirs_or_notexist($dir, 0777); |
|
||||
$this->file->move($dir, $this->file_name); |
|
||||
//错误一般是已经被抛出了 |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 远程获取图片 |
|
||||
* @param string $url |
|
||||
* @param string|null $key |
|
||||
* @return true |
|
||||
*/ |
|
||||
public function fetch(string $url, ?string $key) |
|
||||
{ |
|
||||
try { |
|
||||
mkdirs_or_notexist(dirname($key), 0777); |
|
||||
$ch = curl_init($url); |
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
||||
$content = curl_exec($ch); |
|
||||
curl_close($ch); |
|
||||
// $content = @file_get_contents($url);//file_get_contents下载网络图片慢,更换为curl下载 |
|
||||
if (!empty($content)) { |
|
||||
file_put_contents($key, $content); |
|
||||
|
|
||||
|
|
||||
$image_info = getimagesize($key); |
|
||||
$image_type = $image_info[2]; |
|
||||
// if($image_type == IMAGETYPE_JPEG){ |
|
||||
// // 保存图片为PNG格式 |
|
||||
// $image = imagecreatefromjpeg($key); |
|
||||
// }else if($image_type == IMAGETYPE_PNG){ |
|
||||
// // 保存图片为PNG格式 |
|
||||
// $image = imagecreatefrompng($key); |
|
||||
// } |
|
||||
if($image_type == IMAGETYPE_WEBP){ |
|
||||
// 保存图片为PNG格式 |
|
||||
$image = imagecreatefromwebp($key); |
|
||||
} |
|
||||
// 创建图片资源 |
|
||||
// 检查图片是否创建成功 |
|
||||
if (!empty($image)){ |
|
||||
|
|
||||
// 图片类型常量定义:IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF |
|
||||
if ($image_type == IMAGETYPE_WEBP) { |
|
||||
$temp_arr = explode('.', $key); |
|
||||
$ext = end($temp_arr); |
|
||||
if($ext == 'jpg' || $ext == 'jpeg'){ |
|
||||
// 保存图片为PNG格式 |
|
||||
imagejpeg($image, $key); |
|
||||
}else if($ext = 'png'){ |
|
||||
// 保存图片为PNG格式 |
|
||||
imagepng($image, $key); |
|
||||
} |
|
||||
} |
|
||||
// 释放内存 |
|
||||
imagedestroy($image); |
|
||||
} |
|
||||
|
|
||||
} else { |
|
||||
throw new UploadFileException(203006); |
|
||||
} |
|
||||
return true; |
|
||||
} catch ( Exception $e ) { |
|
||||
throw new UploadFileException($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* base64转图片 |
|
||||
* @param string $content |
|
||||
* @param string|null $key |
|
||||
* @return true |
|
||||
*/ |
|
||||
public function base64(string $content, ?string $key = null) |
|
||||
{ |
|
||||
|
|
||||
mkdirs_or_notexist(dirname($key)); |
|
||||
file_put_contents(url_to_path($key), base64_decode($content)); |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 删除本地附件 |
|
||||
* @param string $file_name |
|
||||
* @return bool |
|
||||
*/ |
|
||||
public function delete(string $file_name) |
|
||||
{ |
|
||||
$file_path = url_to_path($file_name); |
|
||||
if (file_exists($file_path)) { |
|
||||
$result = unlink($file_path); |
|
||||
// throw new UploadFileException(100013); |
|
||||
}else{ |
|
||||
$result = true; |
|
||||
} |
|
||||
//顺便删除相关的缩略图 |
|
||||
$dirname = dirname($file_name); |
|
||||
$file_list = []; |
|
||||
search_dir($dirname, $file_list); |
|
||||
if(!empty($file_list)){ |
|
||||
$file_arr = explode('/', $file_name); |
|
||||
$only_file_name = end($file_arr); |
|
||||
foreach($file_list as $v){ |
|
||||
if(str_contains($v, $only_file_name) && file_exists($v)){ |
|
||||
unlink($v); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
return $result; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 缩略图 |
|
||||
* @param $file_path |
|
||||
* @param $thumb_type |
|
||||
* @return array |
|
||||
* @throws Exception |
|
||||
*/ |
|
||||
public function thumb($file_path, $thumb_type) |
|
||||
{ |
|
||||
//todo 判断缩略图是否存在 |
|
||||
$thumb_config = config('upload.thumb.thumb_type'); |
|
||||
// …… |
|
||||
//获取文件原名 获取 |
|
||||
$file_arr = explode('/', $file_path); |
|
||||
$file_name = end($file_arr); |
|
||||
$thumb_list = []; |
|
||||
//获取文件后缀 |
|
||||
foreach ($thumb_config as $k => $v) { |
|
||||
if ($thumb_type == 'all' || $thumb_type == $k || (is_array($thumb_type) && in_array($k, $thumb_type))) { |
|
||||
$new_width = $v['width']; |
|
||||
$new_height = $v['height']; |
|
||||
$new_thumb_path = str_replace($file_name, $new_width . 'x' . $new_height . '_' . $file_name, $file_path); |
|
||||
|
|
||||
if (!file_exists($new_thumb_path)) { |
|
||||
$editor = Grafika::createEditor(); |
|
||||
$editor->open($image, $file_path); |
|
||||
$editor->resizeFit($image, $new_width, $new_height); |
|
||||
//新缩略图文件名称 |
|
||||
$editor->save($image, $new_thumb_path, null, null, false, 0777); |
|
||||
} |
|
||||
$thumb_list[$k] = $new_thumb_path; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
return $thumb_list; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 图片水印 |
|
||||
* @param $file_path |
|
||||
* @return mixed |
|
||||
* @throws Exception |
|
||||
*/ |
|
||||
public function water($file_path) |
|
||||
{ |
|
||||
$water_config = []; |
|
||||
if (!empty($water_config)) { |
|
||||
$status = $water_config['status'];//是否启用 |
|
||||
if ($status) { |
|
||||
$editor = Grafika::createEditor(); |
|
||||
$editor->open($image, $file_path); |
|
||||
if ($water_config['type'] == 'image') { |
|
||||
$water_image = $water_config['image']; |
|
||||
if (!empty($water_image)) { |
|
||||
//判断水印图片是否是本地图片 |
|
||||
if (check_file_is_remote($water_image)) { |
|
||||
$file_arr = explode('.', $water_image); |
|
||||
$ext_name = end($file_arr); |
|
||||
$name = $this->createFileName($water_image, $ext_name); |
|
||||
$watermark_image = 'upload/water/' . $name; |
|
||||
$this->fetch($water_image, $watermark_image); |
|
||||
} |
|
||||
if (file_exists($water_image)) { |
|
||||
|
|
||||
} |
|
||||
$editor->open($image1, $water_config['image']); |
|
||||
$editor->blend($image, $image1, 'normal', $water_config['opacity'], $this->position[$water_config['position']], $water_config['offset_x'], $water_config['offset_y']); |
|
||||
} |
|
||||
} else { |
|
||||
if ($water_config['text']) { |
|
||||
$position = $this->position[$water_config['position']]; |
|
||||
$offset_x = $water_config['offset_x'];//水平偏移值 |
|
||||
$offset_y = $water_config['offset_y'];//垂直偏移值 |
|
||||
$width = $image->getWidth(); |
|
||||
$height = $image->getHeight(); |
|
||||
|
|
||||
//获取文字信息 |
|
||||
$info = imagettfbbox($water_config['size'], $water_config['angle'], $water_config['font'], $water_config['text']); |
|
||||
$minx = min($info[0], $info[2], $info[4], $info[6]); |
|
||||
$maxx = max($info[0], $info[2], $info[4], $info[6]); |
|
||||
$miny = min($info[1], $info[3], $info[5], $info[7]); |
|
||||
$maxy = max($info[1], $info[3], $info[5], $info[7]); |
|
||||
/* 计算文字初始坐标和尺寸 */ |
|
||||
$x = $minx; |
|
||||
$y = abs($miny); |
|
||||
$w = $maxx - $minx; |
|
||||
$h = $maxy - $miny; |
|
||||
//转化坐标 |
|
||||
$position = new Position($position, $offset_x, $offset_y); |
|
||||
// Position is for $image2. $image1 is canvas. |
|
||||
list($offset_x, $offset_y) = $position->getXY($width, $height, $w, $h); |
|
||||
|
|
||||
$editor->text($image, $water_config['text'], $water_config['size'], $offset_x, $offset_y, new Color($water_config['color']), $water_config['font'], $water_config['angle']); |
|
||||
} |
|
||||
$editor->save($image, $file_path); |
|
||||
|
|
||||
|
|
||||
} |
|
||||
} |
|
||||
return $file_path; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,180 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\upload; |
|
||||
|
|
||||
use core\exception\UploadFileException; |
|
||||
use Exception; |
|
||||
use Qiniu\Auth; |
|
||||
use Qiniu\Config; |
|
||||
use Qiniu\Storage\BucketManager; |
|
||||
use Qiniu\Storage\UploadManager; |
|
||||
|
|
||||
/** |
|
||||
* 文件管理驱动类 |
|
||||
*/ |
|
||||
class Qiniu extends BaseUpload |
|
||||
{ |
|
||||
|
|
||||
private $position = array( |
|
||||
'top-left' => 'NorthWest', |
|
||||
'top-center' => 'North', |
|
||||
'top-right' => 'NorthEast', |
|
||||
'center-left' => 'West', |
|
||||
'center' => 'Center', |
|
||||
'center-right' => 'East', |
|
||||
'bottom-left' => 'SouthWest', |
|
||||
'bottom-center' => 'South', |
|
||||
'bottom-right' => 'SouthEast', |
|
||||
); |
|
||||
|
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
parent::initialize($config); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取一个鉴权对象 |
|
||||
* @return Auth |
|
||||
*/ |
|
||||
public function auth() |
|
||||
{ |
|
||||
$access_key = $this->config['access_key']; |
|
||||
$secret_key = $this->config['secret_key']; |
|
||||
return new Auth($access_key, $secret_key); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* @throws Exception |
|
||||
*/ |
|
||||
public function upload(string $dir) |
|
||||
{ |
|
||||
$this->validate(); |
|
||||
$bucket = $this->config['bucket']; |
|
||||
//todo 这儿可以定义凭证的过期时间 |
|
||||
$up_token = $this->auth()->uploadToken($bucket); |
|
||||
// 初始化 UploadManager 对象并进行文件的上传。 |
|
||||
$upload_mgr = new UploadManager(); |
|
||||
[$ret, $err] = $upload_mgr->putFile($up_token, $this->getFullPath($dir), $this->getRealPath()); |
|
||||
if ($err !== null) |
|
||||
throw new UploadFileException($err->message()); |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 抓取网络资源到空间 |
|
||||
* @param string $url |
|
||||
* @param string|null $key |
|
||||
* @return true |
|
||||
* @throws Exception |
|
||||
*/ |
|
||||
public function fetch(string $url, ?string $key = null) |
|
||||
{ |
|
||||
$bucket = $this->config['bucket']; |
|
||||
$auth = $this->auth(); |
|
||||
if (!str_contains($url, 'http://') && !str_contains($url, 'https://')) { |
|
||||
$token = $auth->uploadToken($bucket); |
|
||||
$upload_mgr = new UploadManager(); |
|
||||
[$ret, $err] = $upload_mgr->putFile($token, $key, $url); |
|
||||
} else { |
|
||||
//抓取网络资源到空间 |
|
||||
$bucket_manager = new BucketManager($auth); |
|
||||
[$ret, $err] = $bucket_manager->fetch($url, $bucket, $key);//不指定key时,以文件内容的hash作为文件名 |
|
||||
} |
|
||||
|
|
||||
if ($err !== null) |
|
||||
throw new UploadFileException($err->message()); |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* base64资源上传 |
|
||||
* @param string $base64_data |
|
||||
* @param string|null $key |
|
||||
* @return true |
|
||||
*/ |
|
||||
public function base64(string $base64_data, ?string $key = null) |
|
||||
{ |
|
||||
$bucket = $this->config['bucket']; |
|
||||
$auth = $this->auth(); |
|
||||
$up_token = $this->auth()->uploadToken($bucket); |
|
||||
// 初始化 UploadManager 对象并进行文件的上传。 |
|
||||
$upload_mgr = new UploadManager(); |
|
||||
//将 base64 编码的图片数据解码 |
|
||||
$base64_file = base64_decode($base64_data); |
|
||||
if (!$base64_file) throw new UploadFileException('FILE_ERROR'); |
|
||||
// 初始化 UpLoadManager 对象并进行文件的上传 |
|
||||
list($ret, $err) = $upload_mgr->put($up_token, $key, $base64_file); |
|
||||
if ($err !== null) throw new UploadFileException($err->message); |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 删除空间中的文件 |
|
||||
* @param string $file_name |
|
||||
* @return true |
|
||||
*/ |
|
||||
public function delete(string $file_name) |
|
||||
{ |
|
||||
$bucket = $this->config['bucket']; |
|
||||
$auth = $this->auth(); |
|
||||
$config = new Config(); |
|
||||
$bucket_manager = new BucketManager($auth, $config); |
|
||||
[$ret, $err] = $bucket_manager->delete($bucket, $file_name); |
|
||||
if ($err !== null) |
|
||||
throw new UploadFileException($err->message()); |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
public function thumb($file_path, $thumb_type) |
|
||||
{ |
|
||||
// mageView2/1/w/400/h/600/q/85 |
|
||||
$thumb_config = config('upload.thumb.thumb_type'); |
|
||||
$thumb_data = []; |
|
||||
foreach ($thumb_config as $k => $v) { |
|
||||
if ($thumb_type == 'all' || $thumb_type == $k || (is_array($thumb_type) && in_array($k, $thumb_type))) { |
|
||||
// ?x-oss-process=image/resize,m_fill,w_200,h_600,quality,q_60 |
|
||||
$width = $v['width']; |
|
||||
$height = $v['height']; |
|
||||
//拼装缩略路径 |
|
||||
$item_thumb = $file_path . '?imageView2/2/w/' . $width . '/h/' . $height; |
|
||||
$thumb_data[$k] = $item_thumb; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return $thumb_data; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 图片水印 |
|
||||
* @param $file_path |
|
||||
* @return mixed |
|
||||
* @throws Exception |
|
||||
*/ |
|
||||
public function water($file_path) |
|
||||
{ |
|
||||
$water_config = []; |
|
||||
$water_path = $file_path; |
|
||||
if (!empty($water_config)) { |
|
||||
$status = $water_config['status'];//是否启用 |
|
||||
if ($status) { |
|
||||
//判断当前的云图片是否存在?,存在符号的话需要用|连接 |
|
||||
if (str_contains($file_path, '?')) { |
|
||||
$water_path .= '|watermark'; |
|
||||
} else { |
|
||||
$water_path .= '?watermark'; |
|
||||
} |
|
||||
if ($water_config['type'] == 'image') { |
|
||||
$water_image = $water_config['image']; |
|
||||
if (!empty($water_image)) { |
|
||||
$water_path .= '/1/image/' . base64_encode($water_image) . '/gravity/' . $this->position[$water_config['position']] . '/dissolve/' . $water_config['opacity'] . '/dx/' . $water_config['offset_x'] . '/dy/' . $water_config['offset_y']; |
|
||||
} |
|
||||
} else { |
|
||||
$water_path .= '/2/text/' . base64_encode($water_config['text']) . '/font/' . base64_encode($water_config['font']) . '/fill/' . base64_encode($water_config['color']) . '/fontsize/' . $water_config['size'] . '/gravity/' . $this->position[$water_config['position']] . '/dx/' . $water_config['offset_x'] . '/dy/' . $water_config['offset_y']; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
return $water_path; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,195 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\upload; |
|
||||
|
|
||||
use core\exception\UploadFileException; |
|
||||
use Exception; |
|
||||
use Qcloud\Cos\Client; |
|
||||
|
|
||||
/** |
|
||||
* 腾讯云存储引擎 (COS) |
|
||||
*/ |
|
||||
class Tencent extends BaseUpload |
|
||||
{ |
|
||||
|
|
||||
private $position = array( |
|
||||
'top-left' => 'northwest', |
|
||||
'top-center' => 'north', |
|
||||
'top-right' => 'northeast', |
|
||||
'center-left' => 'west', |
|
||||
'center' => 'center', |
|
||||
'center-right' => 'east', |
|
||||
'bottom-left' => 'southwest', |
|
||||
'bottom-center' => 'south', |
|
||||
'bottom-right' => 'southeast', |
|
||||
); |
|
||||
|
|
||||
protected function initialize(array $config = []) |
|
||||
{ |
|
||||
parent::initialize($config); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取服务主体 |
|
||||
* @return Client |
|
||||
*/ |
|
||||
public function client() |
|
||||
{ |
|
||||
$secret_id = $this->config['access_key']; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.tencentcloud.com/cam/capi |
|
||||
$secret_key = $this->config['secret_key']; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.tencentcloud.com/cam/capi |
|
||||
$region = $this->config['region']; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.tencentcloud.com/cos5/bucket |
|
||||
|
|
||||
return new Client( |
|
||||
array( |
|
||||
'region' => $region, |
|
||||
// 'schema' => 'https', //协议头部,默认为http |
|
||||
'credentials' => array( |
|
||||
'secretId' => $secret_id, |
|
||||
'secretKey' => $secret_key) |
|
||||
) |
|
||||
); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 执行上传 |
|
||||
* @param string $dir |
|
||||
* @return true |
|
||||
*/ |
|
||||
public function upload(string $dir) |
|
||||
{ |
|
||||
$this->validate(); |
|
||||
$bucket = $this->config['bucket']; |
|
||||
try { |
|
||||
$result = $this->client()->putObject(array( |
|
||||
'Bucket' => $bucket, //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket |
|
||||
'Key' => $this->getFullPath($dir), |
|
||||
'Body' => fopen($this->getRealPath(), 'rb'), |
|
||||
)); |
|
||||
// 请求成功 |
|
||||
return true; |
|
||||
} catch ( Exception $e ) { |
|
||||
throw new UploadFileException($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* base文件上云 |
|
||||
* @param string $base64_data |
|
||||
* @param string|null $key |
|
||||
* @return true |
|
||||
*/ |
|
||||
public function base64(string $base64_data, ?string $key = null) |
|
||||
{ |
|
||||
$bucket = $this->config['bucket']; |
|
||||
try { |
|
||||
$base64_file = base64_decode($base64_data); |
|
||||
if (!$base64_file) throw new UploadFileException('FILE_ERROR'); |
|
||||
$result = $this->client()->putObject(array( |
|
||||
'Bucket' => $bucket, //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket |
|
||||
'Key' => $key, |
|
||||
'Body' => $base64_file, |
|
||||
)); |
|
||||
// 请求成功 |
|
||||
return true; |
|
||||
} catch ( Exception $e ) { |
|
||||
throw new UploadFileException($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
/** |
|
||||
* notes: 抓取远程资源(最大支持上传5G文件) |
|
||||
* @param string $url |
|
||||
* @param string|null $key |
|
||||
* @return true |
|
||||
*/ |
|
||||
public function fetch(string $url, ?string $key = null) |
|
||||
{ |
|
||||
|
|
||||
$bucket = $this->config['bucket']; |
|
||||
try { |
|
||||
$result = $this->client()->putObject(array( |
|
||||
'Bucket' => $bucket, //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket |
|
||||
'Key' => $key, |
|
||||
'Body' => fopen($url, 'rb'), |
|
||||
)); |
|
||||
// 请求成功 |
|
||||
return true; |
|
||||
} catch ( Exception $e ) { |
|
||||
throw new UploadFileException($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 删除一个简单对象 |
|
||||
* @param string $file_name |
|
||||
* @return true |
|
||||
*/ |
|
||||
public function delete(string $file_name) |
|
||||
{ |
|
||||
$bucket = $this->config['bucket']; |
|
||||
try { |
|
||||
$this->client()->deleteObject(array( |
|
||||
'Bucket' => $bucket, |
|
||||
'Key' => $file_name |
|
||||
)); |
|
||||
return true; |
|
||||
} catch ( Exception $e ) { |
|
||||
throw new UploadFileException($e->getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public function thumb($file_path, $thumb_type) |
|
||||
{ |
|
||||
//腾讯云缩略图地址 |
|
||||
|
|
||||
$thumb_config = config('upload.thumb.thumb_type'); |
|
||||
$thumb_data = []; |
|
||||
foreach ($thumb_config as $k => $v) { |
|
||||
if ($thumb_type == 'all' || $thumb_type == $k || (is_array($thumb_type) && in_array($k, $thumb_type))) { |
|
||||
// ?x-oss-process=image/resize,m_fill,w_200,h_600,quality,q_60 |
|
||||
$width = $v['width']; |
|
||||
$height = $v['height']; |
|
||||
//拼装缩略路径 |
|
||||
$item_thumb = $file_path . '?imageMogr2/thumbnail/' . $width . 'x' . $height; |
|
||||
$thumb_data[$k] = $item_thumb; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return $thumb_data; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
/** |
|
||||
* 图片水印 |
|
||||
* @param $file_path |
|
||||
* @return mixed |
|
||||
* @throws Exception |
|
||||
*/ |
|
||||
public function water($file_path) |
|
||||
{ |
|
||||
$water_config = []; |
|
||||
$water_path = $file_path; |
|
||||
if (!empty($water_config)) { |
|
||||
$status = $water_config['status'];//是否启用 |
|
||||
if($status){ |
|
||||
//判断当前的云图片是否存在?,存在符号的话需要用|连接 |
|
||||
if(str_contains($file_path, '?')){ |
|
||||
$water_path .= '&watermark'; |
|
||||
}else{ |
|
||||
$water_path .= '?watermark'; |
|
||||
} |
|
||||
if ($water_config['type'] == 'image') { |
|
||||
$water_image = $water_config['image']; |
|
||||
if(!empty($water_image)){ |
|
||||
//http://examples-1251000004.cos.ap-shanghai.myqcloud.com/sample.jpeg?watermark/1/image/aHR0cDovL2V4YW1wbGVzLTEyNTEwMDAwMDQucGljc2gubXlxY2xvdWQuY29tL3NodWl5aW4uanBn/gravity/southeast |
|
||||
$water_path .= '/1/image/' . base64_encode($water_image) . '/gravity/' . $this->position[$water_config['position']] . '/blogo/1/dx/' . $water_config['offset_x'] . '/dy/' . $water_config['offset_y'].'/dissolve/'.$water_config['opacity']; |
|
||||
} |
|
||||
} else { |
|
||||
//http://examples-1251000004.cos.ap-shanghai.myqcloud.com/sample.jpeg?q-sign-algorithm=<signature>&watermark/2/text/6IW-6K6v5LqRwrfkuIfosaHkvJjlm74/fill/IzNEM0QzRA/fontsize/20/dissolve/50/gravity/northeast/dx/20/dy/20/batch/1/degree/45 |
|
||||
$water_path .= '/2/text/' . base64_encode($water_config['text']) . '/font/' . base64_encode($water_config['font']) . '/fill/' . base64_encode($water_config['color']) . '/fontsize/' . $water_config['size'] . '/gravity/' . $this->position[$water_config['position']] . '/dx/' . $water_config['offset_x'] . '/dy/' . $water_config['offset_y']; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
return $water_path; |
|
||||
} |
|
||||
} |
|
||||
@ -1,44 +0,0 @@ |
|||||
<?php |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | 官方网址:https://www.niucloud.com |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | niucloud团队 版权所有 开源版本可自由商用 |
|
||||
// +---------------------------------------------------------------------- |
|
||||
// | Author: Niucloud Team |
|
||||
// +---------------------------------------------------------------------- |
|
||||
|
|
||||
namespace core\upload; |
|
||||
|
|
||||
use core\loader\Loader; |
|
||||
|
|
||||
/** |
|
||||
* @see UploadLoader |
|
||||
* @package think\facade |
|
||||
* @mixin BaseUpload |
|
||||
* @method string|null upload(string $dir) 附件上传 |
|
||||
* @method array fetch(string $url, ?string $key) 抓取远程附件 |
|
||||
* @method mixed delete(string $file_name) 附件删除 |
|
||||
* @method mixed thumb(string $file_path, $thumb_type) 附件删除 |
|
||||
* @method mixed base64(string $base64_data, ?string $key = null) base文件上传 |
|
||||
*/ |
|
||||
class UploadLoader extends Loader |
|
||||
{ |
|
||||
/** |
|
||||
* 空间名 |
|
||||
* @var string |
|
||||
*/ |
|
||||
protected $namespace = '\\core\\upload\\'; |
|
||||
|
|
||||
protected $config_name = 'upload'; |
|
||||
|
|
||||
/** |
|
||||
* 默认驱动 |
|
||||
* @return mixed |
|
||||
*/ |
|
||||
protected function getDefault() |
|
||||
{ |
|
||||
return config('upload.default'); |
|
||||
} |
|
||||
} |
|
||||
@ -1,74 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\util; |
|
||||
|
|
||||
require_once( 'barcode/class/BCGFontFile.php' ); |
|
||||
require_once( 'barcode/class/BCGColor.php' ); |
|
||||
require_once( 'barcode/class/BCGDrawing.php' ); |
|
||||
require_once( 'barcode/class/BCGcode128.barcode.php' ); |
|
||||
|
|
||||
class Barcode |
|
||||
{ |
|
||||
public $size; //字体大小 |
|
||||
private $color_black; |
|
||||
private $color_white; |
|
||||
private $font; |
|
||||
public $drawException = null; |
|
||||
public $fontPath; |
|
||||
public $content; |
|
||||
|
|
||||
public function __construct($size, $content) |
|
||||
{ |
|
||||
$this->color_black = new \BCGColor(0, 0, 0); |
|
||||
$this->color_white = new \BCGColor(255, 255, 255); |
|
||||
$this->size = $size; |
|
||||
$this->fontPath = str_replace("\\", "/", root_path() . "core/util/barcode/font/Arial.ttf"); |
|
||||
$this->font = new \BCGFontFile($this->fontPath, $this->size); |
|
||||
$this->content = $content; |
|
||||
} |
|
||||
|
|
||||
//生成条形码 |
|
||||
public function generateBarcode($path = '', $scale = 2) |
|
||||
{ |
|
||||
try { |
|
||||
$code = new \BCGcode128(); |
|
||||
$code->setScale($scale); |
|
||||
$code->setThickness(30); // 条形码的厚度 |
|
||||
$code->setForegroundColor($this->color_black); // 条形码颜色 |
|
||||
$code->setBackgroundColor($this->color_white); // 空白间隙颜色 |
|
||||
$code->setFont($this->font); // |
|
||||
$code->parse($this->content); // 条形码需要的数据内容 |
|
||||
} catch (Exception $exception) { |
|
||||
$this->drawException = $exception; |
|
||||
} |
|
||||
|
|
||||
if ($path == '') { |
|
||||
$path = 'upload/barcode';//条形码存放路径 |
|
||||
} |
|
||||
|
|
||||
if (!is_dir($path)) { |
|
||||
$mode = intval('0777', 8); |
|
||||
mkdir($path, $mode, true); |
|
||||
chmod($path, $mode); |
|
||||
} |
|
||||
$path = $path . '/' . $this->content . '.png'; |
|
||||
if (file_exists($path)) { |
|
||||
unlink($path); |
|
||||
} |
|
||||
|
|
||||
//根据以上条件绘制条形码 |
|
||||
$drawing = new \BCGDrawing('', $this->color_white); |
|
||||
if ($this->drawException) { |
|
||||
$drawing->drawException($this->drawException); |
|
||||
} else { |
|
||||
$drawing->setBarcode($code); |
|
||||
$drawing->setFilename($path); |
|
||||
$drawing->draw(); |
|
||||
} |
|
||||
// 生成PNG格式的图片 |
|
||||
$drawing->finish(\BCGDrawing::IMG_FORMAT_PNG); |
|
||||
return $path; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
?> |
|
||||
@ -1,532 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace core\util; |
|
||||
|
|
||||
use think\facade\Db; |
|
||||
|
|
||||
class DbBackup |
|
||||
{ |
|
||||
/** |
|
||||
* 文件指针 |
|
||||
* @var resource |
|
||||
*/ |
|
||||
private $fp; |
|
||||
/** |
|
||||
* 备份文件信息 part - 卷号,name - 文件名 |
|
||||
* @var array |
|
||||
*/ |
|
||||
private $file; |
|
||||
/** |
|
||||
* 当前打开文件大小 |
|
||||
* @var integer |
|
||||
*/ |
|
||||
private $size = 0; |
|
||||
|
|
||||
/** |
|
||||
* 数据库配置 |
|
||||
* @var integer |
|
||||
*/ |
|
||||
private $dbconfig = array(); |
|
||||
/** |
|
||||
* 备份配置 |
|
||||
* @var integer |
|
||||
*/ |
|
||||
private $config = array( |
|
||||
// 数据库备份路径 |
|
||||
'path' => './backup/', |
|
||||
// 数据库备份卷大小 |
|
||||
'part' => 20971520, |
|
||||
// 数据库备份文件是否启用压缩 0不压缩 1 压缩 |
|
||||
'compress' => 0, |
|
||||
// 数据库备份文件压缩级别 1普通 4 一般 9最高 |
|
||||
'level' => 9, |
|
||||
); |
|
||||
|
|
||||
/** |
|
||||
* 数据库备份构造方法 |
|
||||
* @param array $file 备份或还原的文件信息 |
|
||||
* @param array $config 备份配置信息 |
|
||||
*/ |
|
||||
public function __construct($config = []) |
|
||||
{ |
|
||||
$this->config = is_array($config) && !empty($config) ? array_merge($this->config, $config) : $this->config; |
|
||||
//初始化文件名 |
|
||||
$this->setFile(); |
|
||||
//初始化数据库连接参数 |
|
||||
$this->setDbConn(); |
|
||||
//检查文件是否可写 |
|
||||
if (!$this->checkPath($this->config['path'])) { |
|
||||
throw new \Exception("The current directory is not writable"); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置脚本运行超时时间 |
|
||||
* 0表示不限制,支持连贯操作 |
|
||||
*/ |
|
||||
public function setTimeout($time = null) |
|
||||
{ |
|
||||
if (!is_null($time)) { |
|
||||
set_time_limit($time) || ini_set("max_execution_time", $time); |
|
||||
} |
|
||||
return $this; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置数据库连接必备参数 |
|
||||
* @param array $dbconfig 数据库连接配置信息 |
|
||||
* @return object |
|
||||
*/ |
|
||||
public function setDbConn($dbconfig = []) |
|
||||
{ |
|
||||
if (empty($dbconfig)) { |
|
||||
$this->dbconfig = config('database.connections.'.config('database.default')); |
|
||||
} else { |
|
||||
$this->dbconfig = $dbconfig; |
|
||||
} |
|
||||
return $this; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置备份文件名 |
|
||||
* |
|
||||
* @param Array $file 文件名字 |
|
||||
* @return object |
|
||||
*/ |
|
||||
public function setFile($file = null) |
|
||||
{ |
|
||||
if (is_null($file)) { |
|
||||
$this->file = ['name' => date('Ymd-His'), 'part' => 1]; |
|
||||
} else { |
|
||||
if (!array_key_exists("name", $file) && !array_key_exists("part", $file)) { |
|
||||
$this->file = $file['1']; |
|
||||
} else { |
|
||||
$this->file = $file; |
|
||||
} |
|
||||
} |
|
||||
return $this; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 数据库表列表 |
|
||||
* |
|
||||
* @param null $table |
|
||||
* @param int $type |
|
||||
* @return array |
|
||||
*/ |
|
||||
public function dataList($table = null, $type = 1) |
|
||||
{ |
|
||||
if (is_null($table)) { |
|
||||
$list = Db::query("SHOW TABLE STATUS"); |
|
||||
} else { |
|
||||
if ($type) { |
|
||||
$list = Db::query("SHOW FULL COLUMNS FROM {$table}"); |
|
||||
} else { |
|
||||
$list = Db::query("show columns from {$table}"); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return array_map('array_change_key_case', $list); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 数据库备份文件列表 |
|
||||
* |
|
||||
* @return array |
|
||||
*/ |
|
||||
public function fileList() |
|
||||
{ |
|
||||
if (!is_dir($this->config['path'])) { |
|
||||
mkdir($this->config['path'], 0755, true); |
|
||||
} |
|
||||
$path = realpath($this->config['path']); |
|
||||
$flag = \FilesystemIterator::KEY_AS_FILENAME; |
|
||||
$glob = new \FilesystemIterator($path, $flag); |
|
||||
$list = array(); |
|
||||
foreach ($glob as $name => $file) { |
|
||||
if (preg_match('/^\\d{8,8}-\\d{6,6}-\\d+\\.sql(?:\\.gz)?$/', $name)) { |
|
||||
$name1 = $name; |
|
||||
$name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d'); |
|
||||
$date = "{$name[0]}-{$name[1]}-{$name[2]}"; |
|
||||
$time = "{$name[3]}:{$name[4]}:{$name[5]}"; |
|
||||
$part = $name[6]; |
|
||||
if (isset($list["{$date} {$time}"])) { |
|
||||
$info = $list["{$date} {$time}"]; |
|
||||
$info['part'] = max($info['part'], $part); |
|
||||
$info['size'] = $info['size'] + $file->getSize(); |
|
||||
} else { |
|
||||
$info['part'] = $part; |
|
||||
$info['size'] = $file->getSize(); |
|
||||
} |
|
||||
$extension = strtoupper(pathinfo($file->getFilename(), PATHINFO_EXTENSION)); |
|
||||
$info['name'] = $name1; |
|
||||
$info['compress'] = $extension === 'SQL' ? '-' : $extension; |
|
||||
$info['time'] = strtotime("{$date} {$time}"); |
|
||||
$list["{$date} {$time}"] = $info; |
|
||||
} |
|
||||
} |
|
||||
return $list; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取文件名称 |
|
||||
* |
|
||||
* @param string $type |
|
||||
* @param int $time |
|
||||
* @return array|false|mixed|string |
|
||||
* @throws \Exception |
|
||||
*/ |
|
||||
public function getFile($type = '', $time = 0) |
|
||||
{ |
|
||||
// |
|
||||
if (!is_numeric($time)) { |
|
||||
throw new \Exception("{$time} Illegal data type"); |
|
||||
} |
|
||||
switch ($type) { |
|
||||
case 'time': |
|
||||
$name = date('Ymd-His', $time).'-*.sql*'; |
|
||||
$path = realpath($this->config['path']).DIRECTORY_SEPARATOR.$name; |
|
||||
return glob($path); |
|
||||
break; |
|
||||
case 'timeverif': |
|
||||
$name = date('Ymd-His', $time).'-*.sql*'; |
|
||||
$path = realpath($this->config['path']).DIRECTORY_SEPARATOR.$name; |
|
||||
$files = glob($path); |
|
||||
$list = array(); |
|
||||
foreach ($files as $name) { |
|
||||
$basename = basename($name); |
|
||||
$match = sscanf($basename, '%4s%2s%2s-%2s%2s%2s-%d'); |
|
||||
$gz = preg_match('/^\\d{8,8}-\\d{6,6}-\\d+\\.sql.gz$/', $basename); |
|
||||
$list[$match[6]] = array($match[6], $name, $gz); |
|
||||
} |
|
||||
$last = end($list); |
|
||||
if (count($list) === $last[0]) { |
|
||||
return $list; |
|
||||
} else { |
|
||||
throw new \Exception("File {$files['0']} may be damaged, please check again"); |
|
||||
} |
|
||||
break; |
|
||||
case 'pathname': |
|
||||
return "{$this->config['path']}{$this->file['name']}-{$this->file['part']}.sql"; |
|
||||
break; |
|
||||
case 'filename': |
|
||||
return "{$this->file['name']}-{$this->file['part']}.sql"; |
|
||||
break; |
|
||||
case 'filepath': |
|
||||
return $this->config['path']; |
|
||||
break; |
|
||||
default: |
|
||||
$arr = array( |
|
||||
'pathname' => "{$this->config['path']}{$this->file['name']}-{$this->file['part']}.sql", |
|
||||
'filename' => "{$this->file['name']}-{$this->file['part']}.sql", |
|
||||
'filepath' => $this->config['path'], 'file' => $this->file |
|
||||
); |
|
||||
return $arr; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 删除备份文件 |
|
||||
* |
|
||||
* @param $time |
|
||||
* @return mixed |
|
||||
* @throws \Exception |
|
||||
*/ |
|
||||
public function delFile($time) |
|
||||
{ |
|
||||
if ($time) { |
|
||||
$file = $this->getFile('time', $time); |
|
||||
array_map("unlink", $file); |
|
||||
$file = $this->getFile('time', $time); |
|
||||
if (count($file)) { |
|
||||
throw new \Exception("File ".implode('##', $file)." deleted failed"); |
|
||||
} else { |
|
||||
return $time; |
|
||||
} |
|
||||
} else { |
|
||||
throw new \Exception("{$time} Time parameter is incorrect"); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 下载备份 |
|
||||
* |
|
||||
* @param string $time |
|
||||
* @param integer $part |
|
||||
* @return array|mixed|string |
|
||||
*/ |
|
||||
public function downloadFile($time, $part = 0) |
|
||||
{ |
|
||||
$file = $this->getFile('time', $time); |
|
||||
$fileName = $file[$part]; |
|
||||
if (file_exists($fileName)) { |
|
||||
ob_end_clean(); |
|
||||
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); |
|
||||
header('Content-Description: File Transfer'); |
|
||||
header('Content-Type: application/octet-stream'); |
|
||||
header('Content-Length: '.filesize($fileName)); |
|
||||
header('Content-Disposition: attachment; filename='.basename($fileName)); |
|
||||
readfile($fileName); |
|
||||
} else { |
|
||||
throw new \Exception("{$time} File is abnormal"); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public function setSqlMode() { |
|
||||
Db::query("SET sql_mode = '';"); |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 导入表 |
|
||||
* |
|
||||
* @param $start |
|
||||
* @param $time |
|
||||
* @return array|false|int |
|
||||
* @throws Exception |
|
||||
*/ |
|
||||
public function import($start, $time) |
|
||||
{ |
|
||||
//还原数据 |
|
||||
$this->file = $this->getFile('time', $time); |
|
||||
if ($this->config['compress']) { |
|
||||
$gz = gzopen($this->file[0], 'r'); |
|
||||
$size = 0; |
|
||||
} else { |
|
||||
$size = filesize($this->file[0]); |
|
||||
$gz = fopen($this->file[0], 'r'); |
|
||||
} |
|
||||
$sql = ''; |
|
||||
if ($start) { |
|
||||
$this->config['compress'] ? gzseek($gz, $start) : fseek($gz, $start); |
|
||||
} |
|
||||
for ($i = 0; $i < 1000; $i++) { |
|
||||
$sql .= $this->config['compress'] ? gzgets($gz) : fgets($gz); |
|
||||
if (preg_match('/.*;$/', trim($sql))) { |
|
||||
if (false !== Db::query($sql)) { |
|
||||
$start += strlen($sql); |
|
||||
} else { |
|
||||
return false; |
|
||||
} |
|
||||
$sql = ''; |
|
||||
} elseif ($this->config['compress'] ? gzeof($gz) : feof($gz)) { |
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
return array($start, $size); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 写入初始数据 |
|
||||
* |
|
||||
* @return boolean true - 写入成功,false - 写入失败 |
|
||||
*/ |
|
||||
public function backupInit() |
|
||||
{ |
|
||||
$sql = "-- -----------------------------\n"; |
|
||||
$sql .= "-- Think MySQL Data Transfer \n"; |
|
||||
$sql .= "-- \n"; |
|
||||
$sql .= "-- Host : ".$this->dbconfig['hostname']."\n"; |
|
||||
$sql .= "-- Port : ".$this->dbconfig['hostport']."\n"; |
|
||||
$sql .= "-- Database : ".$this->dbconfig['database']."\n"; |
|
||||
$sql .= "-- \n"; |
|
||||
$sql .= "-- Part : #{$this->file['part']}\n"; |
|
||||
$sql .= "-- Date : ".date("Y-m-d H:i:s")."\n"; |
|
||||
$sql .= "-- -----------------------------\n\n"; |
|
||||
$sql .= "SET FOREIGN_KEY_CHECKS = 0;\n\n"; |
|
||||
return $this->write($sql); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 查询单条 |
|
||||
* @param $sql |
|
||||
* @return array|mixed |
|
||||
*/ |
|
||||
public function selectOne($sql) { |
|
||||
$result = Db::query($sql); |
|
||||
return $result[0] ?? []; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 备份表结构 |
|
||||
* |
|
||||
* @param string $table 表名 |
|
||||
* @param integer $start 起始行数 |
|
||||
* @return boolean false - 备份失败 |
|
||||
*/ |
|
||||
public function backup($table, $start = 0) |
|
||||
{ |
|
||||
// 备份表结构 |
|
||||
if (0 == $start) { |
|
||||
$result = $this->selectOne("SHOW CREATE TABLE `{$table}`"); |
|
||||
$sql = "\n"; |
|
||||
$sql .= "-- -----------------------------\n"; |
|
||||
$sql .= "-- Table structure for `{$table}`\n"; |
|
||||
$sql .= "-- -----------------------------\n"; |
|
||||
$sql .= "DROP TABLE IF EXISTS `{$table}`;\n"; |
|
||||
$sql .= trim($result['Create Table']).";\n\n"; |
|
||||
if (false === $this->write($sql)) { |
|
||||
return false; |
|
||||
} |
|
||||
} |
|
||||
//数据总数 |
|
||||
$result = $this->selectOne("SELECT COUNT(*) AS count FROM `{$table}`"); |
|
||||
$count = $result['count']; |
|
||||
//备份表数据 |
|
||||
if ($count) { |
|
||||
//写入数据注释 |
|
||||
if (0 == $start) { |
|
||||
$sql = "-- -----------------------------\n"; |
|
||||
$sql .= "-- Records of `{$table}`\n"; |
|
||||
$sql .= "-- -----------------------------\n"; |
|
||||
$this->write($sql); |
|
||||
} |
|
||||
//备份数据记录 |
|
||||
$result = Db::query("SELECT * FROM `{$table}` LIMIT {$start}, 1000"); |
|
||||
$sql = "INSERT INTO `{$table}` VALUES\n"; |
|
||||
foreach ($result as $index => $row) { |
|
||||
$row = array_map(function ($item){ |
|
||||
return is_string($item) ? addslashes($item) : $item; |
|
||||
}, $row); |
|
||||
$sql .= "('".str_replace(array("\r", "\n"), array('\\r', '\\n'), |
|
||||
implode("', '", $row))."')"; |
|
||||
$sql .= $index < (count($result) - 1) ? ",\n" : ";\n"; |
|
||||
} |
|
||||
|
|
||||
if (false === $this->write($sql)) { |
|
||||
return false; |
|
||||
} |
|
||||
//还有更多数据 |
|
||||
if ($count > $start + 1000) { |
|
||||
return $this->backup($table, $start + 1000); |
|
||||
} |
|
||||
} |
|
||||
//备份下一表 |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 优化表 |
|
||||
* |
|
||||
* @param String $tables 表名 |
|
||||
* @return String $tables |
|
||||
*/ |
|
||||
public function optimize($tables = null) |
|
||||
{ |
|
||||
if ($tables) { |
|
||||
if (is_array($tables)) { |
|
||||
$tables = implode('`,`', $tables); |
|
||||
$list = db ::select("OPTIMIZE TABLE `{$tables}`"); |
|
||||
} else { |
|
||||
$list = Db::query("OPTIMIZE TABLE `{$tables}`"); |
|
||||
} |
|
||||
if ($list) { |
|
||||
return $tables; |
|
||||
} else { |
|
||||
throw new \Exception("data sheet'{$tables}'Repair mistakes please try again!"); |
|
||||
} |
|
||||
} else { |
|
||||
throw new \Exception("Please specify the table to be repaired!"); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 修复表 |
|
||||
* |
|
||||
* @param String $tables 表名 |
|
||||
* @return String $tables |
|
||||
*/ |
|
||||
public function repair($tables = null) |
|
||||
{ |
|
||||
if ($tables) { |
|
||||
if (is_array($tables)) { |
|
||||
$tables = implode('`,`', $tables); |
|
||||
$list = Db::query("REPAIR TABLE `{$tables}`"); |
|
||||
} else { |
|
||||
$list = Db::query("REPAIR TABLE `{$tables}`"); |
|
||||
} |
|
||||
if ($list) { |
|
||||
|
|
||||
return $list; |
|
||||
} else { |
|
||||
throw new \Exception("data sheet'{$tables}'Repair mistakes please try again!"); |
|
||||
} |
|
||||
} else { |
|
||||
throw new \Exception("Please specify the table to be repaired!"); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 写入SQL语句 |
|
||||
* |
|
||||
* @param string $sql 要写入的SQL语句 |
|
||||
* @return boolean true - 写入成功,false - 写入失败! |
|
||||
*/ |
|
||||
private function write($sql) |
|
||||
{ |
|
||||
$size = strlen($sql); |
|
||||
//由于压缩原因,无法计算出压缩后的长度,这里假设压缩率为50%, |
|
||||
//一般情况压缩率都会高于50%; |
|
||||
$size = $this->config['compress'] ? $size / 2 : $size; |
|
||||
$this->open($size); |
|
||||
return $this->config['compress'] ? @gzwrite($this->fp, $sql) : @fwrite($this->fp, $sql); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 打开一个卷,用于写入数据 |
|
||||
* |
|
||||
* @param integer $size 写入数据的大小 |
|
||||
*/ |
|
||||
private function open($size) |
|
||||
{ |
|
||||
if ($this->fp) { |
|
||||
$this->size += $size; |
|
||||
if ($this->size > $this->config['part']) { |
|
||||
$this->config['compress'] ? @gzclose($this->fp) : @fclose($this->fp); |
|
||||
$this->fp = null; |
|
||||
$this->file['part']++; |
|
||||
session('backup_file', $this->file); |
|
||||
$this->backupInit(); |
|
||||
} |
|
||||
} else { |
|
||||
$backuppath = $this->config['path']; |
|
||||
$filename = "{$backuppath}{$this->file['name']}-{$this->file['part']}.sql"; |
|
||||
if ($this->config['compress']) { |
|
||||
$filename = "{$filename}.gz"; |
|
||||
$this->fp = @gzopen($filename, "a{$this->config['level']}"); |
|
||||
} else { |
|
||||
$this->fp = @fopen($filename, 'a'); |
|
||||
} |
|
||||
$this->size = filesize($filename) + $size; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 检查目录是否可写 |
|
||||
* |
|
||||
* @param string $path 目录 |
|
||||
* @return boolean |
|
||||
*/ |
|
||||
protected function checkPath($path) |
|
||||
{ |
|
||||
if (is_dir($path)) { |
|
||||
return true; |
|
||||
} |
|
||||
if (mkdir($path, 0755, true)) { |
|
||||
return true; |
|
||||
} else { |
|
||||
return false; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 析构方法,用于关闭文件资源 |
|
||||
*/ |
|
||||
public function __destruct() |
|
||||
{ |
|
||||
if ($this->fp) { |
|
||||
$this->config['compress'] ? @gzclose($this->fp) : @fclose($this->fp); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
File diff suppressed because it is too large
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue