致命错误:未找到“客户”类

时间:2017-06-30 06:08:40

标签: wordpress woocommerce twilio

将Twilio SMS APi添加到我的网站时出错。我的网站使用wordpress并使用Woo商务。

错误: Fatal error: Class 'Client' not found in /var/www/html/++++/wp-content/themes/dokan-theme-v2.2.2-child/functions.php on line 4583

我的代码如下:

function wl8OrderPlacedTriggerSomething($order_id){
      //do something...

      //echo get_stylesheet_directory_uri(). '/twilio-php-master/Twilio/Rest/Client.php';

      require_once( get_stylesheet_directory_uri(). '/twilio-php-master/Twilio/autoload.php');
      require( get_stylesheet_directory_uri(). '/twilio-php-master/Twilio/Rest/Client.php');

        // Use the REST API Client to make requests to the Twilio REST API
     // use Twilio\Rest\Client;

        // Your Account SID and Auth Token from twilio.com/console
        $sid = 'xxxxxxxxxxxxxxxxxxxxxx';
        $token = 'xxxxxxxxxxxxxxxx';
        $client = new 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  (xxxxxxx)
            'xxxxxxxxx',
            array(
                // A Twilio phone number you purchased at twilio.com/console
                'from' => '+xxxxxxx',
                // the body of the text message you'd like to send
                'body' => "Hey Jenny! Good luck on the bar exam!"
            )
        );

}

请帮助我。

谢谢,

2 个答案:

答案 0 :(得分:1)

Twilio开发者传道者在这里。

在这种情况下,我认为您可能需要使用Client的完全限定名称空间。尝试:

$client = new Twilio\Rest\Client($sid, $token);

如果有帮助,请告诉我。

修改

好的,那不起作用。读完之后,我发现it's not recommended to use require or require_once within a function。我建议您在函数之外需要自动加载文件use命名空间,然后调用函数内的Client。像这样:

require_once( get_stylesheet_directory_uri(). '/twilio-php-master/Twilio/autoload.php');
use Twilio\Rest\Client;

function wl8OrderPlacedTriggerSomething($order_id){

    $sid = 'xxxxxxxxxxxxxxxxxxxxxx';
    $token = 'xxxxxxxxxxxxxxxx';
    $client = new Client($sid, $token);

    // and so on...
}

答案 1 :(得分:0)

确保正确加载autoload.php和Client.php文件。 它无法加载客户端调用