Php GCM推送服务器端,使用哪个API密钥?
我有点困惑。我有一个GCM PHP服务器端应用服务器,它使用来自Google开发者控制台的密钥。我可以按照《入门指南》中的说明创建Android密钥,也可以创建浏览器密钥、服务器密钥或OAuth密钥 有人能告诉我在通过GCM向Android设备发送消息时应该在服务器端PHP上使用哪个键吗 这是向GCM发送消息的功能Php GCM推送服务器端,使用哪个API密钥?,php,android,google-cloud-messaging,Php,Android,Google Cloud Messaging,我有点困惑。我有一个GCM PHP服务器端应用服务器,它使用来自Google开发者控制台的密钥。我可以按照《入门指南》中的说明创建Android密钥,也可以创建浏览器密钥、服务器密钥或OAuth密钥 有人能告诉我在通过GCM向Android设备发送消息时应该在服务器端PHP上使用哪个键吗 这是向GCM发送消息的功能 public function send_notification($registatoin_ids, $message) { // include config
public function send_notification($registatoin_ids, $message) {
// include config
include_once './config.php';
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
$headers = array(
'Authorization: key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
echo $result;
}
显然,在原始代码中,xxxxxxxxxxxxxxxxxxxxxxxxxxxx字符串被我的API_密钥替换
p、 s:我的android在GCM上注册的很好,我的注册id也被发送到了服务器上,是发送消息post请求总是返回401未经授权,恐怕我使用了错误的密钥
p、 s2:我已尝试了所有3种API_密钥,但均未成功。请确保包含值为“key=APIKEY”的“Authorization”标题 ApiKey可以是服务器密钥或浏览器密钥 如果为服务器密钥定义IP白名单,则只能从指定的IP发送消息。 我专注于Android或服务器API_键,但实际上我必须使用浏览器键 此外,为了进行最初的测试,我从白名单中删除了所有IP地址,以确保这不是发挥其作用的因素 现在我有了使用浏览器API密钥和IP限制的推送服务来处理上述代码,用于白名单
干杯:)请发布您的服务器代码看起来我已经在这么做了。请看一下我刚才添加到问题中的代码