The PHP code blogger on the iOSPush server was originally a PHPer. when I switched to iOS, I was very excited to see PHP.
Currently, there is a project that requires you to build the server code for iOS push. So I searched the code on the internet. the following error is always reported during execution:
Warning: stream_socket_client(): SSL operation failed with code 1.
This is because the key ck. pem is not enabled or generated by openssl is faulty. These problems were not found later. Paste the correct code for future use:
$ Message, 'sound' => 'default'); // Encode the payload as JSON $ payload = json_encode ($ body ); // Build the binary notification $ msg = chr (0 ). pack ('N', 32 ). pack ('H * ', $ deviceToken ). pack ('N', strlen ($ payload )). $ payload; // Send it to the server $ result = fwrite ($ fp, $ msg, strlen ($ msg); if (! $ Result) echo 'message not delivered'. PHP_EOL; elseecho 'message successfully delivered'. PHP_EOL; // Close the connection to the serverfclose ($ fp);?>