无法使用 php 中的 plivo 令牌和身份验证 ID 获取或显示收到的短信

Unable to get or display received sms using plivo token and auth id in php

我正在编写 PHP 脚本,我想在其中获取并显示在 plivo 号码上收到的所有消息?

我已经尝试了两种不同的方法,但都不起作用

请指导如何获得方法 1 中必需的 your_message_uuid

方法一

require 'vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("auth id", "auth_token");
$response = $client->messages->get('your_message_uuid');
print_r($response);

方法二

require 'vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("auth id", "auth_token");
$response = $client->messages->list(
    [
        'limit' => 5,
        'offset' => 0,
        'subaccount' =>'subaccount_auth_id'
    ]
);
print_r($response);
// Prints only the message_uuid
print_r($response->getmessageUuid(0));

使用方法 1 的结果

Plivo\Resources\Message\Message Object ( [client:protected] => Plivo\BaseClient Object ( [timeout:protected] => [httpClientHandler:protected] => Plivo\HttpClients\PlivoGuzzleHttpClient Object ( [guzzleClient:protected] => GuzzleHttp\Client Object ( [config:GuzzleHttp\Client:private] => Array ( [handler] => GuzzleHttp\HandlerStack Object ( [handler:GuzzleHttp\HandlerStack:private] => Closure Object ( [static] => Array ( [default] => GuzzleHttp\Handler\CurlMultiHandler Object ( [factory:GuzzleHttp\Handler\CurlMultiHandler:private] => GuzzleHttp\Handler\CurlFactory Object ( [handles:GuzzleHttp\Handler\CurlFactory:private] => Array ( ) [maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 50 ) [selectTimeout:GuzzleHttp\Handler\CurlMultiHandler:private] => 1 [active:GuzzleHttp\Handler\CurlMultiHandler:private] => [handles:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) [delays:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) [options:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) ) [sync] => GuzzleHttp\Handler\CurlHandler Object ( [factory:GuzzleHttp\Handler\CurlHandler:private] => GuzzleHttp\Handler\CurlFactory Object ( [handles:GuzzleHttp\Handler\CurlFactory:private] => Array ( [0] => Resource id #55 ) [maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 3 ) ) ) [parameter] => Array ( [$request] => [$options] => ) ) [stack:GuzzleHttp\HandlerStack:private] => Array ( [0] => Array ( [0] => Closure Object ( [parameter] => Array ( [$handler] => ) ) [1] => http_errors ) [1] => Array ( [0] => Closure Object ( [parameter] => Array ( [$handler] => ) ) [1] => allow_redirects ) [2] => Array ( [0] => Closure Object ( [parameter] => Array ( [$handler] => ) ) [1] => cookies ) [3] => Array ( [0] => Closure Object ( [parameter] => Array ( [$handler] => ) ) [1] => prepare_body ) ) [cached:GuzzleHttp\HandlerStack:private] => Closure Object ( [static] => Array ( [handler] => GuzzleHttp\RedirectMiddleware Object ( [nextHandler:GuzzleHttp\RedirectMiddleware:private] => Closure Object ( [static] => Array ( [handler] => GuzzleHttp\PrepareBodyMiddleware Object ( [nextHandler:GuzzleHttp\PrepareBodyMiddleware:private] => Closure Object ( [static] => Array ( [default] => GuzzleHttp\Handler\CurlMultiHandler Object ( [factory:GuzzleHttp\Handler\CurlMultiHandler:private] => GuzzleHttp\Handler\CurlFactory Object ( [handles:GuzzleHttp\Handler\CurlFactory:private] => Array ( ) [maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 50 ) [selectTimeout:GuzzleHttp\Handler\CurlMultiHandler:private] => 1 [active:GuzzleHttp\Handler\CurlMultiHandler:private] => [handles:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) [delays:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) [options:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) ) [sync] => GuzzleHttp\Handler\CurlHandler Object ( [factory:GuzzleHttp\Handler\CurlHandler:private] => GuzzleHttp\Handler\CurlFactory Object ( [handles:GuzzleHttp\Handler\CurlFactory:private] => Array ( [0] => Resource id #55 ) [maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 3 ) ) ) [parameter] => Array ( [$request] => [$options] => ) ) ) ) [parameter] => Array ( [$request] => [$options] => ) ) ) ) [parameter] => Array ( [$request] => [$options] => ) ) ) [allow_redirects] => Array ( [max] => 5 [protocols] => Array ( [0] => http [1] => https ) [strict] => [referer] => [track_redirects] => ) [http_errors] => 1 [decode_content] => 1 [verify] => 1 [cookies] => [idn_conversion] => 1 [headers] => Array ( [User-Agent] => GuzzleHttp/6.5.5 curl/7.75.0 PHP/7.2.34 ) ) ) [authId:protected] =>  [authToken:protected] =>  ) [basicAuth:protected] => Plivo\Authentication\BasicAuth Object ( [authId:protected] => [authToken:protected] => ) ) [interface:protected] => [id:protected] => [pathParams:protected] => Array ( [authId] => [messageUuid] => ) [properties] => Array ( [from] => [to] => [messageDirection] => [messageState] => [messageTime] => [messageType] => [messageUuid] => [resourceUri] => [totalAmount] => [totalRate] => [units] => ) )

使用方法 2 的空结果

查看 Plivo's use case guide to receiving SMS messages。它解释了如何

  1. 创建一个 PHP 应用程序来读取消息内容
  2. 创建 Plivo SMS 应用程序并为其分配 PHP 应用程序
  3. 将 Plivo SMS 应用分配给 Plivo 号码(该号码将接收 收到的短信)
  4. 每当在该 Plivo 号码上收到传入的 SMS 消息时,Plivo 将详细信息发送到他在 Plivo SMS 中配置的应用服务器 应用程序(消息URL)