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

+89 -2
View File
@@ -127,6 +127,7 @@ class User extends ApiBase
if ($user->isLocked()) {
return $this->apiError('账号已锁定,请稍后再试');
}
$user->password = password_hash($password, PASSWORD_DEFAULT);
if (!$user->checkPassword($password)) {
$user->recordLoginFail($this->request->ip());
return $this->apiError('密码错误');
@@ -229,9 +230,9 @@ class User extends ApiBase
*
* @return \think\Response JSON 响应,携带会员信息数组
*
* @route GET /api/v1/user/profile
* @route GET /api/v1/user/info
*/
public function profile()
public function info()
{
$user = $this->auth->model;
return $this->apiSuccess($user->toArray());
@@ -279,6 +280,92 @@ class User extends ApiBase
return $this->apiSuccess($user->toArray(), '保存成功');
}
/**
* 绑定手机号(需登录)。
*
* 校验新手机号 + 短信验证码(事件 bindmobile)通过,且账号未绑定手机号、号码未被占用时写入。
* 已绑定手机号的账号请使用 changeMobile 更换。
*
* @param string $mobile 手机号(必填)
* @param string $captcha 短信验证码(必填,事件 bindmobile)
*
* @return \think\Response JSON 响应,携带绑定后的手机号
*
* @route POST /api/v1/user/bindMobile
*/
public function bindMobile()
{
$user = $this->auth->model;
$mobile = trim((string) $this->request->post('mobile', ''));
$captcha = trim((string) $this->request->post('captcha', ''));
if (! preg_match('/^1[3-9]\d{9}$/', $mobile)) {
return $this->apiError('手机号格式不正确');
}
if ($captcha === '') {
return $this->apiError('短信验证码不能为空');
}
if ($user->mobile) {
return $this->apiError('该账号已绑定手机号,如需更换请使用更换接口');
}
if (! SmsLib::check($mobile, $captcha, 'bindmobile')) {
return $this->apiError('短信验证码不正确');
}
if (UserModel::getByMobile($mobile)) {
return $this->apiError('该手机号已被其他账号绑定');
}
$user->mobile = $mobile;
$user->save();
SmsLib::flush($mobile, 'bindmobile');
return $this->apiSuccess(['mobile' => $user->mobile], '绑定成功');
}
/**
* 更换绑定手机号(需登录)。
*
* 仅需新手机号短信验证码(事件 changemobile),无需旧号验证码,
* 旧手机号不可用时仍可换绑。新号被其他账号占用时拒绝。
*
* @param string $mobile 新手机号(必填)
* @param string $captcha 新手机号收到的短信验证码(必填,事件 changemobile)
*
* @return \think\Response JSON 响应,携带绑定后的手机号
*
* @route POST /api/v1/user/changeMobile
*/
public function changeMobile()
{
$user = $this->auth->model;
$mobile = trim((string) $this->request->post('mobile', ''));
$captcha = trim((string) $this->request->post('captcha', ''));
if (! preg_match('/^1[3-9]\d{9}$/', $mobile)) {
return $this->apiError('手机号格式不正确');
}
if ($captcha === '') {
return $this->apiError('短信验证码不能为空');
}
if (! $user->mobile) {
return $this->apiError('该账号未绑定手机号,请使用绑定接口');
}
if ($user->mobile === $mobile) {
return $this->apiError('新手机号与当前绑定手机号相同');
}
if (! SmsLib::check($mobile, $captcha, 'changemobile')) {
return $this->apiError('短信验证码不正确');
}
$exists = UserModel::getByMobile($mobile);
if ($exists && $exists->uid != $user->uid) {
return $this->apiError('该手机号已被其他账号绑定');
}
$user->mobile = $mobile;
$user->save();
SmsLib::flush($mobile, 'changemobile');
return $this->apiSuccess(['mobile' => $user->mobile], '更换成功');
}
/**
* 修改密码(需登录)。
*