2017-05-01 5 views
-3

私は単一のPHPスクリプトを使用してアンドロイドのプッシュ通知をテストしていますが、カールエラーが発生して読み込みに時間がかかります。私もエラーを見ることができません。私のAPIキーとGCMが正しいかどうかを確認できるように、サンプルコードで解決策またはテストスクリプトを提供してください。プッシュ通知phpコードがAndroid用に機能していません

enter image description here

// API access key from Google API's Console 
define('API_ACCESS_KEY', 'AIzaSyDG3fYAj1uW7VB-wejaMJyJXiO5JagAsYI'); 
// $registrationIds = array("f-fAcroIrA8:APA91bFKyAmILhqC7itmq9W-ZsPJ09O908E8APZUavcLNpdGjxyihVPtFTR9wBnrMzDTYxQs3utuaFR_lPlBSkwpsSzV2W38NtZydf-S-aqOlq1cTj74eV3PcsDEM_8EVaKNqytrurvy"); 
$registrationIds = 'APA91bHdOmMHiRo5jJRM1jvxmGqhComcpVFDqBcPfLVvaieHeFI9WVrwoDeVVD1nPZ82rV2DxcyVv-oMMl5CJPhVXnLrzKiacR99eQ_irrYogy7typHQDb5sg4NB8zn6rFpiBuikNuwDQzr-2abV6Gl_VWDZlJOf4w'; 
// prep the bundle 
$msg = array 
(
    'message' => 'hiiii', 
    'title'  => 'This is a title. title', 
    'subtitle' => 'This is a subtitle. subtitle', 
    'tickerText' => 'Ticker text here...Ticker text here...Ticker text here', 
    'vibrate' => 1, 
    'sound'  => 1, 
    'largeIcon' => 'large_icon', 
    'smallIcon' => 'small_icon' 
); 
$fields = array 
(
    'registration_ids' => $registrationIds, 
    'data'   => $msg 
); 

// echo "<pre>"; 
// print_r($fields);exit; 

$headers = array 
(
    'Authorization: key=' . API_ACCESS_KEY, 
    'Content-Type: application/json' 
); 

$ch = curl_init(); 
curl_setopt($ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send'); 
curl_setopt($ch,CURLOPT_POST, true); 
curl_setopt($ch,CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($fields)); 
$result = curl_exec($ch); 
if($result === false) 
{ 
    echo curl_error($ch); 
    die('Curl failed: ' . curl_error($ch)); 
} 


curl_close($ch); 
echo $result; 
+2

は、あなたがしようとしているコードを提供します。 –

+0

@Badshah私のコードを確認してください –

+0

私の答えをチェックしてください –

答えて

0

私はちょうど私がそれを

$fields = array(
      'registration_ids' => array($registrationIds), 
      'data'    => array("message" => $msg), 
      ); 

$fields = array 
(
    'registration_ids' => $registrationIds, 
    'data'   => $msg 
); 

あなたの問題を解決することを願っ変更

<?php 
// API access key from Google API's Console 
define('API_ACCESS_KEY', 'AIzaSyDG3fYAj1uW7VB-wejaMJyJXiO5JagAsYI'); 
// $registrationIds = array("f-fAcroIrA8:APA91bFKyAmILhqC7itmq9W-ZsPJ09O908E8APZUavcLNpdGjxyihVPtFTR9wBnrMzDTYxQs3utuaFR_lPlBSkwpsSzV2W38NtZydf-S-aqOlq1cTj74eV3PcsDEM_8EVaKNqytrurvy"); 
$registrationIds = 'APA91bHdOmMHiRo5jJRM1jvxmGqhComcpVFDqBcPfLVvaieHeFI9WVrwoDeVVD1nPZ82rV2DxcyVv-oMMl5CJPhVXnLrzKiacR99eQ_irrYogy7typHQDb5sg4NB8zn6rFpiBuikNuwDQzr-2abV6Gl_VWDZlJOf4w'; 
// prep the bundle 
$msg = array 
(
    'message' => 'hiiii', 
    'title'  => 'This is a title. title', 
    'subtitle' => 'This is a subtitle. subtitle', 
    'tickerText' => 'Ticker text here...Ticker text here...Ticker text here', 
    'vibrate' => 1, 
    'sound'  => 1, 
    'largeIcon' => 'large_icon', 
    'smallIcon' => 'small_icon' 
); 


$fields = array(
      'registration_ids' => array($registrationIds), 
      'data'    => array("message" => $msg), 
      ); 

// echo "<pre>"; 
// print_r($fields);exit; 

$headers = array 
(
    'Authorization: key=' . API_ACCESS_KEY, 
    'Content-Type: application/json' 
); 

$ch = curl_init(); 
curl_setopt($ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send'); 
curl_setopt($ch,CURLOPT_POST, true); 
curl_setopt($ch,CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($fields)); 
$result = curl_exec($ch); 
if($result === false) 
{ 
    echo curl_error($ch); 
    die('Curl failed: ' . curl_error($ch)); 
} 


curl_close($ch); 
echo $result; 
今のコードの下に与えてみてください
0

phpで複数のユーザーのプッシュ通知を送信するにはどうすればいいですか?私はこのスクリプトを使用

..

define('API_ACCESS_KEY', 'AIzaSyBpAw3JWL-IbwaPnVBLhXJrjMSrKpIJdjI'); 
    $registrationIds = array($push); 

    // prep the bundle 
    $msg = array 
    (
    'message' => $_POST['msg'], 
    'title' => 'This is a title. title', 
    'subtitle' => 'This is a subtitle. subtitle', 
    'tickerText' => 'Ticker text here...Ticker text here...Ticker text here', 
    'vibrate' => 1, 
    'sound' => 1, 
    'largeIcon' => 'large_icon', 
    'smallIcon' => 'small_icon' 
    ); 
    $fields = array 
    (
    'registration_ids' => $registrationIds, 
    'data' => $msg 
    ); 

    $headers = array 
    (
    'Authorization: key=' . API_ACCESS_KEY, 
    'Content-Type: application/json' 
    ); 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 
    curl_setopt($ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send'); 
    curl_setopt($ch,CURLOPT_POST, true); 
    curl_setopt($ch,CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($fields)); 
    $result = curl_exec($ch); 
    if($result === false) 
    { 
     echo curl_error($ch); 
     die('Curl failed: ' . curl_error($ch)); 
    } 


    curl_close($ch); 
    echo $result; 





} 
関連する問題