如何通过plivo api发送短信需要autoload.php

时间:2016-10-14 08:00:01

标签: php cakephp plivo

如何通过plivo api发送短信它说 需要vendor / autoload.php 但我找不到任何autoload.php,它也有composer.json 当我运行这是得到错误

未找到类'GuzzleHttp \ Client'

这里是我的代码

<form action="send_sms_from_browser.php" method="post">
From No:<input type="text" name="From"><br><br>
To&nbsp;&nbsp;&nbsp;&nbsp;No:<input type="text" name="To"><br><br>
Message:<br>
<textarea name="Text" rows="3" cols="30" >Message Text</textarea><br>     <br>
<input type="submit" value="Send SMS">
</form> 


error_reporting(E_ALL);
require_once 'vendor/autoload.php';
use Plivo\RestAPI;
$to = $_POST['To'];
$from = $_POST['From'];
$text = $_POST['Text'];
echo "<br/>Sent Message info:<br/><br/>To: $to<br/>";
echo "From: $from  <br/>";
echo "Message: $text <br/>";
$auth_id = 'Auth id';
$auth_token = "Token";

$p = new RestAPI($auth_id, $auth_token);

print_r($p);
// Send a message
$params = array(
        'src' => "$from",
        'dst' => "$to",
        'text' => "$text",
        'type' => 'sms',
    );
$response = $p->send_message($params);
echo $response[0];
if (array_shift(array_values($response)) == "202")
{
    echo "<br/><br/>Message status: Sent";
}
else
{
    echo "<br/><br/>Error: Please ensure that From number is a valid";
}

1 个答案:

答案 0 :(得分:0)

谢谢你,我现在自己解决了这个代码希望这对你们有用..

$ch = curl_init();
$data = '{"src": "source number with country code","dst": "receiver with country code", "text": "Hi, text from Plivo"}';


 curl_setopt($ch, CURLOPT_URL, "https://api.plivo.com/v1/Account/AUTH_ID/Message/");
 curl_setopt($ch, CURLOPT_POST, true);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
 curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Content-Type: application/json"
 ));


curl_setopt($ch, CURLOPT_USERPWD, "AUTH_ID:TOKEN_ID");
$result = curl_exec($ch);
print_r($result);exit;