如何从 codeigniter 控制器 class 调用 coinbase api 方法?

How to call coinbase api methods from codeigniter controller class?

我在 application/third_party 文件夹中添加了 coinbase php 库。现在我想在 codeigniter 根文件夹中使用该库添加一个普通的 php 文件,以将内容添加到日志文件并发送电子邮件以通知交易?

更新: 我在 application/controlers 中使用以下代码

创建了一个控制器
class Coinbase extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->database();   
    }

    function readnotifications()
    {
        echo APPPATH;
        require_once(APPPATH.'third_party/coinbase-php/vendor/autoload.php');
        use Coinbase\Wallet\Client;
}
}

我遇到以下错误。

Parse error: syntax error, unexpected 'use' (T_USE)

更新 2:

$config['composer_autoload'] = APPPATH.'third_party/coinbase-php/vendor/autoload.php';

class Coinbase extends CI_Controller
{
    function readnotifications()
    {

$apiKey = "sss ";
$apiSecret =  "sss";
        namespace Coinbase\Wallet;
        use Coinbase\Wallet\Client;
        use Coinbase\Wallet\Configuration;
        use Coinbase\Wallet\Enum\Param;
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$authenticity = $client->verifyCallback($raw_body, $signature); // boolean
}
}

Parse error: syntax error, unexpected 'Coinbase' (T_STRING), expecting \ (T_NS_SEPARATOR)

知道如何解决吗?

在你application/config/config.php中搜索$config['composer_autoload']并设置你的第三方包autoload.php文件路径作为其值

$config['composer_autoload'] = '/path/to/vendor/autoload.php';

然后你可以像这样简单地使用你的任何包 类

function readnotifications()
{
        $client = Coinbase\Wallet\Client;
}

也看看这个https://www.codeigniter.com/user_guide/general/autoloader.html