Estoy usando el SDK de PHP de Twilio para enviar SMS. A continuación se muestra el código:
<?php // Required if your environment does not handle autoloading require './autoload.php'; // Use the REST API Client to make requests to the Twilio REST API use Twilio\Rest\Client; // Your Account SID and Auth Token from twilio.com/console $sid = 'XXXXXXXXXXXXXXXXXXXXXXXX'; $token = 'XXXXXXXXXXXXXXXXXXXX'; $client = new Client($sid, $token); // Use the client to do fun stuff like send text messages! $client->messages->create( // the number you'd like to send the message to '+XXXXXXXXXX', array( // A Twilio phone number you purchased at twilio.com/console 'from' => '+XXXXXXXX', // the body of the text message you'd like to send 'body' => 'Hey Jenny! Good luck on the bar exam!' ) ); **Response: [Twilio.Api.V2010.MessageInstance accountSid=XXXXXXXXXXXXXXXX sid=XXXXXXXXXXXXXXX]**¿Cómo puedo obtener la respuesta en formato JSON? Cualquier ayuda es apreciada.
La respuesta rápida es:
$json_string = json_encode(</POST|GET>); Use los súper globales $_POST o $_GET y obtendrá un formato de cadena json.
p.ej
/* * Imagine this is the POST request * * $_POST = [ * 'foo' => 'Hello', * 'bar' => 'World!' * ]; * */ $json_string = json_encode($_POST); // You get → {"foo":"Hello","bar":"World!"}De esta forma codificas los valores en una representación JSON .