假设 Alyssa 想给她的朋友 Ben 发送一条消息,询问他是否还记得归还一本借来的书。她可以创建一个 ActivityStreams 对象并将其发送到她的发件箱。
{
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Note",
"to": ["https://chatty.example/ben/"],
"attributedTo": "https://social.example/alyssa/",
"content": "Say, did you finish reading that book I lent you?"
}
服务器会将这条消息包装在一个 Create 活动中,并发送到 Ben 的收件箱。
{
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Create",
"id": "https://social.example/alyssa/posts/a29a6843-9feb-4c74-a7f7-081b9c9201d3",
"to": ["https://chatty.example/ben/"],
"actor": "https://social.example/alyssa/",
"object": {
"type": "Note",
"id": "https://social.example/alyssa/posts/49e2d03d-b53a-4c4c-a95c-94a6abf45a19",
"attributedTo": "https://social.example/alyssa/",
"to": ["https://chatty.example/ben/"],
"content": "Say, did you finish reading that book I lent you?"
}
}
安全性和验证
在 ActivityPub 中,服务器应该验证收到的内容,以防止内容欺骗攻击。例如,当服务器接收到一个 Like 活动时,应该验证该活动的 id 是否存在并且是一个有效对象。