sqlite-web 0.7.2
gitea.db
issue
Create
Query
access
access_token
action
action_artifact
action_run
action_run_index
action_run_job
action_runner
action_runner_token
action_schedule
action_schedule_spec
action_task
action_task_output
action_task_step
action_tasks_version
action_variable
app_state
attachment
auth_token
badge
branch
collaboration
comment
commit_status
commit_status_index
commit_status_summary
commit_sync_log
commit_sync_status
dbfs_data
dbfs_meta
deploy_key
email_address
email_hash
external_login_user
follow
gpg_key
gpg_key_import
hook_task
issue
issue_assignees
issue_content_history
issue_dependency
issue_index
issue_label
issue_pin
issue_user
issue_watch
label
language_stat
lfs_lock
lfs_meta_object
login_source
milestone
mirror
notice
notification
oauth2_application
oauth2_authorization_code
oauth2_grant
org_user
package
package_blob
package_blob_upload
package_cleanup_rule
package_file
package_property
package_version
project
project_board
project_issue
protected_branch
protected_tag
public_key
pull_auto_merge
pull_request
push_mirror
reaction
release
renamed_branch
repo_archiver
repo_hidden_file
repo_indexer_status
repo_license
repo_redirect
repo_topic
repo_transfer
repo_unit
repository
review
review_state
secret
session
sqlite_sequence
star
stopwatch
system_setting
task
team
team_invite
team_repo
team_unit
team_user
topic
tracked_time
two_factor
upload
user
user_badge
user_blocking
user_open_id
user_redirect
user_setting
version
watch
webauthn_credential
webhook
Toggle helper tables
Structure
Content
Query
Insert
Drop
Import
Export
Delete row 284 from issue
id
284
repo_id
21
index
66
poster_id
1
original_author
original_author_id
0
name
🔍 代码审查报告:pay-260519 - Merge remote-tracking branch
🔍 代码审查报告:pay-260519 - Merge remote-tracking branch 'pay/pay-260519' into
...
content
## 自动代码审查报告 **分支**: pay-260519 **提交**: `2bff7d95d
## 自动代码审查报告 **分支**: pay-260519 **提交**: `2bff7d95dc470de71955de8e943db93119d7af02` **提交人**: zhangjunnan (121158035@qq.com) **时间**: 2026-05-22 10:48:39 --- ## 1. 审查摘要 - **代码质量评分**:5.5 / 10 分 - **总体评价**:代码实现了多业务线的微信退款核心流程,具备基本的参数校验与日志记录能力。但存在严重的逻辑漏洞(恒真条件拦截)、硬编码安全密钥、大量重复代码、破坏框架生命周期的输出方式以及浮点数精度隐患。整体可维护性与健壮性较弱,需进行结构性重构。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `OrderWxRefund.php` ~L240 | `refundQuery()` 中条件判断逻辑恒为真:`if (isset($param['order_id']) \|\| empty($param['order_id']))`。无论参数是否存在,该条件均成立,导致所有正常请求被错误拦截。 | 修正逻辑运算符,改为非空校验。 | `if (!isset($param['order_id']) \|\| empty($param['order_id'])) { $this->error_response('订单号不为空'); }` | | 🔴 严重 | `OrderWxRefund.php` ~L10, L155, L210 | 退款密钥校验使用硬编码盐值 `'1441600902'` 和 `'1621353600'`。一旦代码泄露,攻击者可伪造合法退款请求,造成资金损失。 | 将盐值迁移至 `application/config/config.php` 或环境变量,通过 `config_item()` 读取。 | `if ($param['refund_key'] !== md5($param['order_id'] . $param['trade_no'] . config_item('refund_verify_salt'))) { ... }` | | 🟠 警告 | `OrderWxRefund.php` ~L15-25 | `$_REQUEST['json']` 或 `php://input` 直接 `json_decode`,未校验 JSON 格式。非法 JSON 会导致 `$this->stream` 为 `null`,后续访问 `$this->stream['request']` 触发 `Fatal Error`。 | 增加 `json_last_error()` 校验,或统一使用 CI 的 `$this->input->raw_input_stream`。 | `$raw = $_REQUEST['json'] ?? file_get_contents('php://input'); $this->stream = json_decode($raw, true); if (json_last_error() !== JSON_ERROR_NONE) { $this->error_response('请求数据格式错误'); }` | | 🟠 警告 | `OrderWxRefund.php` ~L130, L275, L315 | 退款单号 `out_refund_no` 使用 `date("YmdHis")` 生成。高并发场景下同一秒内多次请求会导致单号重复,微信接口将拒绝退款。 | 追加微秒时间戳或 `uniqid()` 确保全局唯一。 | `$input->SetOut_refund_no(WxPayConfig::MCHID . date("YmdHis") . substr(microtime(true), 2, 6));` | | 🟠 警告 | `OrderWxRefund.php` ~L75, L95 | 直接修改请求参数 `$param['total_fee'] = $pay_list['_actual_pay'];`。污染原始请求数据,影响后续日志记录与审计追踪。 | 使用独立变量接收计算后的金额,保持 `$param` 只读。 | `$actual_total_fee = $pay_list['_actual_pay'] ?? $param['total_fee'];` | | 🟠 警告 | `OrderWxRefund.php` 全文件 | `doRefund`、`platformIncomeRefund`、`repairRefund`、`haizanAppRefund` 中存在大量重复的参数校验、金额转换、响应组装逻辑,违反 DRY 原则。 | 提取基类方法 `validateRefundParams()`、`buildRefundResponse()`,或采用策略模式按 `type` 分发处理。 | `protected function validateRefundParams(array $param, array $allowedFrom, array $allowedType) { ... }` | | 🟡 建议 | `OrderWxRefund.php` ~L350 | `jsonEcho()` 使用 `ob_end_clean(); ob_start(); ... die();` 强行接管输出,破坏 CI 框架的 Output 类生命周期,且 `exit()` 与 `die()` 冗余。 | 使用 CI 标准输出方式,移除缓冲区操作,保持框架完整性。 | `$this->output->set_content_type('application/json')->set_output(json_encode(['header' => $this->stream['header'], 'response' => $response])); return;` | | 🟡 建议 | `Ahead_book_order_model.php` ~L100 | 事务回滚逻辑与 CI3 事务管理器冲突。`$this->db->trans_start()` 配合 `try-catch` 手动 `trans_rollback()` 易导致事务状态机异常。 | 移除 `catch` 中的手动回滚,依赖 CI 的 `trans_complete()` 自动回滚机制,或改用原生 PDO 事务。 | `try { ... } catch (Exception $e) { log_message('error', $e->getMessage()); throw $e; } // CI 会自动回滚` | | 🟡 建议 | `OrderWxRefund.php` ~L125 | 金额计算 `$param['total_fee'] * 100` 使用浮点数乘法,存在精度丢失风险(如 `0.1 * 100 = 10.000000000000002`)。 | 使用 `bcmul()` 进行高精度计算,或统一以“分”为单位存储与传输。 | `$total_fee = (int) bcmul((string)$param['total_fee'], '100', 0);` | | 🟡 建议 | 全文件多处 | 大量使用魔法数字(如状态码 `1, 2, 3, 4`、平台标识 `1, 3, 14`),降低代码可读性。 | 定义类常量或配置数组集中管理。 | `const STATUS_PAID = 1; const PAY_PLATFORM_WX = 1;` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **修复恒真拦截 Bug**:立即修正 `refundQuery()` 中的 `isset/empty` 逻辑,否则该接口完全不可用。 2. **移除硬编码密钥**:将退款校验盐值、商户号等敏感配置抽离至 `config/` 目录,并通过 `.env` 或服务器环境变量管理,杜绝代码库泄露风险。 3. **保障退款单号唯一性**:替换 `date("YmdHis")` 为带微秒或随机后缀的生成逻辑,避免高并发退款失败。 4. **修复 JSON 解析崩溃隐患**:在 `__construct()` 中增加 `json_last_error()` 校验,防止畸形请求导致 500 错误。 ### 🛠 后续重构与优化方向 1. **架构解耦(策略模式)**:当前 `doRefund()` 中长达 150+ 行的 `if-elseif` 分支严重违反开闭原则。建议按 `$param['type']` 映射到独立的退款策略类(如 `OrderRefundStrategy`, `VipRechargeRefundStrategy`),控制器仅负责路由与参数校验。 2. **统一响应与校验层**:提取 `BaseApiController`,封装 `validateParams()`、`success()`、`error()` 方法。移除 `ob_*` 和 `die()`,全面接入 CI 的 `$this->output` 组件。 3. **财务精度规范**:所有涉及金额的计算、存储、传输必须统一使用**整数分**或 `BCMath` 扩展。禁止直接使用浮点数进行加减乘除。 4. **事务安全规范**:CI3 的 `$this->db->trans_start()` 与 `$this->db->trans_complete()` 是成对设计的。建议在业务层仅使用 `trans_start()`,在 `catch` 中仅记录日志并抛出异常,由框架或上层统一处理回滚,避免状态混乱。 5. **框架适配提示**:代码中大量使用 `$this->load->model()` 动态加载。建议在 CI 的 `autoload.php` 中预加载高频模型,或在构造函数中统一加载,减少运行时 I/O 开销。 > 📝 **局限性说明**:本次审查基于提供的 `OrderWxRefund.php` 及部分截断的 Model 文件。由于 `Ahead_book_order_model.php`、`Ahead_shop_book_time_info_model.php` 等文件内容不完整,部分业务逻辑(如预订状态流转、团购券核销联动)未能进行全链路验证。建议在完整代码合并前,补充单元测试覆盖核心退款与事务分支。 --- *此 Issue 由代码审查服务自动创建*
...
milestone_id
0
priority
0
is_closed
0
is_pull
0
num_comments
0
ref
deadline_unix
0
created_unix
1779418119
updated_unix
1779418119
closed_unix
0
is_locked
0
content_version
0
time_estimate
0
Delete
Cancel