【问题标题】:Unable to send sms using plivo api in php无法在php中使用plivo api发送短信
【发布时间】:2021-06-28 04:08:42
【问题描述】:

我正在尝试在 PHP 中使用 Plivo API 发送短信,但所有方法都工作正常,并且还从 Plivo 获得响应,但我没有从所有这些方法中收到短信?

源代码 1

# Plivo AUTH ID
$AUTH_ID = 'my id';
# Plivo AUTH TOKEN
$AUTH_TOKEN = 'my token';
# SMS sender ID.
$src = 'sender name';
# SMS destination number
$dst = '+92123456789';
# SMS text
$text = 'Hello';
$url = 'https://api.plivo.com/v1/Account/'.$AUTH_ID.'/Message/';
$data = array("src" => "$src", "dst" => "$dst", "text" => "$text");
$data_string = json_encode($data);
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_USERPWD, $AUTH_ID . ":" . $AUTH_TOKEN);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec( $ch );
curl_close($ch);
print_r($response);

源代码 2

$auth_id = 'my auth id';
$auth_token = 'my token';
$src = 'sender number';
$dst = '+92123456789';

$text = 'Hello, this is testing message';

$api = curl_init("https://api.plivo.com/v1/Account/$auth_id/Message/");
curl_setopt_array($api, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_POST => 1,
    CURLOPT_HTTPHEADER => array("Authorization: Basic ".base64_encode($auth_id.':'.$auth_token)),
    CURLOPT_POSTFIELDS => array(
        'src' =>$src,
        'dst' => $dst,
        'text' => $text
    )
));

$resp = curl_exec($api);

$resp = curl_exec($api);
curl_close($api);

var_dump($resp);

源代码 3

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

$client = new RestClient("auth_id", "auth_token");
$response = $client->messages->create(
    'sender number', // Sender's phone number with country code
    ['+92123456789'], // receiver's phone number with country code
    "Hello, this is a sample text", // Your SMS text message        
    ["url"=>"http://test.com/plivoapi/"]
);
print_r($response);

我已经尝试了所有这些方法来发送短信无法使用 Plivo 获取短信,即使我尝试使用不同国家/地区号码获取短信

请指导我哪里做错了,或者我需要在 Plivo API 中添加一个 webhook URL 来发送短信?

【问题讨论】:

    标签: php api sms plivo


    【解决方案1】:

    通过查找问题中的目的地号码,看起来这是一个无效号码。如果您在这里仍然需要帮助,最好的选择是create a support ticket

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-30
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多