无法使用php中的plvo令牌和auth id获取或显示收到的SMS

2022-03-01 00:00:00 api sms php plivo

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

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

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

方法1

require 'vendor/autoload.php';
use PlivoRestClient;

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

方法2

require 'vendor/autoload.php';
use PlivoRestClient;

$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的结果

PlivoResourcesMessageMessage Object ( [client:protected] => PlivoBaseClient Object ( [timeout:protected] => [httpClientHandler:protected] => PlivoHttpClientsPlivoGuzzleHttpClient Object ( [guzzleClient:protected] => GuzzleHttpClient Object ( [config:GuzzleHttpClient:private] => Array ( [handler] => GuzzleHttpHandlerStack Object ( [handler:GuzzleHttpHandlerStack:private] => Closure Object ( [static] => Array ( [default] => GuzzleHttpHandlerCurlMultiHandler Object ( [factory:GuzzleHttpHandlerCurlMultiHandler:private] => GuzzleHttpHandlerCurlFactory Object ( [handles:GuzzleHttpHandlerCurlFactory:private] => Array ( ) [maxHandles:GuzzleHttpHandlerCurlFactory:private] => 50 ) [selectTimeout:GuzzleHttpHandlerCurlMultiHandler:private] => 1 [active:GuzzleHttpHandlerCurlMultiHandler:private] => [handles:GuzzleHttpHandlerCurlMultiHandler:private] => Array ( ) [delays:GuzzleHttpHandlerCurlMultiHandler:private] => Array ( ) [options:GuzzleHttpHandlerCurlMultiHandler:private] => Array ( ) ) [sync] => GuzzleHttpHandlerCurlHandler Object ( [factory:GuzzleHttpHandlerCurlHandler:private] => GuzzleHttpHandlerCurlFactory Object ( [handles:GuzzleHttpHandlerCurlFactory:private] => Array ( [0] => Resource id #55 ) [maxHandles:GuzzleHttpHandlerCurlFactory:private] => 3 ) ) ) [parameter] => Array ( [$request] => [$options] => ) ) [stack:GuzzleHttpHandlerStack: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:GuzzleHttpHandlerStack:private] => Closure Object ( [static] => Array ( [handler] => GuzzleHttpRedirectMiddleware Object ( [nextHandler:GuzzleHttpRedirectMiddleware:private] => Closure Object ( [static] => Array ( [handler] => GuzzleHttpPrepareBodyMiddleware Object ( [nextHandler:GuzzleHttpPrepareBodyMiddleware:private] => Closure Object ( [static] => Array ( [default] => GuzzleHttpHandlerCurlMultiHandler Object ( [factory:GuzzleHttpHandlerCurlMultiHandler:private] => GuzzleHttpHandlerCurlFactory Object ( [handles:GuzzleHttpHandlerCurlFactory:private] => Array ( ) [maxHandles:GuzzleHttpHandlerCurlFactory:private] => 50 ) [selectTimeout:GuzzleHttpHandlerCurlMultiHandler:private] => 1 [active:GuzzleHttpHandlerCurlMultiHandler:private] => [handles:GuzzleHttpHandlerCurlMultiHandler:private] => Array ( ) [delays:GuzzleHttpHandlerCurlMultiHandler:private] => Array ( ) [options:GuzzleHttpHandlerCurlMultiHandler:private] => Array ( ) ) [sync] => GuzzleHttpHandlerCurlHandler Object ( [factory:GuzzleHttpHandlerCurlHandler:private] => GuzzleHttpHandlerCurlFactory Object ( [handles:GuzzleHttpHandlerCurlFactory:private] => Array ( [0] => Resource id #55 ) [maxHandles:GuzzleHttpHandlerCurlFactory: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] => PlivoAuthenticationBasicAuth 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短信应用并为其分配PHP应用
  3. 将Plivo SMS应用程序分配给Plivo号码(将收到 传入短信)
  4. 每当在该Plivo号码上接收到传入SMS消息时,Plivo 会将详细信息发送到他在Plivo SMS中配置的应用程序服务器 APP(消息URL)

相关文章