iPhone推送通知(PHP)没有发送

Dav*_*eck 0 iphone push-notification

我设置了一个PHP脚本来使用本教程发送推送通知.我运行脚本没有任何错误,但我的设备上没有任何显示.我究竟做错了什么?

小智 7

为推送通知创建一个通用函数根据您的应用程序要求,在函数devicetoken,message和extra params中传递以下参数.如果您使用的是开发人员pem文件,那么您必须使用"gateway.sandbox.push.apple.com:2195",如果您使用的是分销商panm文件,则必须使用"gateway.push.apple.com:2195"

public function pushtoios($devicetoken, $message, $params = array()) {
    $passphrase = 'apple';
    $ctx = stream_context_create();
/*Development pam file*/
    //stream_context_set_option($ctx, 'ssl', 'local_cert',  your path.'apns-dev.pem');
/*Distributer pam file*/
    stream_context_set_option($ctx, 'ssl', 'local_cert', your path.'apns-distr.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

/*For Development pam file*/
    //$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);

/*For Distributer pam file*/
    $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
    if (!$fp)
        exit("Failed to connect amarnew: $err $errstr" . PHP_EOL);

    $body['aps'] = array(
        'alert' => $message,
        'sound' => 'default'
    );
    $body['type'] = $params['type'];
    $body['params'] = $params;
    $payload = json_encode($body);
    $msg = chr(0) . pack('n', 32) . pack('H*', $devicetoken) . pack('n', strlen($payload)) . $payload;

    $result = fwrite($fp, $msg, strlen($msg));
    if (!$result) {
        return false;
    } else {
        return true;
    }
    fclose($fp);
}
Run Code Online (Sandbox Code Playgroud)