时间:2021-07-01 10:21:17 帮助过:8人阅读
目前有一个项目需要自己构建iOS推送的服务端代码。于是搜索了一下网上的代码,带式在执行的时候总是会报错,错误为:
Warning: stream_socket_client(): SSL operation failed with code 1.
本以为是openssl没有开启或者生成的秘钥ck.pem有问题。后来发现不是这些个问题。现在贴出正确的代码,以备不时之需:
$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);?>