【发布时间】:2016-12-12 02:05:30
【问题描述】:
我正在尝试在我的 Cordova 应用程序中实现推送通知,并且一直在学习一些教程。
我正在使用这段代码将通知发送到应用程序,但由于某种原因我收到了 MismatchSenderID 错误。
我多次检查并重新生成了访问密钥,GCM ID 是我从应用程序中获得的,所以它应该可以工作。
为什么会这样?
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'xx' );
$registrationIds = 'xx';
// 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' => array($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;
?>
--编辑:更多信息
我已经尝试了下面链接的线程中给出的解决方案,但是它们似乎不起作用,或者我做错了,因为 Google Console 的 url 格式和布局从那时起就变成了这样的东西:http://imgur.com/a/yosLF 我确实尝试重新安装 phonegap 以获得不同的注册 ID,并尝试了这两个 ID,包括 URL 中的一个和下面的一个。我可以通过终端成功发送推送通知,所以注册ID必须是正确的。
【问题讨论】:
标签: php android ios cordova google-cloud-messaging