convertir curl en php



https://incarnate.github.io/curl-to-php/


ejemplo:
script curl:

curl -H "Content-Type: application/json" \
     -H "Authorization: key=YOUR_SERVER_KEY" \
     -d '{
           "notification": {
             "title": "New chat message!",
             "body": "There is a new message in FriendlyChat",
             "icon": "/images/profile_placeholder.png",
             "click_action": "http://localhost:5000"
           },
           "to": "YOUR_DEVICE_TOKEN"
         }' \
     https://fcm.googleapis.com/fcm/send


convertido a php:

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"notification\": {\n \"title\": \"New chat message!\",\n \"body\": \"There is a new message in FriendlyChat\",\n \"icon\": \"/images/profile_placeholder.png\",\n \"click_action\": \"http://localhost:5000\"\n },\n \"to\": \"YOUR_DEVICE_TOKEN\"\n }"); curl_setopt($ch, CURLOPT_POST, 1); $headers = array(); $headers[] = "Content-Type: application/json"; $headers[] = "Authorization: key=YOUR_SERVER_KEY"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close ($ch);


No hay comentarios:

Publicar un comentario

linux ubuntu mint actualizar chrome

 desde una terminal: $ sudo apt update $ sudo apt install google-chrome-stable