php写的可以在本机发送iOS push程序
最后更新于:2022-04-01 20:01:06
用于客户端,本机发push消息,把下面这段代码拷贝到文件以.php后缀名,和证书放到同一目录;ck.pem需要自己生成。具体步骤[详见这里](http://blog.csdn.net/hherima/article/details/45583865)
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-03-10_56e11b13bc245.jpg)
~~~
’push测试2’,
'action-loc-key'=>'ok');
// Create the payload body
$pushInfo['aps'] = array(
'alert' => $alert,
'sound' => '1',
// 'content-available' => 1//,//for 静默下载。
'badge' => 1
);
$pushInfo['usrdefined'] = array('ptype'=>'6',
'pushid'=>'4865',
//自定义字段
'appleid'=>’123456’
);
// Encode the payload as JSON
$payload = json_encode($pushInfo);
// 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;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
~~~
● 填写token的时候,把空格去掉。
● cd到文件的目录,键入命令 php xxx.php,如果收到此消息说明发送成功
Connected to APNS
Message successfully delivered
';