当我尝试发送消息时(使用GCM推送通知从服务器到移动设备)我收到以下错误。我已经尝试了stackoverflow中其他帖子中提供的所有解决方案
{" multicast_id":XXXXXX,"成功":0,"失效":1," canonical_ids":0 "结果":[{"错误":" MismatchSenderId"}]}
我已在GCM注册了
服务器密钥1:xxxxxxxxxx 项目编号:xxxxxx
在我的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" />
&#13;
湾我从GCM服务器获得了注册ID,并将其存储在我的服务器中。
℃。当我尝试使用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;
?>
&#13;
请帮助我,我在这里错过任何一步。