通知服务
借助 AFP 通知服务,AFP Direct 平台可以在子帐号和网站状态发生变化时收到通知。平台可以使用 Platform API 调查更改。
如需接收通知,请实现一台服务器,让其接受 POST 请求并解析架构中列出的 JSON 载荷(请参阅示例设置)。然后,您需要向您的战略合作伙伴经理提供端点网址,以激活该服务。
架构
通知载荷必须遵循以下架构:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Notification",
"type": "object",
"properties": {
"accountName": {
"type": "string",
"description": "The name of the modified sub-account."
},
"domain": {
"type": "string",
"description": "The domain the notification refers to, if any. Optional (only populated for SITE_APPROVAL)"
},
"notificationType": {
"type": "string",
"enum": ["PUBLISHER_APPROVAL", "SITE_APPROVAL"],
"description": "Type of notification"
}
},
"required": ["platformPublisherId", "publisherId", "notificationType"],
"additionalProperties": false
}
稍后可添加更多 notificationTypes
和其他字段。
示例
发布商审批通知如下所示:
{
"accountName" : "platforms/pub-1234567890123456/accounts/pub-0987654321654321",
"notificationType": "PUBLISHER_APPROVAL"
}
网站审批通知如下所示:
{
"accountName" : "platforms/pub-1234567890123456/accounts/pub-0987654321654321",
"domain": "afpsite.com",
"notificationType": "SITE_APPROVAL"
}
示例设置
以下是记录通知内容的 NodeJS 服务器示例:
// Import express
const express = require('express');
// Create an express application
const app = express();
// Middleware to parse JSON bodies
app.use(express.json());
// Define a route to receive POST requests
app.post('/notification', (req, res) => {
console.log('Received account name:', req.body.accountName)
console.log('Received Domain:', req.body.domain)
console.log('Received notification type', req.body.notificationType)
// Send a response back to the client
res.status(200).send('Notification received');
});
// Start the server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
端点网址示例:https://yourdomain.com/your-endpoint
使用 curl
发送 POST 请求,验证您的端点是否正常工作:
curl -X POST https://yourdomain.com/your-endpoint \
-H "Content-Type: application/json" \
-d '{"accountName": "platforms/pub-1234567890123456/accounts/pub-0987654321654321", \
"notificationType": "PUBLISHER_APPROVAL"}'
配置 robots.txt
确保允许通知服务访问您的端点。通知服务会遵循网域根目录的 robots.txt
文件(如果存在)中列出的指令:
User-agent: GoogleOther
Disallow: <ensure your endpoint is not disallowed>