This commit is contained in:
2026-03-26 20:51:36 +08:00
parent 4e211ed1fe
commit 7eb8c3a5ad
13 changed files with 122 additions and 4 deletions
+7
View File
@@ -68,6 +68,13 @@ npm start
- `onlyMatched=true`:只返回 `parseStatus=matched` 的验证码
- 返回:`{ inbounds: [...] }`
6. 业务系统查询出站发送任务状态(新增)
- `GET /api/v1/business/outbound-tasks?limit=50&status=&phone=`
- 请求头:`X-Api-Key: <SMS_GATEWAY_API_KEY>`
- status 取值:
- `pending` / `sending` / `failed` / `success`
- 返回:`{ tasks: [{ taskId, phone, content, status, ...}] }`
## 数据表
- `inbound_sms`
Binary file not shown.
+59
View File
@@ -183,6 +183,65 @@ router.post("/api/v1/business/outbound-tasks", (req, res) => {
}
});
// 6) 业务侧查询发送任务状态(用于业务系统展示)
router.get("/api/v1/business/outbound-tasks", (req, res) => {
const deviceId = getDeviceIdFromHeader(req);
if (!deviceId) return res.status(401).json({ error: "missing api key for device identification" });
const limit = Math.min(Number(req.query.limit || 50), 200);
const status = req.query.status ? String(req.query.status) : "";
const phone = req.query.phone ? safeString(req.query.phone) : "";
try {
const where = ["device_id = ?"];
const params = [deviceId];
if (status !== "") {
where.push("status = ?");
params.push(status);
}
if (phone !== "") {
where.push("phone LIKE ?");
params.push(`%${phone}%`);
}
const rows = db
.prepare(
`
SELECT
task_id,
phone,
content,
status,
retry_count,
last_error,
created_at,
updated_at
FROM outbound_tasks
WHERE ${where.join(" AND ")}
ORDER BY created_at DESC
LIMIT ?
`
)
.all(...params, limit);
res.json({
tasks: rows.map((r) => ({
taskId: r.task_id,
phone: r.phone,
content: r.content,
status: r.status,
retryCount: r.retry_count,
lastError: r.last_error,
createdAt: r.created_at,
updatedAt: r.updated_at,
})),
});
} catch (e) {
res.status(500).json({ error: "failed to query outbound tasks", detail: String(e?.message || e) });
}
});
// 5) 业务侧读取入站验证码(MVP 用)
router.get("/api/v1/business/inbound-sms", (req, res) => {
const deviceId = getDeviceIdFromHeader(req);