mkwsra/ zoho
Asciisd Zoho 提供了一种优雅且简单的方式与 Zoho CRM 进行通信。
Requires
- php: ^8.0
- ext-json: *
- illuminate/support: ^6.0|^7.0|^8.0
- nesbot/carbon: ^2.0
- zohocrm/php-sdk-archive: ^2.2
Requires (Dev)
- mockery/mockery: ^1.0
- orchestra/testbench: ^4.0|^5.0
- phpunit/phpunit: ^8.0|^9.0
Suggests
- ext-intl: Allows for more locales besides the default "en" when formatting money values.
README
此包用于与新的 Zoho CRM 集成
要求
- 注册一个Zoho CRM 账户。
- 注册您的应用程序
- PHP >= 7.2
- Laravel >= 6.*
安装
通过 composer require
命令将 Zoho CRM 添加到您的 composer 文件中
$ composer require asciisd/zoho
或者手动将其添加到 composer.json
"require": { "asciisd/zoho": "^1.0" }
Zoho CRM 服务提供者将自动使用 Laravel 的自动发现功能进行注册。
配置
在 config/zoho.php
中设置默认配置设置。将此文件复制到您的配置目录以修改值。您可以使用此命令发布配置
$ php artisan zoho:install
您需要将以下变量添加到您的 .env 文件中。使用之前注册应用程序时获得的凭证。
ZOHO_CLIENT_ID= ZOHO_CLIENT_SECRET= ZOHO_REDIRECT_URI= ZOHO_CURRENT_USER_EMAIL=
然后,按照以下步骤进行
- 转到 Zoho CRM 开发者控制台。
- 添加客户端
基于服务器的应用程序
。 - 输入客户端名称
您想要的任何名称
- 输入主页 URL
您的基本主页 URL
- 输入授权重定向 URI
config('app.url') . /zoho/oauth2callback
- 在终端转到您的项目位置并输入
php artisan zoho:authentication
- 复制生成的链接并在浏览器中粘贴以完成 OAuth 流程。
现在 Zoho CRM 已准备好使用。
测试
在测试之前,请确保在
tests/Fixture/Storage/oauth/logs/ZCRMClientLibrary.log
创建文件 ZCRMClientLibrary.log 并将您的 zcrm_oauthtokens.txt 放在
tests/Fixture/Storage/oauth/tokens/zcrm_oauthtokens.txt
最后,将您的环境密钥放入
ZOHO_CLIENT_ID= ZOHO_CLIENT_SECRET= ZOHO_REDIRECT_URI= ZOHO_CURRENT_USER_EMAIL=
如何使用
使用如下 ZOHO Facade
use Asciisd\Zoho\Facades\ZohoManager; // we can now deals with leads module $leads = ZohoManager::useModule('Leads');
这将返回一个 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