通过 userId 和 APIG objectId 查询用户的 APIGAuth 授权记录(余额、使用情况等)。 用于 OpenClaw 检查用户是否有额度、支付页面显示当前余额。
| 参数名 | 必填 | 说明 |
|---|---|---|
| userId | 是 | _User 表的 objectId |
| apigId | 是 | APIG 表的 objectId |
{
"code": 200,
"success": true,
"data": {
"objectId": "authObjectId",
"user": "userId",
"apig": "Vo3ROWEvDy",
"count": 1000,
"totalRecharge": 2000,
"createdAt": "2026-01-01T00:00:00.000Z",
"updatedAt": "2026-04-02T00:00:00.000Z"
}
}
如果用户没有授权记录,返回:
{
"code": 200,
"success": true,
"data": null
}
async function handler(request, response) {
console.log('🚀 执行 getApigAuth 云函数...');
try {
// 1. 获取参数
let userId = null;
let apigId = null;
if (request.params) {
userId = request.params.userId;
apigId = request.params.apigId;
}
if (!userId && request.body) userId = request.body.userId;
if (!apigId && request.body) apigId = request.body.apigId;
// 2. 参数校验
if (!userId || !apigId) {
response.json({ code: 400, success: false, error: '缺少必需参数 userId 或 apigId' });
return;
}
// 3. 查询 APIGAuth 表 — 通过 user 和 apig 字段查找
const sql = `
SELECT
a."objectId",
a."count",
a."createdAt",
a."updatedAt",
a."user",
a."apig"
FROM "APIGAuth" a
WHERE a."user" = $1 AND a."apig" = $2
LIMIT 1
`;
const result = await Psql.query(sql, [userId, apigId]);
// 4. 返回结果
if (!result || result.length === 0) {
response.json({
code: 200,
success: true,
data: null
});
return;
}
const row = result[0];
response.json({
code: 200,
success: true,
data: {
objectId: row.objectId,
user: row.user,
apig: row.apig,
count: row.count || 0,
createdAt: row.createdAt,
updatedAt: row.updatedAt
}
});
} catch (error) {
console.error('❌ getApigAuth 执行失败:', error.message);
response.json({ code: 500, success: false, error: error.message });
}
}
getApigAuthhttps://server.fmode.cn/parse/functions/getApigAuth请求体:
{
"_ApplicationId": "ncloudmaster",
"userId": "nd7NOCmFiE",
"apigId": "Vo3ROWEvDy"
}