0
作爲參數傳遞的消息是一個數組。但推送沒有得到發送,而如果我發送一個字符串推送成功發送到IOS。對於IOS推送如何發送一個數組消息
public function sendIosPush($registatoin_ids, $message) {
set_time_limit(0);
$this->logger->write("INFO :","message for IOS PUSH".$message);
header('content-type: text/html; charset: utf-8');
$passphrase = '******';
$deviceIds=$registatoin_ids;
$body['aps'] = array('alert' => $message);
//$payload = '{"aps":{"alert":"' . $message . '","sound":"default"}}';
//$result = 'Start' . '<br />';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
foreach ($deviceIds as $item) {
//sleep(1);
$fp = stream_socket_client($this->iosServer, $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
// Build the binary notification
$payload = json_encode($body);
$this->logger->write("INFO :","message for IOS PUSH".$payload);
$msg = chr(0) . pack('n', 32) . pack('H*', $item) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if ($fp) {
fclose($fp);
}
}
//set_time_limit(30);
}
我已經做了類似於你所說的,但它不工作。你能幫助我解決任何工作示例嗎? – Rajeshwar