【问题标题】:Unable to connect to ssl://gateway.push.apple.com:2195 (Connection refused)无法连接到 ssl://gateway.push.apple.com:2195(连接被拒绝)
【发布时间】:2019-02-02 00:21:28
【问题描述】:

几年前我在 Codeigniter(php) 的项目中实现了推送通知,直到 10 天前一切正常。我的.pem 文件在我的本地服务器以及在线通知工具上运行良好。

错误:“stream_socket_client():无法连接到 ssl://gateway.push.apple.com:2195(连接 拒绝)”。

我正在使用以下功能:

public function applePushSend($deviceToken, $msg){

            $mode ='prod';

            $ctx = stream_context_create();

            if($mode=='dev'){
                $gateway = 'ssl://gateway.sandbox.push.apple.com:2195';
                stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert_dev.pem');
            }else{
                $gateway = 'ssl://gateway.push.apple.com:2195';
                stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert_prod.pem');
            }

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

            if (!$fp){
            }else{

                $alert = array();
                $alert['title'] = "My Message";
                $alert['body'] = $msg;
                $body['aps']['alert'] = $alert;
                $body['aps']['badge'] = 1;
                $body['aps']['sound'] = 'default';
                $body['notificationtypeid'] = 4;

                $payload = json_encode($body);
                $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
                $pushresult = fwrite($fp, $msg, strlen($msg));
            }
            fclose($fp);
            return($pushresult);
        }

【问题讨论】:

标签: php codeigniter push-notification


【解决方案1】:

我把代码改成:

$streamContext = stream_context_create(array('ssl' => array(
                      'local_cert' => $this->_sProviderCertificateFile
                    )));

它就像一个魅力!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-26
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多