Codeigniter Twilio集成

qgzx9mmu  于 7个月前  发布在  其他
关注(0)|答案(2)|浏览(72)

我试图让twilio与我的网站发送短信。
以下是我采取的步骤,
首先,我下载了最新的repo,并将Twilio文件夹放在/libraries下
然后我加了一句,

$config['composer_autoload'] = '/libraries/Twilio/autoload.php';

字符串
到http://www.php
然后在我的控制器中,
我有一个功能,

$number = 'xx';
$country = '1';

$to = '+'.$country.$number;
require(APPPATH . "/libraries/Twilio/autoload.php");

// Use the REST API Client to make requests to the Twilio REST API
// Your Account SID and Auth Token from twilio.com/console
$sid = "xx"; // Your Account SID from www.twilio.com/console
$token = "xx";
$client = new Twilio\Rest\Client($sid, $token);

// Use the client to do fun stuff like send text messages!
$client->messages->create(
    // the number you'd like to send the message to
    $to,
    array(
        // A Twilio phone number you purchased at twilio.com/console
        'xxx' => 'ADD Your Free/purchased Number',
        // the body of the text message you'd like to send
        'body' => "Hey Emir! It's Works"
    )
);


所以我的问题是,当我运行视图时,这是我得到的错误,
遇到PHP错误
严重性:警告
Copyright © 2018 www.xxx.com/public_html/application/libraries/Twilio/Twilio/Rest/Client.php All rights reserved.
所以出于某种原因,Twilio/autoload.php在路径中添加了另一个/Twilio,我无法弄清楚。
有什么需要帮忙的吗?

fgw7neuy

fgw7neuy1#

1.从存储库Twilio Php repository下载代码
2.解压缩代码,并将Twilio文件夹复制到application/libraries文件夹3.转到您(Model或Controller)想要使用库的文件。并在顶部添加这行代码。

require APPPATH.'/libraries/Twilio/autoload.php';

字符串
1.现在你可以调用和使用Twilio类。

$client = new Twilio\Rest\Client($sid, $token);
        return $client->messages->create(
            $to,
            [
                'from' => $from,
                'body' => $message
            ]
        );

wfypjpf4

wfypjpf42#

// Get the PHP helper library from twilio.com/docs/php/install
require_once 'Full/path/to/vendor/autoload.php'; // Loads the library

use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account

$sid = "AC5ef872f6da5a21de157d80997a64bd33";
$token = "your_auth_token";
$client = new Client($sid, $token);
$client->messages->create(
    "+16518675309",
    array(
    'from' => "+14158141829",
    'body' => "Tomorrow's forecast in Financial District, San Francisco is Clear.",
   'mediaUrl' => "https://climacons.herokuapp.com/clear.png",
  )
);

字符串

相关问题