-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (52 loc) · 2.25 KB
/
Copy pathindex.js
File metadata and controls
69 lines (52 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const express = require("express");
const bodyParser = require("body-parser");
const crypto = require("crypto");
const app = express();
const PORT = process.env.PORT || 10000;
// 和 eBay 页面里填的一模一样
const EBAY_VERIFICATION_TOKEN = process.env.EBAY_VERIFICATION_TOKEN;
// 你在 eBay 里配置的 Endpoint URL(完全一致,包括路径和 https)
const EBAY_ENDPOINT_URL =
"https://cardfolio-ebay-webhook.onrender.com/webhooks/ebay/account-deletion";
app.use(bodyParser.json());
// 根路径测试
app.get("/", (req, res) => {
res.send("cardfolio eBay webhook is running");
});
// --------------- eBay 验证用 GET ---------------
app.get("/webhooks/ebay/account-deletion", (req, res) => {
console.log("▶️ 收到 eBay 验证 GET:", req.method, req.url, req.query);
const challengeCode = req.query.challenge_code;
if (!challengeCode) {
console.error("❌ 缺少 challenge_code");
return res.status(400).json({ error: "missing challenge_code" });
}
if (!EBAY_VERIFICATION_TOKEN) {
console.error("❌ 本地没有配置 EBAY_VERIFICATION_TOKEN 环境变量");
return res.status(500).json({ error: "server misconfigured" });
}
// 按官方要求:challengeCode + verificationToken + endpointURL
const hash = crypto.createHash("sha256");
hash.update(challengeCode);
hash.update(EBAY_VERIFICATION_TOKEN);
hash.update(EBAY_ENDPOINT_URL);
const challengeResponse = hash.digest("hex");
console.log("✅ challengeResponse =", challengeResponse);
res
.status(200)
.json({ challengeResponse }); // Content-Type: application/json
});
// --------------- 后续真正的通知用 POST ---------------
app.post("/webhooks/ebay/account-deletion", (req, res) => {
console.log("📩 收到 eBay 删除通知 POST:", JSON.stringify(req.body, null, 2));
const { metadata } = req.body || {};
if (!metadata || metadata.topic !== "MARKETPLACE_ACCOUNT_DELETION") {
console.error("❌ topic 无效:", metadata);
return res.status(400).send("Invalid topic");
}
// TODO: 在这里根据通知内容执行你自己的删除逻辑
res.sendStatus(200);
});
app.listen(PORT, () => {
console.log(`🚀 Server listening on port ${PORT}`);
});