0

Webサーバー経由で通知メッセージを送信します。サーバーでは、メッセージは正常に送信されましたが、デバイスには表示されません。しかし、EASY APNs Providerから同じ証明書キーを使用してメッセージを送信すると、メッセージがデバイスに表示されます。これは開発モードで起こります。私はまだ生産モードには適用していません。メッセージは正常に送信されましたが、iosの開発モードでデバイスに表示されません

enter image description here

enter image description here

しかし、私は、コマンド

openssl pkcs12 -in pushcert.p12 -out pushcert.pem -nodes -clcerts 

私を使用して、このarticle

次の.pemファイルを作成し、Webサーバから

を働いていませんconfig.inc.phpを

$IOS_pem='/apraise/transformers/fc2apple/phpscripts/pushcert2july.pem'; 
$SSL_URL='ssl://gateway.sandbox.push.apple.com:2195'; 

$config_passphrase = 'apraise123'; 

ログファイルにPHPコード

if((include 'config.inc.php') == TRUE) { 
     WriteDebug('Functions.php include: OK'); 
    } 
    try { 
     $ctx = stream_context_create(); 
     stream_context_set_option($ctx, 'ssl', 'local_cert', $IOS_pem); 
     stream_context_set_option($ctx, 'ssl', 'passphrase', $config_passphrase); 
     $time_start = microtime(true); 
     // Open a connection to the APNS server 
     $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: $err $errstr" . PHP_EOL); 
     echo 'Connected to APNS' . PHP_EOL; 

     $text = ""; 
     foreach($body['aps'] as $key => $value){    
      //WriteDebugLog("Body Key = " . $key . " & Value= " . $value, DEBUG); 
      $text .="[' " . $key . "',".$value."]"; 
     }    
     WriteDebug("$text to $deviceToken"); 
     // Encode the payload as JSON 
     //$payload = json_encode($body); 
     // Build the binary notification 
     $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($pushArray)) . $pushArray; 
     WriteDebug('REQ '.$msg); 
     // Send it to the server 
     $result = fwrite($fp, $msg, strlen($msg)); 
     //Get response from apple 
     stream_set_timeout($fp, 5); 
     $resFromApple = fread($fp, 2000); 
     //Getting the timeout status 
     $info = stream_get_meta_data($fp); 
     fclose($fp); 
     //Track time taken 
     $time_end = microtime(true); 
     if ($info['timed_out']) { 
      echo 'Connection timed out!'; 
      WriteDebug('RSP Timed out!'); 
     } else { 
      echo $resFromApple; 
      WriteDebug('RSP '.$resFromApple); 
     } 
     if (!$result) { 
      WriteDebug('Message failed delivered, Push Unsuccessfully,TT: '.number_format(($time_end-$time_start), 2, '.', '')*1000); 
      echo 'Message failed delivered, Push Unsuccessfully,TT: '.number_format(($time_end-$time_start), 2, '.', '')*1000; 
     } else { 
      WriteDebug('Message successfully delivered, Push successfully,TT: '.number_format(($time_end-$time_start), 2, '.', '')*1000); 
      echo'Message successfully delivered, Push successfully,TT: '.number_format(($time_end-$time_start), 2, '.', '')*1000; 
     } 
     // Close the connection to the server 
     fclose($fp); 
    } catch (Exception $exp) { 
     //WriteDebug("Error connection"); 
     fwrite($lfh, $exp); 
     WriteErr($exp); 
     return 9; 
    } 

2017-07-03 17:28:50.011 DBG receivers: 120f49ce167956785b5d1d6552510feb7d8587610b2b1496d2a1fae951b34969sharePush: {"aps" : {"alert" : {"title" : "Add Contact","body" : "Setting test apn"},"sound" : "default","badge" : 1}} 
2017-07-03 17:28:50.011 DBG Functions.php include: OK 
2017-07-03 17:28:50.647 DBG to 120f49ce167956785b5d1d6552510feb7d8587610b2b1496d2a1fae951b34969 
2017-07-03 17:28:50.647 DBG REQ {"aps" : {"alert" : {"title" : "Add Contact","body" : "Setting test apn"},"sound" : "default","badge" : 1}} 
2017-07-03 17:28:50.648 DBG $result: 144 
2017-07-03 17:28:50.648 DBG RSP 
2017-07-03 17:28:50.648 DBG Message successfully delivered, Push successfully,TT: 640 

私は他のファイルを作成するために、このarticleに従っています。

任意のsugession?

ありがとうございます。

+0

プッシュ通知に[OneSignal](https://onesignal.com/)を使用することをおすすめします。これであなたの人生は楽になります:) –

+0

pemファイルが有効かどうかを確認してください。http://apns-gcm.bryantan.info/ – Jay

答えて

1

あなたは開発のゲートウェイを使用する必要が生産

ssl://gateway.push.apple.com:2195 

のゲートウェイを使用しています。

ssl://gateway.sandbox.push.apple.com:2195 

また、私のPHPファイルをチェックしてください。

<?php 


    $deviceToken = '163e00bf5a7fe5298782988a4dcdecddac0dfe2fecf3723b4354076adasdasdfasdf'; // Development 

    // Put your private key's passphrase here: 
    $passphrase = '[email protected]@123'; 

    // Put your alert message here: 
    $message = 'My first push notification!'; 


    $sound = 'Default'; 


    $badge=12; 
    //////////////////////////////////////////////////////////////////////////////// 

    echo 'Connection Start'; 

    $ctx = stream_context_create(); 
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert.pem'); 
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); 

    // Open a connection to the APNS server 
    $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); 

    if (!$fp) 
    exit("Failed to connect: $err $errstr" . PHP_EOL); 

    echo 'Connected to APNS' . PHP_EOL; 

    $body['aps'] = array('alert' => 'This is the alert text', 'badge' => $badge, 'sound' => 'default'); 


    $body['PushKey'] = array('Type' => 1, 'ID' => 392); 



    echo json_encode($body); 


    // Encode the payload as JSON 
    $payload = json_encode($body); 

    // Build the binary notification 
    $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload; 

    // Send it to the server 
    $result = fwrite($fp, $msg, strlen($msg)); 

    if (!$result) 
    echo 'Message not delivered' . PHP_EOL; 
    else 
    echo 'Message successfully delivered' . PHP_EOL; 

    // Close the connection to the server 
    fclose($fp); 
+0

解決策が解決されました:Dありがとうございました。 –

関連する問題