service - 推送通知的反馈服务

标签 service push notifications feedback

我编写了以下脚本来读取反馈数据。但是,由于某些原因,我没有从服务器收到任何数据。您能告诉我脚本有什么问题吗?另外,如果您有任何可用于反馈服务的php脚本,请您分享一下...

问候, DD。

 <?php

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');


// Set time limit to indefinite execution
set_time_limit (0); 

// Set the ip and port we will listen on
$address = 'ssl://feedback.sandbox.push.apple.com';
$port = 2196; 

// Create a TCP Stream socket
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
echo "PHP Socket Server started at " . $address . " " . $port . "\n";

// Bind the socket to an address/port
socket_bind($sock, $address, $port) or die('Could not bind to address');
// Start listening for connections
socket_listen($sock); 

//loop and listen

while (true) {
    /* Accept incoming requests and handle them as child processes */
    $client = socket_accept($sock); 

    // Read the input from the client – 1024 bytes
    $input = socket_read($client, 1024); 


}

// Close the client (child) socket
socket_close($client); 

// Close the master sockets
socket_close($sock);

?>

最佳答案

您必须充当客户端,就像发送通知一样。那一定是这样的:

<?php
$certFile = 'apns-dev.pem';

while (true) { 
    $ctx = stream_context_create(); 
    stream_context_set_option($ctx, 'ssl', 'local_cert', $certFile); 
    //stream_context_set_option($ctx, 'ssl', 'passphrase', $this->certPass);
    echo "try to open stream\n";
    $fp = stream_socket_client('ssl://feedback.sandbox.push.apple.com:2196', $err, $errstr, 5, STREAM_CLIENT_CONNECT, $ctx); 
    if (!$fp) { 
      print "Failed to connect". $err . $errstr. "\n"; 
      exit(); 
    } else {
        echo 'Connected to feedback sandbox...';
        while (($in = fread($fp, 1024)) != EOF) {
            echo 'read '. $in . "\n";   
        }

        socket_close($fp);
        fclose($fp);
    }
    sleep(2000);
}
?>

关于service - 推送通知的反馈服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1708248/

相关文章:

iphone - 解锁 iPhone 时推送通知警报会打开应用程序

java - 当客户端代码运行在多台机器上时,如何保证服务调用的上限?

jquery - 将数组插入一个 JSON 数组

java - Android:FileObserver 不会收到有关 FS 更改的通知

git - 如何在不提交/添加任何文件或修改任何文件的情况下检查远程 GIT 存储库权限

flutter - Flutter audio_service实现没有队列的skipToNext

javascript - 当页面中发生有趣的事情时如何照亮浏览器窗口/选项卡?

user-interface - 黑莓 - 如何在状态栏中使用通知图标

java - 如果我想代理所有服务调用,以便在不显式调用记录器的情况下正确记录它们,我有什么选择?

c++ - win2k3上转换为VC2012后Windows服务启动报错error 193 0xc1