通知服务

借助 AFP 通知服务,AFP 透明平台可以在 PlatformChildSite 获得批准后接收通知,这表示该网站现在可在 API 中使用。

如需接收通知,请实现一个服务器,用于接受 POST 请求并解析架构中所述的 JSON 载荷(请参阅示例设置)。然后,您需要向战略合作伙伴经理提供端点网址,以便激活该服务。

架构

通知载荷必须遵循以下架构:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Notification",
  "type": "object",
  "properties": {
    "platformPublisherId": {
      "type": "string",
      "description": "The unique identifier for the platform publisher."
    },
    "publisherId": {
      "type": "string",
      "description": "The unique identifier for the publisher."
    },
    "platformChildSiteName": {
      "type": "string",
      "description": "The name of the PlatformChildSite the notification refers to (populated for SITE_APPROVAL)."
    },
    "notificationType": {
      "type": "string",
      "enum": ["SITE_APPROVAL"],
      "description": "Type of notification"
    },
  },
  "required": ["platformPublisherId", "publisherId", "notificationType"],
  "additionalProperties": false
}

我们日后可能会添加更多 notificationTypes 和其他字段。

示例

SITE_APPROVAL 通知将如下所示:

{
  "platformPublisherId" : "pub-123",
  "publisherId" : "pub-456",
  "platformChildSiteName" : "accounts/pub-123/platforms/my-platform/childAccounts/pub-456/sites/child-domain.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 platformPublisherId:', req.body.platformPublisherId)
    console.log('Received publisherId:', req.body.publisherId)
    console.log('Received platformChildSiteName:', req.body.platformChildSiteName)
    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 '{"platformPublisherId" : "pub-123", \
          "publisherId" : "pub-456", \
          "platformChildSiteName" : "accounts/pub-123/platforms/my-platform/childAccounts/pub-456/sites/child-domain.com", \
          "notificationType": "SITE_APPROVAL"}'

配置 robots.txt

验证通知服务是否有权访问您的端点。通知服务会遵循网域根目录的 robots.txt 文件(如果有)中列出的指令:

User-agent: GoogleOther
Disallow: <ensure your endpoint is not disallowed>