MismatchSenderId err - use only legacy server_key not server_key (firebase console)
PHP send message script
-----------------------------
<?php
header("Content-Type: text/plain");
//server_key
define('API_ACCESS_KEY',
"AIzaSyAxGQAHG2E3kH_xxxxxxxxxxxxxxxxxxxxx"); //<-- legacy_server_key
$curl = curl_init();
$client_id = "cnjo8BNuQJY:APA91bFnjBgMB4y3ZLTelNGrQWaKVX3QNBnZosXeCr4zKAAkpJKFY1MSGqk4n5ZW3H4oLxzlM4gSJg6Oa8mS_MDuHznW3vV8NDTJekG_6_T0j2M7ScVHkyJduE6IiEwNdpxxxxxxxxxxxxx";
$param = json_encode(
array(
"to"=>$client_id,
//'registration_ids'=>array($client_id),
'priority'=>'high',
'notification'=>[
'body' => 'here is a message. message',
'title' => 'This is title #1',
'sound' => "default",
'color' => "#203E78",
"icon" => "myicon"
]
)
);
echo $param;
curl_setopt_array($curl, array(
CURLOPT_URL => "https://fcm.googleapis.com/fcm/send",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $param,
CURLOPT_HTTPHEADER => array(
"Authorization: key=".API_ACCESS_KEY,
"Cache-Control: no-cache",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Комментариев нет:
Отправить комментарий