使用php推送Android的通知

时间:2016-01-28 09:00:12

标签: php android

我要使用Android设备我试试下面与谷歌API密钥“AIzaSyCBpVn9J2TWxPZDqyilCssUh5dbphQQtWE”和设备寄存器ID“APA91bGiZr2BAqkwqQrsxCfXftzVnUGaWnBbI-NYtT3i3vpQC_wwMcLZDoJx-04YHUHUf0NKp3Sjnwx_Rx-U-3fAZOTVFI9oRp2z”代码推送通知,但它给“未授权 错误401“错误..

<?php

define( 'API_ACCESS_KEY', 'AIzaSyCBpVn9J2TWxPZDqyilCssUh5dbphQQtWE');


$registrationIds = array("APA91bGiZr2BAqkwqQrsxCfXftzVnUGaWnBbI-NYtT3i3vpQC_wwMcLZDoJx-04YHUHUf0NKp3Sjnwx_Rx-u-3fAZOTVFI9oRp2z");

// 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, 1 );
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;
?>

1 个答案:

答案 0 :(得分:0)

如果你想检查你的UDID并且浏览器密钥工作正常,你可以通过this.检查