2016-11-09 11 views
8

इस्तेमाल करने के बाद एप्पल p8 को APN के प्रमाणीकरण कुंजी परिवर्तित साथ APN से कनेक्ट करने, इस तरह के रूप में वर्तमान https://github.com/immobiliare/ApnsPHP पुस्तकालयों अभी भी कनेक्ट करने के लिएकैसे पीएचपी 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() 

नोड के साथ वर्ष पीईएम और प्रमाणपत्र फ़ाइलों का उपयोग करें। js उदाहरण (https://eladnava.com/send-push-notifications-to-ios-devices-using-xcode-8-and-swift-3/), मैं इस तरह भेज सकता है:

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 
}); 

मैं PHP का उपयोग कैसे कर सकते हैं जैसे मैं Node.js में क्या आईओएस के लिए दूरस्थ सूचना भेजने के लिए?

+0

क्या आपके पास कोई समाधान है? :) – Maximus1809

+0

@ मैक्सिमस 180 9 अभी तक नहीं :) :) – mehmetsen80

+0

मैं ऐसा करने का एक तरीका ढूंढ रहा हूं, ऐसा लगता है कि मुझे समाधान करना होगा –

उत्तर

-1

खेल के लिए बहुत देर हो चुकी है। अगर मैं आपके प्रश्न को सही ढंग से समझता हूं तो मुझे विश्वास है कि यह वही है जो आप खोज रहे हैं। PHP का उपयोग करके ऐप्पल एपीएनएस को संदेश भेजने के लिए मैं यही उपयोग करता हूं। आपको पेलोड पर कुछ शोध करना पड़ सकता है क्योंकि आपके ऐप को कोड करने के तरीके के आधार पर इसे ढांचे के कुछ तरीके हैं। साथ ही, ध्यान रखें कि आप काम करने के लिए पोर्ट 21 9 5 का उपयोग करने में सक्षम होना चाहिए। यदि आप समर्पित या इन-हाउस सर्वर चला रहे हैं तो आपको ठीक होना चाहिए। यदि यह एक साझा सर्वर है तो यह काम नहीं करेगा।

$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); 
    } 
संबंधित मुद्दे