??????iOS??д???????????????????С??????????????????????????????????????????????????????
??????????δ?????????飬???????????????????p12??pem??????
????1.p12?pem ??pem?????????????????????
????pem???????????????????????????????????????????????????????С???????????????????pem????????ɡ?
????· ??Keychain Access????Certificates?????????????顣???certificate??private key(??)???????.p12?????
???????磺Apple Development Push Services > Export “Apple Development Push Services ID123”??????? apns-dev-cert.p12??
??????“Private Key”???????????????? apns-dev-key.p12 ?????
????· ???????????????Щ???????PEM?????????????????????p12?????????????????????? ???????????????
????openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12(????????pem)
????openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12 ??????????pem??
?????????????????????????123456.
????????????????123456??openssl rsa -in apns-dev-key.pem -out apns-dev-key.pem
???????????????????????????apns-dev.pem?????????????????APNS????????
????cat apns-dev-cert.pem apns-dev-key.pem > apns-dev.pem
????2.???????php????????????
??????????????????????????棬????????push.php
????????????
<php
$deviceToken= '7431d4f6e402b180fa37d5a0fbd0c8aed7b5acc0cf60bc81e58f9d707d5c556d'; //??п??
$body = array("aps" => array("alert" => 'helloHui'??"badge" => 2??"sound"=>'warning.caf'));  //?????????????????????
$ctx = stream_context_create();
//?????Windows?????????????pem·??????????·?????????????????
//$pem = dirname(__FILE__) . '/' . 'apns-dev.pem';
//linux ??????????дpem??·??????
stream_context_set_option($ctx??"ssl"??"local_cert"??"apns-dis.pem");
$pass = "";
stream_context_set_option($ctx?? 'ssl'?? 'passphrase'?? $pass);
//???????????????????????????????????????????sandbox????????????Dev??pem??飬?????????????????Product??pem???????????????
//    $fp = stream_socket_client("ssl://gateway.push.apple.com:2195"?? $err?? $errstr?? 60?? STREAM_CLIENT_CONNECT?? $ctx);
$fp = stream_socket_client("ssl://gateway.push.apple.com:2195"?? $err?? $errstr?? 60?? STREAM_CLIENT_CONNECT?? $ctx);
if (!$fp) {
echo "Failed to connect $err $errstrn";
return;
}
print "Connection OK ";
$payload = json_encode($body);
$msg = chr(0) . pack("n"??32) . pack("H*"?? str_replace(' '?? ''?? $deviceToken)) . pack("n"??strlen($payload)) . $payload;
echo "sending message :" . $payload ." ";
fwrite($fp?? $msg);
fclose($fp);
>
??????pem(???????apns-dev-cert.pem ?? apns-dev-key.pem ????????? apns-dev.pem) ?????php?????????????
????????????????????
????php push.php
???????????????????????????£??????????????????????
??????????????С????????????????????
???????С??????????
??????1????“Private Key”???????????????? apns-dev-key.p12 ??????????Private Key?????????
?????????Private key ???? ?????????????????????????????????????????е??????????