2016-11-09 17 views
8

을 사용하여 APN에 연결하는 등 https://github.com/immobiliare/ApnsPHP으로 현재 라이브러리는 여전히 노드와어떻게 애플 P8에있는 APN 인증 키를 변경 한 후 PHP는 P8 인증 키 파일

$push = new ApnsPHP_Push(
    ApnsPHP_Abstract::ENVIRONMENT_SANDBOX, 
    'server_certificates_bundle_sandbox.pem' 
); 
// Set the Provider Certificate passphrase 
// $push->setProviderCertificatePassphrase('test'); 
// Set the Root Certificate Autority to verify the Apple remote peer 
$push->setRootCertificationAuthority('entrust_root_certification_authority.pem'); 
// Connect to the Apple Push Notification Service 
$push->connect() 

를 연결하는 기존 PEM 및 인증서 파일을 사용합니다. JS 예 (https://eladnava.com/send-push-notifications-to-ios-devices-using-xcode-8-and-swift-3/), I는 다음과 같이 보낼 수 :

var apnProvider = new apn.Provider({ 
    token: { 
     key: 'APNsAuthKey_Q34DLF6Z6J.p8', // Path to the key p8 file 
     keyId: 'Q34DLF6Z6J', // The Key ID of the p8 file (available at https://developer.apple.com/account/ios/certificate/key) 
     teamId: 'RLAHF6FL89', // The Team ID of your Apple Developer Account (available at https://developer.apple.com/account/#/membership/) 
    }, 
    production: false // Set to true if sending a notification to a production iOS app 
}); 

어떻게 내가 Node.js를에서처럼 아이폰 OS에 원격 알림을 보낼 PHP를 사용할 수 있습니까?

+0

해결책이 있습니까? :) – Maximus1809

+0

@ Maximus1809 아직 :) – mehmetsen80

+0

이 작업을 수행하는 방법을 찾고 있는데, 솔루션을 만들어야 할 것처럼 보입니다. –

답변

-1

게임에 너무 늦어서 죄송합니다. 내가 당신의 질문을 정확하게 이해한다면, 나는 이것이 당신이 찾고있는 것이라고 믿습니다. 이것은 PHP를 사용하여 Apple APNS에 메시지를 보내는 데 사용하는 것입니다. 페이로드에 대해 조사를해야 할 수도 있습니다. 앱 코딩 방법에 따라 구조를 구성하는 몇 가지 방법이 있기 때문입니다. 또한이 작업을 수행하려면 포트 2195를 사용할 수 있어야합니다. 전용 또는 사내 서버를 운영하고 있다면 괜찮을 것입니다. 공유 서버 인 경우 작동하지 않습니다.

$passphrase = 'xxxxx'; // This is the passphrase used for file ck.pem 
    $ctx = stream_context_create(); 
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem'); // ck.pem file must be included to sent token to ios devices 
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); 
    stream_context_set_option($ctx, 'ssl', 'verify_peer', true); 
    stream_context_set_option($ctx, 'ssl', 'allow_self_signed', true); 
    $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx); 
    stream_set_blocking ($fp, 0); // Ensure that blocking is disabled 

    if (!$fp) { 
     $fds = "Failed to connect: $err $errstr" . PHP_EOL; 
     return false; 
    } else { 

     // Create the payload body 
     // this example uses a custom data payload. depending on your app you may need to change this 
     $body['aps'] = array('alert' => $message, 'sound' => 'default', 'badge' => 1); 
     // Encode the payload as JSON 
     $payload = json_encode($body); 
     // Build the binary notification 
     $msg = chr(0) . pack('n', 32) . pack('H*', str_replace(' ', '',$token)) . pack('n', strlen($payload)) . $payload; 
     // Send it to the server 
     $result = fwrite($fp, $msg, strlen($msg)); 
     // Close the connection to the server 
     fclose($fp); 
    }