gpt4 book ai didi

android - 我无法推送通知

转载 作者:搜寻专家 更新时间:2023-11-01 09:50:15 24 4
gpt4 key购买 nike

我无法推送通知。
我的回答是:

"{\"multicast_id\":8319582670472068768,\"success\":0,\"failure\":3,\"canonical_ids\":0,\"results\":[{\"error\":\"InvalidRegistration\"},{\"error\":\"InvalidRegistration\"},{\"error\":\"InvalidRegistration\"}]}"

代码:

public function sendNotification($registration_ids,$message){


$url = 'https://android.googleapis.com/gcm/send';

$fields = array(
'registration_ids' => $registration_ids,
'data' => $message,
);

$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($fields));

$result = curl_exec($curl);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($curl));
}

error_log("Response from GCM Server:".$result);

curl_close($curl);
return $result;

最佳答案

如果您的 API key 无效,通常会出现此问题。响应是什么状态码?您可以在此处阅读更多信息:https://developers.google.com/cloud-messaging/http#checkAPIkey

If you receive a 401 HTTP status code, your API key is not valid. Otherwise you should see something like this:

{"multicast_id":6782339717028231855,"success":0,"failure":1,
"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

使用为您处理 GCM 消息传递的 Laravel 包可能对您来说更方便:https://github.com/davibennun/laravel-push-notification/

请告诉我您收到的状态码。

关于android - 我无法推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36518348/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com