-1

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


{"multicast_id":9154934162102180737,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}


我不明白什么是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;
4

2 回答 2

0

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

注册令牌与特定的发件人组相关联。当客户端应用注册 GCM 时,它必须指定允许哪些发件人发送消息。在向客户端应用程序发送消息时,您应该使用其中一个发件人 ID。如果您切换到其他发件人,现有的注册令牌将不起作用。

于 2016-10-27T15:37:58.247 回答
0

@SujiniR 首先,您在 Google Cloud Messaging 中注册您的应用程序并获取 API 访问密钥和发送 ID,链接:

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

然后,将您的 api 访问密钥保存在:

define( 'API_ACCESS_KEY', 'api_key_recieved_from_google_by_above_process' );

然后在 Android Application 中使用 SenderID 获取 RegistrationId,将该registrationId 复制或发送到服务器并使用它:

$registrationIds = array(registrationID);
于 2016-10-27T07:47:03.487 回答