【问题标题】:Push notification for android using php使用 php 为 android 推送通知
【发布时间】:2016-01-28 09:00:12
【问题描述】:

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

【问题讨论】:

标签: php android


【解决方案1】:

如果您想检查您的 UDID 和浏览器密钥是否正常工作,则可以通过 this. 进行检查

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-19
    • 2015-11-23
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    相关资源
    最近更新 更多