【问题标题】:How to solve this issue i want to send notifications如何解决这个问题我想发送通知
【发布时间】:2016-10-27 04:48:25
【问题描述】:

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


{"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;

【问题讨论】:

  • 问题是您通过注册 id (GCM) 未注册。您必须通过此生成的 GCM Id 请签入。通过有效的 GCM ID 问题将是 slove.
  • GCM ID是什么意思,怎么注册。
  • $registrationIds 是我的手机号码唯一令牌 ID
  • @JD The Real Hero 告诉我解决方案实际上我花了 2 天时间仍然无法得到解决方案
  • 您确定将相应的发件人 ID 用于您要向其发送消息的注册令牌吗?此外,切勿向公众披露您的 API 密钥。

标签: php google-cloud-messaging gcmtaskservice


【解决方案1】:

@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);

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • @Al 先生告诉我哪一个我做错了密钥 SERVER KEY 或移动注册密钥
    • @SujiniR 很难用您提供的详细信息来判断。您使用的是什么客户端应用程序?
    猜你喜欢
    • 1970-01-01
    • 2022-06-14
    • 1970-01-01
    • 2012-06-22
    • 1970-01-01
    • 2019-10-14
    • 2020-03-25
    • 2020-02-14
    • 2020-07-30
    相关资源
    最近更新 更多