【问题标题】:APNS not working, SSL Broken Pipe & bad write retryAPNS 不工作,SSL Broken Pipe & Bad write retry
【发布时间】:2016-07-01 04:44:07
【问题描述】:

我正在为我的公司开发苹果应用程序,

我正在使用 PHP、laravel 框架在服务器端向 APNS 发送消息。

为了测试,我使用硬编码设备令牌。 我让它在我硬编码的一台设备上工作。

所以我已经开始使用发送 apns 的函数了,apns 是函数中请求的设备令牌。 所以当我调用这个函数时,它会从数据库中获取设备令牌并发送到 apns。

我得到错误

fwrite(): SSL operation failed with code 1. OpenSSL Error messages: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry

fwrite(): SSL: Broken pipe

我将代码改回第一次测试,但它不像以前那样工作。

有人知道我做错了什么或者我的请求有什么错误吗?

请注意这是我的代码

    $apnsServer = 'ssl://gateway.sandbox.push.apple.com:2195';

    $privateKeyPassword = 'my_private_key';

    $id = $request->input('id');
    $message = "message_here";

    $userSelected = User::select('device_token')->where('id', $id)->first();
    $deviceToken = str_replace(' ', '', $userSelected['device_token']);

    $pushCertAndKeyPemFile = $_SERVER['DOCUMENT_ROOT'].'my_certificate.pem';
    $stream = stream_context_create();
    stream_context_set_option($stream, 'ssl', 'passphrase', $privateKeyPassword);
    stream_context_set_option($stream, 'ssl', 'local_cert', $pushCertAndKeyPemFile);
    $connectionTimeout = 30;
    $connectionType = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT;
    $connection = stream_socket_client($apnsServer, $errorNumber, $errorString, $connectionTimeout, $connectionType, $stream);

    if (!$connection){
        echo "Failed to connect to the APNS server. Error = $errorString <br/>"; 
        exit;
    }else{
        echo "Successfully connected to the APNS. Processing...</br>";
    }
    $messageBody['aps'] = array('alert' => $message, 'sound' => 'default', 'badge' => 1);

    $payload = json_encode($messageBody);
    $notification = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
    $wroteSuccessfully = fwrite($connection, $notification, strlen($notification));

    if (!$wroteSuccessfully){
        echo "Could not send the message<br/>";
    } else {
        echo "Successfully sent the message<br/>"; 
    }

【问题讨论】:

    标签: php apple-push-notifications


    【解决方案1】:

    经过一番研究,我发现了我的问题。

    1. 当我们的服务器向APNS发送PUSH消息时,有响应错误需要检查每个请求。 检查错误后,我收到错误消息 8,无效令牌

    2. 当使用开发证书,并且有用户使用开发应用注册时,他们获得设备令牌 但是当你改为生产时,你必须更改生产证书并且注册用户需要获取新的设备令牌才能使推送通知工作

    因为您在开发应用程序中获得的设备令牌不适用于生产证书..

    错过重要的事情完全是我的错误..

    【讨论】:

      猜你喜欢
      • 2017-09-02
      • 1970-01-01
      • 2018-10-29
      • 1970-01-01
      • 2021-08-24
      • 2017-02-28
      • 1970-01-01
      • 2021-08-26
      • 1970-01-01
      相关资源
      最近更新 更多