繁体   English   中英

使用php为Android推送通知

[英]Push notification for android using php

我想使用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;
?>

如果您要检查UDID,并且浏览器密钥正常工作,则可以通过方法进行检查

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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