Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused) in /home/harsh/public_html/androidfb/IOSPushNotiFication/simplepush.php on line 14
  2. Failed to connect: 111 Connection refused
  3. <?php
  4. $deviceToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
  5. $passphrase = '12345';
  6. $message = 'My first push notification!';
  7. $ctx = stream_context_create();
  8. stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
  9. stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
  10. stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');
  11. $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195',$err,$errstr,60,STREAM_CLIENT_CONNECT,$ctx);
  12. if (!$fp)
  13. exit("Failed to connect: $err $errstr" . PHP_EOL);
  14. echo 'Connected to APNS' . PHP_EOL;
  15. $body['aps'] = array(
  16. 'alert' => $message,
  17. 'sound' => 'default'
  18. );
  19. $payload = json_encode($body);
  20. $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
  21. $result = fwrite($fp, $msg, strlen($msg));
  22. if (!$result)
  23. echo 'Message not delivered' . PHP_EOL;
  24. else
  25. echo 'Message successfully delivered' . PHP_EOL;
  26. fclose($fp);
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement