【问题标题】:Custom Sendinblue API available for CodeIgniter?可用于 CodeIgniter 的自定义 Sendinblue API?
【发布时间】:2017-11-21 10:25:56
【问题描述】:

我正在为 Codeigniter 搜索 SendinBlue API,但尚未找到。

在API还不存在的情况下,自己编写代码是不是很难(我已经知道HTTP请求但我对配置一无所知)

或者可以使用 PHP 吗?

谢谢

【问题讨论】:

标签: api codeigniter sendinblue


【解决方案1】:

我对此有一个很好的解决方案,它对我来说很好,我希望它也对你有用。 我正在使用 API-v3。

我所做的是:

  1. 在我的本地 PC 上通过 composer 下载了 API。
  2. 在服务器上创建了一个名为“sendinblue”的文件夹(我们有 assets 文件夹)并从下载的 API 上传供应商文件夹 在这个文件夹中。
  3. 创建了一个名为“Sendinblue.php”的库,并在此处添加了所有必要的功能。现在我可以像使用其他库一样使用这个库了。

这是我的库结构:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Sendinblue{
    public $config;
    public $apiInstance;
    public function __construct(){      
        require_once('sendinblue/vendor/autoload.php');
        $this->config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', '');
        $this->apiInstance = new SendinBlue\Client\Api\ContactsApi(
            new GuzzleHttp\Client(),
            $this->config
        );      
    }

    public function get_contact_info($data){
        $identifier = $data['email'];
        try {
          return $result = $this->apiInstance->getContactInfo($identifier);
        } catch (Exception $e) {
          return 'Exception when calling ContactsApi->getContactInfo: '.$e->getMessage();
        }
    }
    
    public function create_contact($data){
        $createContact = new \SendinBlue\Client\Model\CreateContact();
        $createContact['email'] = $data['email'];
        $createContact['listIds'] = [2];
        try {
          return $result = $this->apiInstance->createContact($createContact);
        } catch (Exception $e) {
          return $e->getCode();
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-25
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    • 2014-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-27
    相关资源
    最近更新 更多