# 主题组件是否可以捕获来自第三方服务的请求？

**URL:** <https://meta.discourse.org/t/is-it-possible-to-catch-a-request-from-a-third-party-service-in-a-theme-component/255047>\
**Category:** Development\
**Created:** [2023 年2 月 13 日 22:54 UTC](https://meta.discourse.org/t/is-it-possible-to-catch-a-request-from-a-third-party-service-in-a-theme-component/255047 "2023-02-13T22:54:12Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)\
**Post date:** [2023 年2 月 13 日 22:54 UTC](https://meta.discourse.org/t/is-it-possible-to-catch-a-request-from-a-third-party-service-in-a-theme-component/255047/1 "2023-02-13T22:54:13Z")

</div>

我的想法从这里开始：

> [@Forum maintenance cost](https://meta.discourse.org/t/forum-maintenance-cost/253930/19?u=canapin):
>
> Yeah, I don’t want to be pushy. The topic is pinned until the fees are met, but the best solution would be a progress bar between the header and the forum’s content I think. It’s not something that I can achieve with my current system since donations are made on ko-fi, unless… eyes grey_question

Ko-Fi 是一个捐赠平台。他们有一个 API，可以向 webhook 发送 HTTP POST 请求。  
[https://ko-fi.com/manage/webhooks](https://ko-fi.com/manage/webhooks)（该页面需要登录，但它只是文档，所以我将复制粘贴：

> **Ko-Fi Webhooks 文档**
>
> **Webhook URL**
> 
> 当付款完成后，我们将向您指定的 URL 发送一个 HTTP POST 请求。您的 URL 必须以 https:// 开头。
> 
> **Verification Token**
> 
> 下面的验证令牌将包含在发送到您的 webhook 的每个请求中。这是一种轻量级的方法，可以增加您对 Ko-fi 服务器是您的 webhook 请求来源的信心。请确保此置信度级别适合您的应用程序。例如，请注意，验证令牌以纯文本形式发送。  
> `XXXXXXXXXXXXXXXXXXXXX`
> 
> **接收和响应**
> 
> 数据以 `application/x-www-form-urlencoded` 的内容类型发送（发布）。名为“data”的字段包含作为 JSON 字符串的付款信息。
> 
> 您的监听器应返回状态码 `200`。如果我们未收到此状态码，我们将使用相同的 message\_id 重试合理次数。
> 
> `type` 字段将是 `Donation`、`Subscription`、`Commission` 或 `Shop Order`。
> 
> 每月订阅付款将设置 `is_subscription_payment` 为 `true`。
> 
> 当有人首次订阅时，`is_first_subscription_payment` 将为 `true`。
> 
> 如果订阅是针对会员等级的，则 `tier_name` 将包含您为该等级指定的名称。
> 
> 对于商店订单，`shop_items` 将包含一个商店项目对象的数组，每个对象只有一个属性，即 `direct_link_code`。
> 
> 重要提示：如果您使用 Webhooks 公开显示付款，则必须遵守 `is_public` 字段，如果值为 `false`，则隐藏消息。
> 
> 如果您没有设置服务器来接收 webhook，但想测试下面的示例，我们建议使用 `https://webhook.site/` 等服务来检查我们发送的请求。
> 
> **示例：单笔捐赠**
> 
> 以下是单笔捐赠将发送的数据示例：
> 
> ```json
> data = {
> "verification_token": "d8546b84-c698-4df5-9812-39d35813e2ff",
> "message_id": "78b207f2-9e6c-4ea7-b47f-5454709824aa",
> "timestamp": "2023-02-13T22:39:12Z",
> "type": "Donation",
> "is_public": true,
> "from_name": "Jo Example",
> "message": "Good luck with the integration!",
> "amount": "3.00",
> "url": "https://ko-fi.com/Home/CoffeeShop?txid=00000000-1111-2222-3333-444444444444",
> "email": "jo.example@example.com",
> "currency": "USD",
> "is_subscription_payment": false,
> "is_first_subscription_payment": false,
> "kofi_transaction_id": "00000000-1111-2222-3333-444444444444",
> "shop_items": null,
> "tier_name": null,
> "shipping": null
> }
> 
> ```
> 
> (etc)

* * *

我想在我的 Discourse 论坛上添加一个捐赠进度条，当 Discourse 收到此类请求时，该进度条会更新。

主题组件可以接收这些请求吗，还是需要插件？

如果使用主题组件（或需要的插件）可以实现，我应该从哪里开始？只需要一些线索或提示即可 🙂

---

_[View the full topic](https://meta.discourse.org/t/is-it-possible-to-catch-a-request-from-a-third-party-service-in-a-theme-component/255047)._
