Unable to receive Apple push notification on iphone through php service -
I'm sorry if this is a duplicate question, but I did not find the solution I was looking for. Here is the service code to send information to my PHP's iPhone:
& lt ;? Php $ data = array (); // Place your device token here (without spaces): $ deviceToken = 'eb9ea0d12eb9a0bae159c7e54fa59baee22329df'; // Place the passphrase of your private key here: $ passphrase = 'dell'; $ Message = 'push notification service'; //////////////////////////////////////////////// ////////////////////////// $ ctx = stream_context_create (); Stream_context_set_option ($ ctx, 'ssl', 'local_cert', 'app / controller / ck.pem'); Stream_context_set_option ($ ctx, 'ssl', 'passphrase', $ passphrase); // Open the connection to the APNS server $ fp = stream_socket_client ('SSL: //gateway.sandbox.push.apple.com: 2195', $$ err, $ errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ ctx); If (! $ Fp) // exit ("Failed to connect: $ err $ errstr". PHP_EOL); $ Data ['response'] = 'connect to APIs' PHP_EOL; // payload body $ body ['aps]] = create array (' warning '=> $ message,' sound '=' gt; 'default'); // Encrypt payload as JSON $ payload = json_encode ($ body); // Create binary notifications $ msg = chr (0). Pack ('N', 32) Pack ('H *', $ DeviceToken) Pack ('n', strollon ($ payload)). $ Payload; // Send it to server $ result = fwrite ($ fp, $ msg, strlen ($ msg)); If (! $ Result) $ data ['response'] = 'message not sent' PHP_EOL; And $ data ['response'] = 'message delivered successfully' PHP_EOL; // Close the server fclose ($ fp) connection; $ Response- & gt; Skill = $ data; $ This- & gt; Feedback ($ reaction, 200); ? & Gt;
To send information I am running over service in php (Code Ignitor) but I am not using code igniter. Although the above mentioned services are successfully running but I am not receiving notification on my phone. Can anyone tell a problem?
"post-text" itemprop = "text">
This works for me:
$ ctx = stream_context_create (); Stream_context_set_option ($ ctx, 'ssl', 'local_cert', $ certFilePath); Stream_context_set_option ($ ctx, 'ssl', 'passphrase', $ passphrase); Stream_context_set_option ($ ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer'); $ WebServiceLocation = 'tls: //gateway.push.apple.com: 2195'; $ Fp = stream_socket_client ($ web service location, $ err, $ errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ ctx); If (! $ Fp) exit ("Failed to connect: $ err $ errstr". PHP_EOL); $ Body ['aps'] = array ('warning' = & gt; $ message, 'sound' = & gt; 'default'); $ Payload = json_encode ($ entity); $ Msg = chr (0) pack ('N', 32) pack ('H *', $ deviceToken). Pack ('n', strollon ($ payload)). $ Payload; $ Result = filitt ($ fp, $ msg, strlen ($ msg)); Fclose ($ FP);
Comments
Post a Comment