简体   繁体   中英

Implement Ionic push notification

I am Implementing push notification in ionic using this tutorial: http://devdactic.com/ionic-push-notifications/

I have succesfully done using this. I got device token: like:

Got token: DEV-f30dac7a-d761-4a4c-a579-01918b9662ad none

When I use this in following php script:

<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'apikey' );
$registrationIds = array( 'f30dac7a-d761-4a4c-a579-01918b9662ad' );
// 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'  => $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;

I got error like:

{`"multicast_id":6920644147476475688,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}`

I dont Know where I am wrong.Please Help

The error says that your app is not registred. Make sure you put your GCM API key in 'apikey'.

令牌是DEV-f30dac7a-d761-4a4c-a579-01918b9662ad ,而不是f30dac7a-d761-4a4c-a579-01918b9662ad因为您输入了$registrationIds

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM