簡體   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