我可以将本地主机用作 Messenger webhook 中的 URL 回调吗

Can i use localhost as a URL Callback in a messenger webhook

晚上好,刚刚看到 Facebook 发布了他的 Messenger bot 工具包,我立即跳进去了解更多信息,也许会尝试做我自己的。

我的问题是我没有 https 网站 运行,它需要 https 有效 url。我尝试使用具有证书的本地 Web 服务器,但它不起作用。

我的问题是,这是否完全可以使用本地主机 url 完成。

提前致谢

My question is if this is possible to be done using a localhost url at all.

不,当然不是——因为这样的“回调”实际上意味着 Facebook 向您的服务器发出请求——这在 localhost.[=12= 中几乎不可能]


如今,您可以通过 LetsEncrypt 轻松免费获得适用于您网站的有效 SSL 证书。即使在您的服务器上不可用,仍然有 StartSSL,它免费提供基本证书。您所需要的只是一台服务器,您可以在其上安装它们,或将它们上传到服务器,或者您的托管商为其提供的任何机制。 (如果他们不提供,那么可能是时候切换了。)

实际上这可以通过本地主机实现。使用 ngrok。它允许您通过 http 或 https 打开 public 网络的本地主机。但是,这应该仅用于测试。

如果您想在本地环境中测试 webhook,我会尝试 ultrahook.com,您可以免费获得一个 API 密钥,该工具会从 public 创建一个隧道URL 到您的计算机。这是来自他们的常见问题解答页面:

You download and run the UltraHook client on your computer. It connects to UltraHook servers in the cloud and creates a tunnel from a public endpoint on our servers to your computer. Any HTTP POST requests sent to the public end point will be sent through the tunnel an delivered to a private endpoint accessible from your computer.

我用它来测试来自不同供应商(如支付网关)的 webhook。在您的计算机中,您可以 运行 像这样的东西:

ultrahook <subdomain> http://localhost:8000/webhook/

然后在您的外部服务中将 webhook URL 配置为 <subdomain>.ultrahook.com