使用PHP执行卷曲来发送推送通知



我正在尝试发送curl命令发送推送通知。我对卷发很新,似乎无法运行命令。

这是卷曲命令行:

curl --header "Authorization: key=AAAAVD27CWY:APA91bE7YdKYiqTmQhErf0E3gm8lbgNt2KP5-xPQf83V7m8eKsa0ljktOLiGyzzrP0uxVNBHC6cyuJAPejkTyNl1DnoxcajesLvGXIzq3YR1l-wiFvoivRmIUkDvThTsKCJkZMomhEPp" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{"registration_ids":["fr1l051Pczw:APA91bGkyuA6iKMP6oICJ8NweijQpWTWGuo-inqvpF5-Mety0D7oL_ppvevKKdWPxIo7ev_v5sAWbprk7pEg8kz3cNCivipL9RCR3XlA1caBtahsRtnANZpaU-KYnsdjcGY3Q51xN1ny"]}"

这是我要执行的php卷发:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{"registration_ids":["fr1l051Pczw:APA91bGkyuA6iKMP6oICJ8NweijQpWTWGuo-inqvpF5-Mety0D7oL_ppvevKKdWPxIo7ev_v5sAWbprk7pEg8kz3cNCivipL9RCR3XlA1caBtahsRtnANZpaU-KYnsdjcGY3Q51xN1ny"]}");
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Authorization: key=AAAAVD27CWY:APA91bE7YdKYiqTmQhErf0E3gm8lbgNt2KP5-xPQf83V7m8eKsa0ljktOLiGyzzrP0uxVNBHC6cyuJAPejkTyNl1DnoxcajesLvGXIzq3YR1l-wiFvoivRmIUkDvThTsKCJkZMomhEPp";
$headers[] = "Content-Type: "application/json"";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);

我正在使用Google的Firebase云消息传递运行此操作。

我可以在服务器上执行命令,因此我至少知道这有效。

运行Ubuntu 16.04和Apache。我正在服务器上运行SSL,并尝试添加:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

仍然没有运气。

请使用以下php curl请求

<?php
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://android.googleapis.com/gcm/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 => "{"registration_ids":["fr1l051Pczw:APA91bGkyuA6iKMP6oICJ8NweijQpWTWGuo-inqvpF5-Mety0D7oL_ppvevKKdWPxIo7ev_v5sAWbprk7pEg8kz3cNCivipL9RCR3XlA1caBtahsRtnANZpaU-KYnsdjcGY3Q51xN1ny"]}",
  CURLOPT_HTTPHEADER => array(
    "authorization: key=AAAAVD27CWY:APA91bE7YdKYiqTmQhErf0E3gm8lbgNt2KP5-xPQf83V7m8eKsa0ljktOLiGyzzrP0uxVNBHC6cyuJAPejkTyNl1DnoxcajesLvGXIzq3YR1l-wiFvoivRmIUkDvThTsKCJkZMomhEPp",
    "content-type: application/json"
  ),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

相关内容

  • 没有找到相关文章

最新更新