# CMS API 改造详情

## Api.php 修改（addons/cms/controller/Api.php）

### 第 51 行：去除 xss_clean
```
// 改前
$data = $this->request->post('', null, 'trim,xss_clean');
// 改后  
$data = $this->request->post('', null, 'trim');
```
原因：xss_clean 会删除 POST 中的 `channel_id` 字段，导致写入数据库失败。

### API key 校验（已注释）
删除了两处：
```php
//if (!$config['apikey']) {
//    $this->error('请先在后台配置API密钥');
//}
// if ($config['apikey'] != $apikey) {
//     $this->error('密钥不正确');
// }
```

### else 分支追加 channel_id
```php
} else {
    $channel_id = $this->request->request('channel_id');
    $channel = Channel::get($channel_id);
    if (!$channel || $channel['status'] != 'normal') {
        $this->error('栏目未找到');
    }
    $data['channel_id'] = $channel->id;   // ← 必须加这行
}
```
原因：$data 来自 xss_clean 过滤后的 POST，else 分支只查到 channel 对象但没把 channel_id 写回 $data。
