asciisd/zoho

Asciisd Zoho提供了一种优雅且简单的方式来与Zoho CRM进行通信。

v2.0.3 2022-09-19 00:43 UTC

README

Latest Version on Packagist Software License Total Downloads

此包曾用于与新的Zoho CRM集成。

请访问以下链接获取新包 - ZohoV3

要求

安装

通过composer require命令将Zoho CRM添加到您的composer文件中

$ composer require asciisd/zoho

或者手动将其添加到composer.json

"require": {
    "asciisd/zoho": "^1.0"
}

将使用Laravel的自动发现功能自动注册Zoho CRM服务提供者。

配置

默认配置设置在config/zoho.php中。将此文件复制到您的配置目录以修改值。您可以使用以下命令发布配置

$ php artisan zoho:install

您需要将以下变量添加到您的.env文件中。使用之前注册应用程序时获得的凭据。

ZOHO_CLIENT_ID=
ZOHO_CLIENT_SECRET=
ZOHO_REDIRECT_URI=
ZOHO_CURRENT_USER_EMAIL=

请注意 对于ZOHO_REDIRECT_URI,您需要将您的app_url作为它在.env文件中的样子,后缀为/zoho/oauth2callback,例如https://asciisd.com/zoho/oauth2callback

然后,按照以下步骤操作

  1. 转到Zoho CRM开发者控制台
  2. 添加客户端基于服务器的应用程序
  3. 输入客户端名称您想要的任何名称
  4. 输入主页URL 您的基首页URL
  5. 输入授权重定向URI config('app.url') . /zoho/oauth2callback
  6. 在终端转到您的项目位置并输入
    php artisan zoho:authentication
  7. 将生成的链接复制到浏览器中以完成OAuth过程。

现在Zoho CRM已准备好使用。

测试

在测试之前,请确保在

tests/Fixture/Storage/oauth/logs/ZCRMClientLibrary.log

上创建文件ZCRMClientLibrary.log

tests/Fixture/Storage/oauth/tokens/zcrm_oauthtokens.txt

并将您的zcrm_oauthtokens.txt放在

ZOHO_CLIENT_ID=
ZOHO_CLIENT_SECRET=
ZOHO_REDIRECT_URI=
ZOHO_CURRENT_USER_EMAIL=

最后放置您的环境密钥

如何使用

use Asciisd\Zoho\Facades\ZohoManager;

// we can now deals with leads module
$leads = ZohoManager::useModule('Leads');

使用如下ZOHO外观

这将返回一个ZohoModules的实例

v1.1.0版本开始可用

添加Zohoable作为扩展类如下:

use Asciisd\Zoho\Zohoable;
use Asciisd\Zoho\CriteriaBuilder;

class Invoice extends Zohoable {
    
    // this is your Zoho module API Name
    protected $zoho_module_name = 'Payments';

    public function searchCriteria(){
        // you should return string of criteria that you want to find current record in crm with.
        //EX:
        return CriteriaBuilder::where('PaymentID', $this->payment_id)
                              ->andWhere('Order_ID', $this->order_id)
                              ->toString();
    }

    public function zohoMandatoryFields() {
        // you should return array of mandatory fields to create module from this model
        // EX:
        return ['Base_Currency' => $this->currency];
    }
}

现在您可以像这样使用发票:

$invoice = \App\Invoice::find(1);

// to check if has zoho id stored on local database or not
$invoice->hasZohoId();

// to return the stored zoho id
$invoice->zohoId();

// that will search on zoho with provided criteria to find the record and associated your model with returned id if exist
// if you provided an `id` that will be used instead of searching on Zoho
$invoice->createOrUpdateZohoId($id = null);

// you can also send current model to zoho
// that wil use `zohoMandatoryFields` method to Serialize model to zohoObject
// Also you can pass additional fields as array to this method
$invoice->createAsZohoable($options = []);

注意:要像这样使用发票,您必须在数据库中有一个invoices表,就像您为任何Laravel模型所做的那样。这允许您将数据保存到数据库中,并能够将其链接到zohos表,并使用Zohoable中的所有功能。如果您不打算以这种方式使用Zohoable模型,请使用以下CRUD函数。

CRUD可以使用如下:

读取

use Asciisd\Zoho\Facades\ZohoManager;

// we can now deals with leads module
$leads = ZohoManager::useModule('Leads');

// find record by it's ID
$lead = $leads->getRecord('3582074000002383003');

更新

// find record by it's ID
$lead = $leads->getRecord('3582074000002383003');

// Set field with new value
$lead->setFieldValue('Last_Name', 'Ahmed');

// Then call update() method
$lead = $lead->update()->getData();

创建

// initiating a new empty instance of leads
$record = $leads->getRecordInstance();

// fill this instance with data
$record->setFieldValue('First_Name', 'Amr');
$record->setFieldValue('Last_Name', 'Emad');
$record->setFieldValue('Email', 'test@asciisd.com');
$record->setFieldValue('Phone', '012345678910');

// create the record into zoho crm then get the created instance data
$lead = $record->create()->getData();

删除

// find record by it's ID
$lead = $leads->getRecord('3582074000002383003');

$lead->delete();

搜索

文字
use Asciisd\Zoho\Facades\ZohoManager;

$records = ZohoManager::useModule('Leads')->searchRecordsByWord('word to be searched');
$first_record = $records[0];
电话
use Asciisd\Zoho\Facades\ZohoManager;

$records = ZohoManager::useModule('Leads')->searchRecordsByPhone('12345678910');
$first_record = $records[0];
电子邮件
use Asciisd\Zoho\Facades\ZohoManager;

$records = ZohoManager::useModule('Leads')->searchRecordsByEmail('nobody@asciisd.com');
$first_record = $records[0];
标准
use Asciisd\Zoho\Facades\ZohoManager;

$records = ZohoManager::useModule('Leads')->searchRecordsByCriteria('(City:equals:NY) and (State:equals:Alden)');
$first_record = $records[0];
自定义
use Asciisd\Zoho\Facades\ZohoManager;

$records = ZohoManager::useModule('Leads')
                    ->where('City', 'NY')
                    ->andWhere('State','Alden')
                    ->search();

$first_record = $records[0];

您也可以这样创建CriteriaBuilder

use Asciisd\Zoho\CriteriaBuilder;
use Asciisd\Zoho\Facades\ZohoManager;

$builder = CriteriaBuilder::where('City', 'NY')->andWhere('State','Alden')->startsWith('City', 'N');
ZohoManager::useModule('Leads')->searchRecordsByCriteria($builder->toString());

国际版本

如果您使用的是zoho.com,则无需更改任何内容。

如果您使用的是zoho.eu,请将其添加到.env

ZOHO_ACCOUNTS_URL=https://accounts.zoho.eu
ZOHO_API_BASE_URL=www.zohoapis.eu

如果您使用的是zoho.com.cn,请将其添加到.env

ZOHO_ACCOUNTS_URL=https://accounts.zoho.com.cn
ZOHO_API_BASE_URL=www.zohoapis.com.cn

许可证

MIT许可证。版权(c)2020,Asciisd

支持

联系
asciisd.com
aemad@asciisd.com
+2-010-1144-1444