PHP:GCM向函数传递数组时注册无效
我为google云消息服务设置的php代码遇到了一个非常奇怪的问题 当前我有以下功能发送推送通知:PHP:GCM向函数传递数组时注册无效,php,android,google-cloud-messaging,Php,Android,Google Cloud Messaging,我为google云消息服务设置的php代码遇到了一个非常奇怪的问题 当前我有以下功能发送推送通知: function sendPushNotification($user_token_list, $message) { global $gcm_api_key, $errors; $data = array('message' => $message); $url = 'https://android.googleapis.com/gcm/send'; $po
function sendPushNotification($user_token_list, $message)
{
global $gcm_api_key, $errors;
$data = array('message' => $message);
$url = 'https://android.googleapis.com/gcm/send';
$post_data = array (
"registration_ids" => $user_token_list,
"data" => array("message" => $message)
);
$header = array (
'Authorization: key='.$gcm_api_key,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
$result = curl_exec($ch);
if (curl_errno($ch)) $errors[] = array('PUSH_NOTIFICATION_FAILURE' => curl_error($ch));
curl_close($ch);
echo $result;
}
$message
是要包含在下游中的消息,$user\u token\u list
是数组类型,其元素包含有效的注册ID
我用来构造$user\u token\u list
数组的函数如下:
function getDeviceTokensFromUserList($recipients, $website)
{
$token_list = array();
for ($i = 0; $i < count($recipients); ++$i)
{
$token_list[] = getDeviceTokenFromUserid($recipients[$i], $website);
}
return $token_list;
}
意味着注册id有效并已在gcm注册
有什么想法吗?根据Android GCM的架构概述,在以下情况下,您会出现无效注册错误: 无效的注册ID请检查传递给服务器的注册ID的格式。确保它与手机在com.google.android.c2dm.intent.registration intent中接收到的注册ID匹配,并且您没有截断它或添加其他字符。错误代码为InvalidRegistration时发生 检查接收下游消息的部件:
这里有一个相关的堆栈溢出问题:您能确保密钥的长度与您需要的长度相同吗?确保没有空格等…只是为了确保,如果
$user\u token\u list
确实是一个数组,var\u dump
将输出其数组结构,而不仅仅是显示的字符串值。是的,var\u dump输出数组结构。。。字符串的长度完全相同。。
$post_data = array (
"registration_ids" => array("duICFkjL5I4:APA91bF_asp9iDmNvMWUX58nPU8bj8kWua8ISiAoUw0KvYai5n37yp-qRlQrl2jPhTPY-a8KMq-XXXXXXXXX"),
"data" => array("message" => $message)
);