
Enviar mensajes con Api Oficial de WhatsApp en PHP
En este tutorial aprenderemos a Enviar mensajes con Api Oficial de WhatsApp en PHP, solo debemos seguir estos pasos:
Creamos una app en Facebook

O podemos aceder a este link Todas las apps – Meta for Developers (facebook.com)





Configuramos el Api de WhatsApp






Enviar mensajes desde postman

Enviar mensajes con Api Oficial de WhatsApp en PHP


<?php //TOKEN QUE NOS DA FACEBOOK $token = 'EAAIW7rNPtRsBAJ08gWP87RgwK03xZABkSWs6YYbXhcohaiCfA4DcOi3LPVnjz1Xpsycy8FZASv6Ny05tGCqds9HQI7r6dZAx5ne4ONgMRKZCQpFML1OZAiBF1DanvG7xo0We1N7IxW7C4ZBBfrnz4bi4ZCfl6zrru5ZB7HBVMZB1v5zKyCFjBQzZAZAuGTo48K8xDN8ZAHimIOHktQZDZD'; //NUESTRO TELEFONO $telefono = '521234567891'; //URL A DONDE SE MANDARA EL MENSAJE $url = 'https://graph.facebook.com/v15.0/105233795800723/messages'; //CONFIGURACION DEL MENSAJE $mensaje = '' . '{' . '"messaging_product": "whatsapp", ' . '"to": "'.$telefono.'", ' . '"type": "template", ' . '"template": ' . '{' . ' "name": "hello_world",' . ' "language":{ "code": "en_US" } ' . '} ' . '}'; //DECLARAMOS LAS CABECERAS $header = array("Authorization: Bearer " . $token, "Content-Type: application/json",); //INICIAMOS EL CURL $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POSTFIELDS, $mensaje); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //OBTENEMOS LA RESPUESTA DEL ENVIO DE INFORMACION $response = json_decode(curl_exec($curl), true); //IMPRIMIMOS LA RESPUESTA print_r($response); //OBTENEMOS EL CODIGO DE LA RESPUESTA $status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); //CERRAMOS EL CURL curl_close($curl); ?>