1

我尝试了以下代码(PHP)

$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apple_push_notification_production.pem';

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
if($apns)
{
    echo "Connection Established<br/>";
    $deviceToken = '**********';//masked

    $body = array();
    $body['aps'] = array(’alert’ => "test message");
    //$body['aps']['badge'] = 1;

    $payload = json_encode($body);


    $apnsMessage = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
    print "sending message :" . $apnsMessage . "<br/>";
    print "sending payload :" . $payload . "<br/>";
    fwrite($apns, $apnsMessage);

}
else
{   
    echo "Connection Failed";

    echo $errorString;
    echo $error;
}
socket_close($apns);
fclose($apns);  

回复是

Connection Established
sending message :�� d^÷Îå0ZCd%1ÄuwOOYš'ÊÈ}ârðm¾Í�,{"aps":{"\u2019alert\u2019":"test message"}}
sending payload :{"aps":{"\u2019alert\u2019":"test message"}}

但我无法收到通知

有什么帮助吗?

4

1 回答 1

1

这只是一个猜测,但从您发布的代码中的文件名来看,您正在使用针对沙盒推送服务器的生产证书。您不能混合使用沙盒和生产证书,也不能混合使用设备令牌。

于 2010-12-16T17:51:42.783 回答