【问题标题】:Wire the homepage so that it fires off a Push notification message to my iPhone every time someone lands on the page连接主页,以便每次有人登陆页面时都会向我的 iPhone 发送推送通知消息
【发布时间】:2010-04-02 10:14:26
【问题描述】:

我正在寻找一种简单的方法来连接我网站的主页,以便每当有人登陆该页面(只需在他们的浏览器中访问)时,它就会向我的 iPhone 发送推送通知消息。我知道这可能会很烦人!

我目前使用 cron 和 curl 定期向我的 iPhone 发送通知,以检查站点/RSS 提要是否有变化,然后发送到 Prowl API,后者又将其发送到我的 iPhone - 就像这样:

curl https://prowl.weks.net/publicapi/add -F apikey=$apikey -F priority=$priority -F application="$app" -F event="$eventname" -F description="$description"

我可以对主页的 HTML 做类似的事情吗?在我的服务器上调用一个脚本,然后触发上面类似的 curl 请求?也许使用 Javascript 或 PHP?理想情况下,我希望我的网页的加载和呈现不会被调用中断。

向 Prowl 致敬 - http://prowl.weks.net/api.php 和 flx.me 我用这两者来制作我已经在工作的东西。

【问题讨论】:

  • 您肯定希望从服务器而不是从页面执行此操作。如果您将代码放在页面中,那么您网站的访问者将能够看到您的关键信息。

标签: javascript iphone curl scripting push-notification


【解决方案1】:

如果您安装了 PHP 的 cURL 库,则可以直接从 PHP 执行命令(参见 http://php.net/manual/en/book.curl.phphttp://curl.haxx.se/libcurl/php/):

<?php
// This is at the top of the HTML page
// (although you could put it anywhere)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://prowl.weks.net/publicapi/add");
// The next 2 commands assume that you are sending a POST request
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "apikey=$apikey,priority=$priority&application=$app&event=$eventname&description=$description");
curl_exec ($ch);
curl_close ($ch);
?>
<html>
...

此外,您可以使用 PHP 的 systemexec 或类似函数来执行 cURL 命令:

<?php
// This is at the top of the HTML page
// (although you could put it anywhere)
exec('curl https://prowl.weks.net/publicapi/add -F apikey=$apikey -F priority=$priority -F application="$app" -F event="$eventname" -F description="$description"');
?>
<html>
...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-17
    • 1970-01-01
    • 2018-02-24
    相关资源
    最近更新 更多