安全(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(市场 / 开发者中心 / 审核 / 分润)
140 lines
4.5 KiB
PHP
140 lines
4.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace addon\paycenter\library;
|
|
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 支付流水读写(wxapp_paycenter_trade)。
|
|
*
|
|
* 与业务订单的关系:插件只记录「这笔钱怎么收的」(渠道 / 场景 / 网关交易号 / 回调),
|
|
* 业务订单(如 appmall_addon_orders)仍由业务自己持有,两边靠 trade_no 关联。
|
|
* 这样插件卸载不会带走业务订单,业务换支付渠道也不用改自己的表。
|
|
*/
|
|
class TradeLog
|
|
{
|
|
/** 下单留痕(幂等:同 trade_no 只写一次) */
|
|
public static function record(array $order, string $channel, string $scene): void
|
|
{
|
|
Schema::ensure();
|
|
|
|
$tradeNo = (string) ($order['trade_no'] ?? '');
|
|
if ($tradeNo === '') {
|
|
return;
|
|
}
|
|
$exists = self::find($tradeNo);
|
|
if ($exists) {
|
|
return;
|
|
}
|
|
try {
|
|
Db::name('paycenter_trade')->insert([
|
|
'trade_no' => $tradeNo,
|
|
'biz' => (string) ($order['biz'] ?? ''),
|
|
'biz_id' => (int) ($order['biz_id'] ?? 0),
|
|
'channel' => $channel,
|
|
'scene' => $scene,
|
|
'subject' => mb_substr((string) ($order['subject'] ?? ''), 0, 200),
|
|
'amount' => (float) ($order['amount'] ?? 0),
|
|
'status' => 0,
|
|
'attach' => mb_substr((string) json_encode($order['attach'] ?? [], JSON_UNESCAPED_UNICODE), 0, 500),
|
|
'create_at' => time(),
|
|
'update_at' => time(),
|
|
]);
|
|
} catch (\Throwable $e) {
|
|
trace('[paycenter] 流水写入失败:' . $e->getMessage(), 'error');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 回调到达:流水不存在时按回调内容补建(业务未走插件下单 / 插件重装过)。
|
|
*/
|
|
public static function touchNotify(array $data, string $channel): ?array
|
|
{
|
|
Schema::ensure();
|
|
|
|
$tradeNo = (string) ($data['trade_no'] ?? '');
|
|
if ($tradeNo === '') {
|
|
return null;
|
|
}
|
|
$trade = self::find($tradeNo);
|
|
if (!$trade) {
|
|
try {
|
|
Db::name('paycenter_trade')->insert([
|
|
'trade_no' => $tradeNo,
|
|
'channel' => $channel,
|
|
'amount' => (float) ($data['amount'] ?? 0),
|
|
'gateway_no' => (string) ($data['gateway_no'] ?? ''),
|
|
'status' => 0,
|
|
'notify_at' => time(),
|
|
'create_at' => time(),
|
|
'update_at' => time(),
|
|
]);
|
|
} catch (\Throwable $e) {
|
|
trace('[paycenter] 回调补建流水失败:' . $e->getMessage(), 'error');
|
|
}
|
|
|
|
return self::find($tradeNo);
|
|
}
|
|
|
|
try {
|
|
Db::name('paycenter_trade')->where('trade_no', $tradeNo)->update([
|
|
'notify_at' => time(),
|
|
'update_at' => time(),
|
|
]);
|
|
} catch (\Throwable) {
|
|
// 更新失败不影响发货
|
|
}
|
|
|
|
return $trade;
|
|
}
|
|
|
|
/** 标记已支付,返回最新流水 */
|
|
public static function markPaid(array $data): ?array
|
|
{
|
|
$tradeNo = (string) ($data['trade_no'] ?? '');
|
|
if ($tradeNo === '') {
|
|
return null;
|
|
}
|
|
try {
|
|
Db::name('paycenter_trade')->where('trade_no', $tradeNo)->update([
|
|
'status' => 1,
|
|
'gateway_no' => (string) ($data['gateway_no'] ?? ''),
|
|
'pay_at' => time(),
|
|
'notify_at' => time(),
|
|
'update_at' => time(),
|
|
]);
|
|
} catch (\Throwable $e) {
|
|
trace('[paycenter] 流水置已付失败:' . $e->getMessage(), 'error');
|
|
}
|
|
|
|
return self::find($tradeNo);
|
|
}
|
|
|
|
public static function markRefunded(string $tradeNo): void
|
|
{
|
|
try {
|
|
Db::name('paycenter_trade')->where('trade_no', $tradeNo)->update([
|
|
'status' => 2,
|
|
'update_at' => time(),
|
|
]);
|
|
} catch (\Throwable) {
|
|
// 忽略
|
|
}
|
|
}
|
|
|
|
public static function find(string $tradeNo): ?array
|
|
{
|
|
if ($tradeNo === '') {
|
|
return null;
|
|
}
|
|
try {
|
|
$row = Db::name('paycenter_trade')->where('trade_no', $tradeNo)->find();
|
|
} catch (\Throwable) {
|
|
return null;
|
|
}
|
|
|
|
return $row ? (array) $row : null;
|
|
}
|
|
}
|