Cordova 获取无效注册我使用了phonegap插件push“;“成功”:“0”;失败:“1”;规范的“标识”:“0”;结果:[{“错误”:“无效注册”}

Cordova 获取无效注册我使用了phonegap插件push“;“成功”:“0”;失败:“1”;规范的“标识”:“0”;结果:[{“错误”:“无效注册”},cordova,push-notification,push,Cordova,Push Notification,Push,获取无效注册我使用phonegap插件推送“成功”:0,“失败”:1,“规范ID”:0,“结果”:[{“错误”:“无效注册”}]} 我正在尝试下面的phonegap最新插件是我的java脚本代码和php代码 使用离子科尔多瓦 PHP代码 enter code here <?php // API access key from Google API's Console define( 'API_ACCESS_KEY', 'AIzaSyBEzOLapgBPKJ-c_NU8rVsoU6k2e_

获取无效注册我使用phonegap插件推送“成功”:0,“失败”:1,“规范ID”:0,“结果”:[{“错误”:“无效注册”}]}

我正在尝试下面的phonegap最新插件是我的java脚本代码和php代码

使用离子科尔多瓦

PHP代码

enter code here

<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'AIzaSyBEzOLapgBPKJ-c_NU8rVsoU6k2e_Q-YqA' );


echo $_GET['id'];
$registrationIds = array( $_GET['id'] );//


// prep the bundle
$msg = array
(
'message'   => 'here is a message. message',
   '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'          => $msg
);

$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 );
curl_close( $ch );
echo $result;
在此处输入代码

事实上,我尝试使用这个库,但我遇到了同样的问题,然后我决定更改这个库并使用PushPlugin,它非常容易使用且简单明了。这里是它的链接:

事实上,我试图使用这个库,但我遇到了同样的问题,然后我决定更改这个库并使用PushPlugin,它非常简单易用。这里是它的链接:

我通过将我的php代码编辑成下面的代码解决了这个问题
//------------------------------
// Payload data you want to send 
// to Android device (will be
// accessible via intent extras)
//------------------------------

$data = array( 'message' => 'Hello World!' );

//------------------------------
// The recipient registration IDs
// that will receive the push
// (Should be stored in your DB)
// 
// Read about it here:
// http://developer.android.com/google/gcm/
//------------------------------

$ids = array( $_GET['id'] );//array( 'abc', 'def' );

//------------------------------
// Call our custom GCM function
//------------------------------

sendGoogleCloudMessage(  $data, $ids );

//------------------------------
// Define custom GCM function
//------------------------------

function sendGoogleCloudMessage( $data, $ids )
{
//------------------------------
// Replace with real GCM API 
// key from Google APIs Console
// 
// https://code.google.com/apis/console/
//------------------------------

$apiKey = 'apikey';

//------------------------------
// Define URL to GCM endpoint
//------------------------------

$url = 'https://android.googleapis.com/gcm/send';

//------------------------------
// Set GCM post variables
// (Device IDs and push payload)
//------------------------------

$post = array(
                'registration_ids'  => $ids,
                'data'              => $data,
                );

//------------------------------
// Set CURL request headers
// (Authentication and type)
//------------------------------

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

//------------------------------
// Initialize curl handle
//------------------------------

$ch = curl_init();

//------------------------------
// Set URL to GCM endpoint
//------------------------------

curl_setopt( $ch, CURLOPT_URL, $url );

//------------------------------
// Set request method to POST
//------------------------------

curl_setopt( $ch, CURLOPT_POST, true );

//------------------------------
// Set our custom headers
//------------------------------

curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );

//------------------------------
// Get the response back as 
// string instead of printing it
//------------------------------

curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

//------------------------------
// Set post data as JSON
//------------------------------

curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );

//------------------------------
// Actually send the push!
//------------------------------

$result = curl_exec( $ch );

//------------------------------
// Error? Display it!
//------------------------------

if ( curl_errno( $ch ) )
{
    echo 'GCM error: ' . curl_error( $ch );
}

//------------------------------
// Close curl handle
//------------------------------

curl_close( $ch );

//------------------------------
// Debug GCM response
//------------------------------

echo $result;
}

我通过将php代码编辑为下面的代码解决了这个问题
//------------------------------
// Payload data you want to send 
// to Android device (will be
// accessible via intent extras)
//------------------------------

$data = array( 'message' => 'Hello World!' );

//------------------------------
// The recipient registration IDs
// that will receive the push
// (Should be stored in your DB)
// 
// Read about it here:
// http://developer.android.com/google/gcm/
//------------------------------

$ids = array( $_GET['id'] );//array( 'abc', 'def' );

//------------------------------
// Call our custom GCM function
//------------------------------

sendGoogleCloudMessage(  $data, $ids );

//------------------------------
// Define custom GCM function
//------------------------------

function sendGoogleCloudMessage( $data, $ids )
{
//------------------------------
// Replace with real GCM API 
// key from Google APIs Console
// 
// https://code.google.com/apis/console/
//------------------------------

$apiKey = 'apikey';

//------------------------------
// Define URL to GCM endpoint
//------------------------------

$url = 'https://android.googleapis.com/gcm/send';

//------------------------------
// Set GCM post variables
// (Device IDs and push payload)
//------------------------------

$post = array(
                'registration_ids'  => $ids,
                'data'              => $data,
                );

//------------------------------
// Set CURL request headers
// (Authentication and type)
//------------------------------

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

//------------------------------
// Initialize curl handle
//------------------------------

$ch = curl_init();

//------------------------------
// Set URL to GCM endpoint
//------------------------------

curl_setopt( $ch, CURLOPT_URL, $url );

//------------------------------
// Set request method to POST
//------------------------------

curl_setopt( $ch, CURLOPT_POST, true );

//------------------------------
// Set our custom headers
//------------------------------

curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );

//------------------------------
// Get the response back as 
// string instead of printing it
//------------------------------

curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

//------------------------------
// Set post data as JSON
//------------------------------

curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );

//------------------------------
// Actually send the push!
//------------------------------

$result = curl_exec( $ch );

//------------------------------
// Error? Display it!
//------------------------------

if ( curl_errno( $ch ) )
{
    echo 'GCM error: ' . curl_error( $ch );
}

//------------------------------
// Close curl handle
//------------------------------

curl_close( $ch );

//------------------------------
// Debug GCM response
//------------------------------

echo $result;
}

请确保您在此处使用了正确的gcm id
{“senderID”:“280872888677”}
?我也遇到了同样的问题。我正在使用phonegap插件推送插件。请确保您在此处使用正确的gcm id
{“senderID”:“280872888677”}
?我也遇到了同样的问题。我正在使用phonegap插件推送插件。当我自动安装时,我无法构建项目。它给我一些错误代码8,现在我已经完成了手动安装。你能告诉我你是如何生成设备注册ID的吗?当我添加此插件时,我无法构建项目这个问题还有其他解决方案吗?是的,兄弟,我面临着完全相同的问题。解决方案只是下载以前的版本,即PushPlugin 2.4.0,下面是它的链接。如果你的问题解决了就给我来,兄弟。CheersHi bro@Nadeem Khoury你能告诉我使用命令行添加旧版本插件的过程吗?我在自动安装时无法构建项目,它给了我一些错误代码8,现在我已经完成了手动安装。你能告诉我你是如何生成设备注册ID的吗?我在安装时无法构建项目添加这个插件这个问题还有其他解决方案吗?是的,兄弟,我也面临同样的问题。解决方案只是下载以前的版本,即PushPlugin 2.4.0,下面是它的链接。如果你的问题解决了就给我来,兄弟。你能告诉我使用命令行添加旧版本插件的过程吗?
//------------------------------
// Payload data you want to send 
// to Android device (will be
// accessible via intent extras)
//------------------------------

$data = array( 'message' => 'Hello World!' );

//------------------------------
// The recipient registration IDs
// that will receive the push
// (Should be stored in your DB)
// 
// Read about it here:
// http://developer.android.com/google/gcm/
//------------------------------

$ids = array( $_GET['id'] );//array( 'abc', 'def' );

//------------------------------
// Call our custom GCM function
//------------------------------

sendGoogleCloudMessage(  $data, $ids );

//------------------------------
// Define custom GCM function
//------------------------------

function sendGoogleCloudMessage( $data, $ids )
{
//------------------------------
// Replace with real GCM API 
// key from Google APIs Console
// 
// https://code.google.com/apis/console/
//------------------------------

$apiKey = 'apikey';

//------------------------------
// Define URL to GCM endpoint
//------------------------------

$url = 'https://android.googleapis.com/gcm/send';

//------------------------------
// Set GCM post variables
// (Device IDs and push payload)
//------------------------------

$post = array(
                'registration_ids'  => $ids,
                'data'              => $data,
                );

//------------------------------
// Set CURL request headers
// (Authentication and type)
//------------------------------

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

//------------------------------
// Initialize curl handle
//------------------------------

$ch = curl_init();

//------------------------------
// Set URL to GCM endpoint
//------------------------------

curl_setopt( $ch, CURLOPT_URL, $url );

//------------------------------
// Set request method to POST
//------------------------------

curl_setopt( $ch, CURLOPT_POST, true );

//------------------------------
// Set our custom headers
//------------------------------

curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );

//------------------------------
// Get the response back as 
// string instead of printing it
//------------------------------

curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

//------------------------------
// Set post data as JSON
//------------------------------

curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );

//------------------------------
// Actually send the push!
//------------------------------

$result = curl_exec( $ch );

//------------------------------
// Error? Display it!
//------------------------------

if ( curl_errno( $ch ) )
{
    echo 'GCM error: ' . curl_error( $ch );
}

//------------------------------
// Close curl handle
//------------------------------

curl_close( $ch );

//------------------------------
// Debug GCM response
//------------------------------

echo $result;
}