【问题标题】:MismatchSenderId error from GCM (using GCM push notification)来自 GCM 的 MismatchSenderId 错误(使用 GCM 推送通知)
【发布时间】:2016-07-31 18:47:33
【问题描述】:

当我尝试发送消息(使用 GCM 推送通知从服务器到移动设备)时,出现以下错误。我已经尝试了stackoverflow中其他帖子中给出的所有解决方案

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

  1. 我已在 GCM 中完成注册

    服务器密钥 1: xxxxxxxxxx 项目编号:xxxxxx

  2. 在我的 android 代码中,我设置了以下内容(我的包名是 com.revu.revu)

    一个。清单文件:

        // When notification received from GCM, then activate this service
        <service
            android:name=".PushNotificationService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>

        <receiver
            android:name="com.google.android.gms.gcm.GcmReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.revu.revu" />
            </intent-filter>
        </receiver>

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.revu.revu.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="com.revu.revu.permission.C2D_MESSAGE" />

b.我从 GCM 服务器获得了注册 ID,并存储在我的服务器中。

c。当我尝试使用 API 密钥(服务器密钥)向注册 ID 发送消息时,出现上述错误(mismatchsenderId)。

我使用以下 php 代码发送消息

<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'xxxxxxxxxxxxxxxxx');
$regId = "APA91bFidqJmnqm0GGmWRmkwB8Kn4fLJ0WPUTbWo3l2bbgQGNnzqbiYKyB4QJ-_JlvoA2tHFhgON2egA_1eJ82TA2sm38qdJVeP2Qk4CW1poxMcFu0emUC1Y_Lf3otKy6U5YAnn2ralS"; 
$registrationIds = array($regId);
// 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;

?>

请帮帮我,我是否错过了这里的任何步骤。

【问题讨论】:

  • 你的senderid错了,请再检查一遍
  • 请向我推荐一些链接,这些链接提供了在 GCM 中注册应用程序的完整程序
  • 我跟着这个成功了:androidwarriors.com/2015/10/…
  • 谢谢,我会试试这个
  • 是否必须将应用放入 Google Play 商店?让 GCM 推送通知工作?到目前为止,我正在创建 apk 文件并直接将其安装在我的手机中并尝试...

标签: php android google-cloud-messaging


【解决方案1】:

我认为这与您在 Google Developer Console 中为项目设置 API 访问的方式有关,

不匹配的Sender ID 与特定的发件人组相关联。当应用程序注册使用 GCM 时,它必须指定允许哪些发送者发送消息。确保您在尝试向设备发送消息时使用其中之一。如果您切换到其他发件人,则注册 ID 不起作用。当错误代码为“MismatchSenderId”时发生。

这是一个讨论 MismatchSenderID 的相关 SO 票证:PHP GCM error message MismatchSenderId

【讨论】:

  • 请向我推荐一些链接,这些链接提供了在 GCM 中注册应用程序的完整程序
  • 是否必须将应用放入 Google Play 商店?让 GCM 推送通知工作?到目前为止,我正在创建 apk 文件并直接将其安装在我的手机中并尝试..
猜你喜欢
  • 2015-03-08
  • 1970-01-01
  • 2016-12-16
  • 2012-11-27
  • 2016-07-24
  • 1970-01-01
  • 2013-02-02
  • 2012-06-30
  • 2017-06-04
相关资源
最近更新 更多