当前位置: 动力学知识库 > 问答 > 编程问答 >

cakephp - How to send sms by plivo api it require autoload.php

问题描述:

How to send sms by plivo api it say

require vendor/autoload.php

But i cannot find any autoload.php , it have also composer.json

when i run this is get error

Class 'GuzzleHttp\Client' not found

here the my code

<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";

}

网友答案:

Thank you now i solved this by myself this is the code hope this is useful for you guys..

$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;
分享给朋友:
您可能感兴趣的文章:
随机阅读: