我正在尝试使用apns发送通知。我在php中创建一个函数来发送消息。我收到错误“stream_socket_client():无法连接到ssl://gateway.sandbox.push.apple.com:2195(连接被拒绝)”。此代码在我的本地服务器上正常工作。但是,当我检查肝脏服务器收到错误。下面是代码
$this->set_url();
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $this->pem_file);
stream_context_set_option($ctx, 'ssl', 'passphrase', '1');
$fp = stream_socket_client($this->get_url(), $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
$sound = 'default';
$badge = 0;
$body = $this->get_message();
$data['key'] = $body['key'];
$data['sound'] = $sound;
$data['badge'] = $badge + 1;
$data['alert'] = $body['message'];
if (isset($body['extra']))
$data['extra'] = $body['extra'];
$apn_data['aps'] = $data;
$payload = json_encode($apn_data);
$msg = chr(0) . pack('n', 32) . pack('H*', $this->get_device()) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
fclose($fp);
答案 0 :(得分:3)
请求服务器管理员为传出连接打开端口2195
。
它会解决你的问题。