【发布时间】:2018-02-12 08:44:38
【问题描述】:
我正在尝试在 Cordova 中使用推送通知。 我还将推送通知插件添加到我的项目中,并在那里输入了我的发件人 ID。 我正在使用 Cordova 设备插件来获取设备 ID 这是我用来向服务器发送数据的代码。
var id = device.uuid;
alert(id);
document.getElementById("f1").value = id;
document.getElementById("form1").submit();
这是 PHP 代码:
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'KEYGOESHERE' );
$registrationIds = array( $_GET['id'] );
// 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;
?>
每次我运行脚本时,都会收到此错误:
{"multicast_id":5616818555748303283,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
你能帮帮我吗?我不知道为什么这不起作用,我没有更改代码中的设备 ID 字符串。 后端/前端部分有什么我遗漏的吗?
【问题讨论】:
-
这应该可以帮助你:stackoverflow.com/a/29706107/1485183
-
我阅读了该主题,但我发现的唯一建议是检查代码是否未更改 ID。我的代码没有改变字符串
-
我从代码中得到的ID是16个字符长,是我必须发送的ID,还是有其他方法可以找回正确的ID