来自Web服务器的低级通知

kim*_*3er 5 notifications web-services growl

我注意到Growl允许从网站发出Growl通知.有人尝试过这个吗?

如果是这样,它采取了什么形式?您是否实施了多用户支持?并且,你能提供任何代码示例(C#或Objective-C会更好,但我不是那么讨厌)?

丰富

dbr*_*dbr 4

有各种语言的GNTP (Growl 网络传输协议)绑定,可以在此处找到绑定列表- 这些允许您从 PHP 脚本等发送通知。

我不会直接信任 Growl 的 UDP 系统,而是编写一个接收和存储通知的服务器(可能作为一个小型 Web 应用程序),以及一个定期通过 HTTP 抓取任何新消息并 Growls 的本地脚本。一点也不复杂,比 UDP 更可靠,并且可以在您的 Growl'ing 机器关闭或无法访问时对消息进行排队。实施起来应该不需要很长时间

基本上,server.php在伪 PHP 中(可以使用Net_Growl):

<?php
if($_GET['action'] == "store"){
    $title = $_POST['title'];
    $message = $_POST['message'];
    $password = sha1($_POST['password']);
    if($password == "..."){
        store_in_database(sanitise($title), sanitise($message);
    }
} else {
    print(json_encode(get_notifications_from_database()));
    mark_notifications_as_read();
}
?>
Run Code Online (Sandbox Code Playgroud)

client.py在伪 Python 中(可以使用gntp):

while 1:
    time.sleep(60):
    data = urllib.urlopen("http://myserver.com/server.php?action=get&password=blah").read()
    for line in data:
        notif = json.decode(line)
        growl.alert(notif['title'], notif['message'])
Run Code Online (Sandbox Code Playgroud)