feat: 上线前安全加固与发布工程化;appmall 由插件迁移为独立应用

安全(P0)
- 发布包签名:新增 scripts/package_keygen.php、scripts/package_verify.php、
  ywxapp\service\PackageVerifier;FrameworkService::apply() 解压前强制验签
  (ywxapp.framework_package_verify,默认开启)
- JWT 收紧:config/jwt.php 移除公开默认密钥,JwtService::assertStrongSecret()
  校验非空 / 长度≥32 / 已知弱值;.env.production.example 键名由 JWT_SECRET_KEY 修正为 JWT_SECRET
- /api/v1/Article:免登录白名单收窄为只读接口,写操作字段白名单 + assertOwner() 越权校验
- 开发者令牌:查找接口不再回显明文、统一失败文案 + 限流
- TemplateInstaller:文件名白名单 + realpath 归一化 + 目录内断言,修复 Zip Slip;补 use ZipArchive
- 后台登录:接入验证码、失败锁定与登录限流(config/ratelimit.php)
- 缓存 / Session 驱动可由 .env 覆盖(CACHE_DRIVER / SESSION_TYPE),集群部署改 redis
- paycenter 支付日志开关改为 PAY_LOG,不再跟随 APP_DEBUG

工程化 / 交付
- 新增 CHANGELOG.md 与 .env.production.example;composer.lock 入库锁定依赖版本
- 插件离线安装 CLI 增加 --uid,后台上传安装透传 uid,付费插件授权校验可通过
- 授权拒绝文案区分「未携带 uid」与「未找到有效授权」,便于排障
- .gitignore 放行 .env.production.example / .env.addon.example / .gitattributes / public/.htaccess

结构
- appmall 由 addon/appmall 迁移为独立应用 app/appmall(市场 / 开发者中心 / 审核 / 分润)
This commit is contained in:
yangwx committed 2026-10-22 00:53:39 +08:00
1 parent 1d49e6f5ee
commit 18101cf11a
636 files changed
+58517 -9519

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ use ywxapp\library\Menu;
use ywxapp\AddonBase;
use think\Request;
class Addon extends addon
class Addon extends AddonBase
{
/**
* 插件安装方法
+36
View File
@@ -0,0 +1,36 @@
<?php
declare (strict_types = 1);
namespace addon\demo\controller\api;
use ywxapp\service\ScoreService;
/**
* 插件调用积分规则引擎示例
*
* 路由:GET /demo/api/score/checkin?uid=1
* 说明:插件无需关心规则表,只管 trigger() 自己的动作;
* 分值/限次/去重全部由后台规则(或插件注入的默认规则)决定。
*/
class Score extends \ywxapp\controller\ApiBase
{
protected $noNeedLogin = ['*'];
protected $noNeedVerify = ['*'];
public function checkin()
{
$uid = (int) $this->request->param('uid/d', 0);
if ($uid <= 0) {
$this->result->apiError('缺少 uid 参数', 1);
}
$res = ScoreService::trigger('demo.checkin', $uid, [
'date' => date('Y-m-d'),
], [
'source' => 'demo',
'source_id' => 'checkin-' . $uid . '-' . date('Ymd'),
]);
$this->result->apiSuccess($res, $res['msg'] ?: 'ok');
}
}
+2 -2
View File
@@ -11,13 +11,13 @@ class Index extends \ywxapp\controller\BackendBase
* Summary of needLogin
* @var array
*/
protected $noNeedLogin = ['*'];
protected $noNeedLogin = [];
/**
* Summary of needRight
* @var array
*/
protected $noNeedVerify = ['*'];
protected $noNeedVerify = [];
/**
* 控制器初始化 _initialize
+35 -25
View File
@@ -1,30 +1,40 @@
<?php
//这是demo应用的配置文件
return [
'name' => 'demo',
'title' => '',
'intro' => '',
'author' => '',
'website' => '',
'version' => '1.0.0',
'state' => 1,
'url' => '/demo',
'license' => '',
'licenseto' => 0,
'config' => [],
'events' => [
// 事件绑定,
'bind' => [],
// 事件监听
'listen' => [],
// 事件订阅
'subscribe' => [],
'name' => 'demo',
'title' => '',
'intro' => '',
'author' => '',
'website' => '',
'version' => '1.0.0',
'state' => 1,
'url' => '/demo',
'license' => '',
'licenseto' => 0,
'config' => [
],
'events' => [
'bind' =>
[
],
'listen' =>
[
],
'subscribe' =>
[
0 => 'addon\\demo\\subscribe\\Score',
1 => 'addon\\demo\\subscribe\\Hook',
],
],
'middleware' => [
// 别名 => 中间件类
'alias' => [],
// 中间件优先级,越靠前优先级越高
'priority' => [],
'alias' =>
[
],
'priority' =>
[
],
],
'services' => [],
];
'services' => [
],
'update_time' => 1790688171,
];
+2
View File
@@ -18,6 +18,8 @@ use think\facade\Route;
// API → apaddonp\demo\controller\api\Index
Route::group('api', function () {
Route::get('index/index', 'index/index')->name('demo_api_index');
// 积分规则引擎调用示例:/demo/api/score/checkin?uid=1
Route::get('score/checkin', 'score/checkin')->name('demo_api_score_checkin');
})->namespace('addon\demo\controller\api');
// 前台 → addon\demo\controller\Index(不加子分组)
+57
View File
@@ -0,0 +1,57 @@
<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: ywxapp<admin@ywxapp.cn>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace addon\demo\subscribe;
use ywxapp\service\HookService;
/**
* 模板钩子订阅器(插件侧接入示例)
*
* eventPrefix='Hook' => onRender() 监听 HookRender(收集型事件)
* 需在 info.php 的 events.subscribe 中声明本类(见 addon/demo/info.php)。
*
* 两种挂载方式,可混用:
* 1. 声明式:HookService::mount('钩子名', 'demo@hook/xxx') —— 可排序、能在后台「模板钩子」页枚举到
* 2. 事件式:onRender() 按 $payload['name'] 返回 HTML —— 适合需要运行时判断的场景
*
* 铁律:不输出就返回空字符串,千万别返回 false —— think\Event::trigger()
* 遇到 false 会 break,排在后面的插件输出会全部丢失。
*/
class Hook
{
protected $eventPrefix = 'Hook';
public function __construct()
{
// 声明式挂载:模板 addon/demo/view/hook/score-toolbar.html
HookService::mount('backend.score.toolbar', 'demo@hook/score-toolbar');
}
/**
* HookRender:收集型事件,返回值会被拼进模板埋点
*
* @param array $payload ['name' => 钩子名, 'vars' => 模板变量]
* @return string|array 字符串,或 ['html' => '...']
*/
public function onRender($payload)
{
$name = (string) ($payload['name'] ?? '');
switch ($name) {
case 'backend.score.form':
return '<div class="layui-form-mid layui-word-aux">示例插件注入:规则保存后可在此扩展玩法</div>';
case 'backend.layout.body_end':
return '<!-- demo 插件在后台页尾注入 -->';
}
return '';
}
}
+92
View File
@@ -0,0 +1,92 @@
<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: ywxapp<admin@ywxapp.cn>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace addon\demo\subscribe;
use think\facade\Log;
use ywxapp\service\ScoreService;
/**
* 积分规则引擎订阅器(插件侧接入示例)
*
* eventPrefix='Score' => onBefore() 监听 ScoreBefore、onAfter() 监听 ScoreAfter
* 需在 info.php 的 events.subscribe 中声明本类(见 addon/demo/info.php)。
*
* 三种接入姿势:
* 1. 注册自己的动作:ScoreService::registerAction(),后台「触发动作」下拉即可选到
* 2. 改分/取消/注入规则:onBefore() 返回 int 或 ['value'=>n] 覆盖分值、
* false 或 ['cancel'=>true] 取消、['rules'=>[...]] 注入临时规则
* 3. 发放后联动:onAfter() 拿到 rule/value/uid 做通知、成就、等级等
*
* 主动发放(不需要事件):
* ScoreService::trigger('demo.checkin', $uid, ['date'=>date('Y-m-d')],
* ['source'=>'demo', 'source_id'=>'checkin-'.$uid.'-'.date('Ymd')]);
*/
class Score
{
protected $eventPrefix = 'Score';
public function __construct()
{
// 本插件动作注册到后台下拉(插件启用后才可见)
ScoreService::registerAction('demo.checkin', '示例-每日签到', 'demo');
}
/**
* ScoreBefore:发放前干预
*
* @param array $payload ['action','uid','context','source','source_id','rules']
* @return array|int|null
*/
public function onBefore($payload)
{
ScoreService::registerAction('demo.checkin', '示例-每日签到', 'demo');
$action = (string) ($payload['action'] ?? '');
$rules = $payload['rules'] ?? [];
// 示例1:本插件动作在后台没配规则时,动态注入一条默认规则(每日1次、按来源ID去重)
if ($action === 'demo.checkin' && empty($rules)) {
return [
'rules' => [[
'id' => 0,
'title' => '示例签到',
'type' => 1,
'value' => 5,
'limit_type' => ScoreService::LIMIT_DAY,
'limit_times' => 1,
'unique_type' => 1,
'remark' => '示例签到 {date}',
]],
];
}
// 示例2:周末双倍(仅对「获取」类规则生效)
$first = $rules[0] ?? null;
if ($first && (int) ($first['type'] ?? 1) === 1 && in_array(date('w'), ['0', '6'], true)) {
return ['value' => (int) ($first['value'] ?? 0) * 2];
}
return null;
}
/**
* ScoreAfter:发放后联动
*
* @param array $payload ['action','uid','context','source','source_id','rule','value']
*/
public function onAfter($payload): void
{
Log::info('[demo][ScoreAfter] uid=' . ($payload['uid'] ?? 0)
. ' action=' . ($payload['action'] ?? '')
. ' value=' . ($payload['value'] ?? 0)
. ' rule=' . ($payload['rule']['title'] ?? '-'));
}
}
+4
View File
@@ -0,0 +1,4 @@
<!-- 插件通过 HookService::mount('backend.score.toolbar', 'demo@hook/score-toolbar') 注入到积分规则列表工具栏 -->
<span class="layui-badge layui-bg-cyan" style="line-height:26px;margin-left:4px;" title="由 addon/demo 插件模板钩子注入">
插件钩子注入
</span>