php 对iphone APNS 的push消息

$deviceToken = $key;
   $body = array("aps" => array("alert" =>$msgcontent,"badge" => 1));
   $ctx = stream_context_create();
   $zhengshu=THINK_PATH."/Api/LW_ORM/ck.pem"; //ck.pem 是应用证书,一个应用有唯一的证书
   stream_context_set_option($ctx, "ssl", "local_cert", $zhengshu);
   $fp = stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
   if (!$fp) {
   // print "Failed to connect $err $errstrn";
     return;
   }
 // print "Connection OK\n";
   $payload = json_encode($body);
   $msg = chr(0) . pack("n",32) . pack("H*", $deviceToken) . pack("n",strlen($payload)) . $payload;
 // print "sending message :" . $payload . "\n";
   fwrite($fp, $msg);
   fclose($fp);

 

详细可以参考 微信公众号推广:http://www.jiweixin168.com    手机号码查询      防骗吧

你可能感兴趣的:(iPhone)