當我嘗試發送消息時(使用GCM推送通知從服務器移動到移動設備)我收到以下錯誤。我已經嘗試了所有在其他帖子中以疊加方式給出的所有解決方案GCM的MismatchSenderId錯誤(使用GCM推送通知)
{「multicast_id」:xxxxxx,「success」:0,「failure」:1,「canonical_ids」:0,「results」:[ { 「錯誤」: 「MismatchSenderId」}]}
我已經做了我的註冊在GCM
服務器密鑰1:XXXXXXXXXX 項目ID:XXXXXX
在我的Android代碼,我設置了以下(m y包名稱爲com.revu.revu)
a。清單文件:
// 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" />
灣我從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
(
\t 'message' \t => 'here is a message. message',
\t 'title' \t \t => 'This is a title. title',
\t 'subtitle' \t => 'This is a subtitle. subtitle',
\t 'tickerText' \t => 'Ticker text here...Ticker text here...Ticker text here',
\t 'vibrate' \t => 1,
\t 'sound' \t \t => 1,
\t 'largeIcon' \t => 'large_icon',
\t 'smallIcon' \t => 'small_icon'
);
$fields = array
(
\t 'registration_ids' \t => $registrationIds,
\t 'data' \t \t \t => $msg
);
$headers = array
(
\t 'Authorization: key=' . API_ACCESS_KEY,
\t '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是錯誤的,檢查一遍PLZ –
請建議我一些鏈接賦予完整的程序應用註冊在GCM –
我按照這一個和成功:http://www.androidwarriors.com/2015/10/push-notification-using-gcm-in-android.html –