接入教程
1. 访问Scanii官网注册账号获取API密钥
2. 查阅官方文档了解API端点和请求格式
3. 使用HTTP客户端发送包含文件的POST请求进行扫描
4. 解析API响应,根据返回结果判断文件安全性
5. 根据业务需求处理安全或存在威胁的文件
使用Python提交文件扫描
import requests
url = 'https://api.example.com/v2/files'
headers = {
'Authorization': 'Bearer YOUR_API_KEY'
}
files = {'file': open('document.pdf', 'rb')}
response = requests.post(url, headers=headers, files=files)
if response.status_code == 200:
result = response.json()
print('Scan ID:', result.get('id'))
print('Findings:', result.get('findings'))
else:
print('Error:', response.status_code, response.text)
使用PHP处理扫描结果
<?php
$apiKey = 'YOUR_API_KEY';
$url = 'https://api.example.com/v2/files';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiKey
]);
$filePath = 'document.pdf';
$cfile = new CURLFile($filePath);
$postData = ['file' => $cfile];
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 200) {
$result = json_decode($response, true);
echo 'Scan ID: ' . $result['id'] . "\n";
echo 'Status: ' . $result['status'] . "\n";
} else {
echo 'Error: ' . $httpCode . "\n";
echo $response;
}
?>
使用JavaScript获取扫描状态
const axios = require('axios');
async function checkScanStatus(scanId) {
const url = `https://api.example.com/v2/files/${scanId}`;
const headers = {
'Authorization': 'Bearer YOUR_API_KEY'
};
try {
const response = await axios.get(url, { headers });
console.log('Scan Status:', response.data.status);
console.log('Findings:', response.data.findings);
return response.data;
} catch (error) {
console.error('Error fetching scan status:', error.response?.status || error.message);
throw error;
}
}
// Usage example
// checkScanStatus('scan_12345');
常见问题
Scanii API支持哪些文件类型?
Scanii API支持广泛的常见文件类型,包括但不限于PDF、Word文档、Excel表格、图像文件(如JPEG、PNG)、压缩文件(如ZIP)以及纯文本文件。具体支持的文件类型列表请参考官方文档。
如何处理扫描发现的威胁?
当Scanii检测到威胁时,API响应会返回详细的发现结果,包括威胁类型和位置信息。建议开发者根据业务需求制定处理策略,例如记录日志、隔离文件、通知用户或管理员,或结合其他安全措施进行进一步分析。
API请求是否有速率限制?
是的,Scanii API设有速率限制以保障服务稳定性。具体限制因订阅计划而异,通常包括每分钟或每小时的最大请求次数。超过限制的请求将收到429状态码响应。详细限制信息请查阅您的账户面板或联系技术支持。
Aitishiku.com