如何解决这个问题,我想发送通知



这里我想发送手机通知。我正在尝试这样做,我得到这样的错误。


{"成功"multicast_id":9154934162102180737:0,"失败":1、"canonical_ids":0,"结果":[{"错误":"MismatchSenderId"}]}


i can not understand what is API_ACCESS_KEY

<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'xxxxxx' );
//$registrationIds = array( $_GET['id'] );
$registrationIds = array( "APA91bEbAxYQZuglicZ2Ea5c26MtK07BYyunv14Us5INdjNvy3gy0Anq6V09dv2j21g7n_JERDumynuOp4l9GYA4RUGRjRZb6KJ4JYg9qPN9dlytPsgPKctIMhxfHFQSr9FfDjobZUJU" );
// 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, true );
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;

@SujiniR首先你注册你的应用程序在谷歌云消息和获得API访问密钥和发送ID,链接:

https://developers.google.com/cloud-messaging/registration

然后,Save Your api access key in:

define( 'API_ACCESS_KEY', 'api_key_recieved_from_google_by_above_process' );

然后在Android应用程序中使用SenderID来获取注册id,复制或发送该注册id到服务器并使用它:

$registrationIds = array(registrationID);

所以根据我们在评论中的讨论,似乎你使用了错误的发件人ID。您应该始终使用注册令牌对应的Sender ID,例如注册的。你的客户端应用程序可以从多个Sender id接收,只要它是绑定到它。否则它将返回一个MismatchSender:

注册令牌绑定到特定的发送者组。当客户端应用程序注册GCM时,它必须指定允许哪些发送方发送消息。如果你切换到一个不同的发送者,现有的注册令牌将不起作用

相关内容

  • 没有找到相关文章

最新更新