Php 发送推送通知返回401未经授权
我一直在尝试用php向fcm google发送通知,但其返回未经授权 我已经检查了我的令牌、api密钥和脚本,但结果仍然相同 有人能帮我吗 这里是我的php代码Php 发送推送通知返回401未经授权,php,firebase,ionic-framework,Php,Firebase,Ionic Framework,我一直在尝试用php向fcm google发送通知,但其返回未经授权 我已经检查了我的令牌、api密钥和脚本,但结果仍然相同 有人能帮我吗 这里是我的php代码 public function pushNotif($data){ $api_key = 'myapikey'; $registrationIds = $data; // prep the bundle $msg = array(
public function pushNotif($data){
$api_key = 'myapikey';
$registrationIds = $data;
// prep the bundle
$msg = array(
'body'=> '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(
'to'=>$data,
'notification'=>$msg
);
$headers = array(
'Authorization: key='.$api_key,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://gcm-http.googleapis.com/gcm/send' );
//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, true );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
}
您是否将服务器的IP列入白名单?默认情况下,浏览器密钥不需要此选项,但服务器密钥需要此选项 您可以在这里查看: 项目编号]:访问 或者将其添加到curl php init中:
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
source我已经签入了您在上面链接中提供给我的谷歌API访问权限。我关注的是已经活跃的GCM。我还在php代码中添加了curl。但是结果还是一样的。@AgustinoWhickey你检查过我发布的源链接了吗?我相信你的答案在那里