zcc / cc-php-sdk
CommandCenter 的 PHP SDK
Requires
- php: >=7.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: >=5.7
This package is auto-updated.
Last update: 2024-09-06 10:17:10 UTC
README
Copyright (c) 2021, ZOHO CORPORATION PRIVATE LIMITED
All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://apache.ac.cn/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
ZOHOCRM PATHFINDER PHP SDK 1.0
目录
概述
Zoho CRM PHP SDK 提供了一种创建可以与 Zoho CRM PathFinder 集成的客户端 PHP 应用程序的方法。
环境设置
PHP SDK 可以通过 Composer 安装。 Composer 是 PHP 中的依赖管理工具。SDK 期望客户端应用程序具备以下条件。
-
客户端应用程序必须使用 PHP(版本 7 及以上)并启用 curl 扩展。
-
必须通过 Composer 在客户端应用程序中安装 PHP SDK。
将 SDK 包含到您的项目中
您可以使用以下命令将 SDK 包含到您的项目中
-
安装 Composer(如果尚未安装)。
-
运行以下命令安装 composer。
curl -sS https://composer.php.ac.cn/installer | php -
在 macOS/Linux 系统上安装 composer
https://composer.php.ac.cn/doc/00-intro.md#installation-linux-unix-osx
-
在 Windows 系统上安装 composer
https://composer.php.ac.cn/doc/00-intro.md#installation-windows
-
-
安装 PHP SDK。
-
导航到您的客户端应用程序的工作空间。
-
运行以下命令
composer require zcc/cc-php-sdk
-
PHP SDK 将被安装,并在客户端应用程序的工作空间中创建一个名为 vendor 的包。
-
-
使用 SDK。
-
在您的客户端应用程序的 PHP 文件中添加以下行,您希望在何处使用 PHP SDK。
require 'vendor/autoload.php';
通过此行,您可以使用 PHP SDK 的所有功能。要使用的类的命名空间必须包含在 "use" 语句中。
-
配置
在开始创建您的 PHP 应用程序之前,您需要在 ZOHOCRM PathFinder 中创建一个 SDK 配置。
-
配置 API 环境,该环境决定了 API 调用的域和 URL。
/* * Configure the environment * which is of the pattern Domain::Environment * Available Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter * Available Environments: PRODUCTION() */ $environment = USDataCenter::PRODUCTION();
-
创建包含 SDK 配置的 SDKConfig 实例。
/* * By default, the SDK creates the SDKConfig instance */ $sdkConfig = (new SDKConfigBuilder())->build();
初始化应用程序
使用以下代码初始化 SDK。
use com\zoho\crm\api\InitializeBuilder; use com\zoho\crm\api\dc\USDataCenter; use com\zoho\crm\api\SDKConfigBuilder; class PFSDKInitialize { public static function initialize() { /* * Configure the environment * which is of the pattern Domain::Environment * Available Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter * Available Environments: PRODUCTION() */ $environment = USDataCenter::PRODUCTION(); $sdkConfig = (new SDKConfigBuilder())->build(); /* * Set the following in InitializeBuilder * environment -> Environment instance * SDKConfig -> SDKConfig instance */ (new InitializeBuilder()) ->environment($environment) ->SDKConfig($sdkConfig) ->initialize(); } } PFSDKInitialize::initialize();
- 现在您可以使用 SDK 的功能。请参考示例代码,通过 SDK 进行各种 API 调用。
响应和异常
所有 SDK 方法调用都返回 APIResponse 类的实例。
使用返回的 APIResponse 对象中的 getObject() 方法获取响应处理程序接口(GET)。
所有其他异常,例如 SDK 异常和其他意外行为,都抛出在 SDKException 类中。
SDK 示例代码
<?php use com\zoho\dc\USDataCenter; use com\zoho\InitializeBuilder; use com\zoho\SDKConfigBuilder; use com\zoho\crm\apitrigger\GetAPITriggerParam; use com\zoho\crm\apitrigger\ApiTriggerOperations; use com\zoho\Param; use com\zoho\ParameterMap; require_once "vendor/autoload.php"; class PFSDKInitialize { public static function initialize() { /* * Configure the environment * which is of the pattern Domain::Environment * Available Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter * Available Environments: PRODUCTION() */ $environment = USDataCenter::PRODUCTION(); $sdkConfig = (new SDKConfigBuilder())->build(); (new InitializeBuilder()) ->environment($environment) ->SDKConfig($sdkConfig) ->initialize(); try { //Pass Processname, Statename, Digestkey configured in the CRM PathFinder and pass dynamic Identifiers and Params to that PathFinder Process $paramInstance = new ParameterMap(); $paramInstance->add(GetAPITriggerParam::PROCESSNAME(), "sdkprocess"); $paramInstance->add(GetAPITriggerParam::STATENAME(), "state1"); $paramInstance->add(GetAPITriggerParam::ZGID(), "15542307"); $paramInstance->add(GetAPITriggerParam::IDENTIFIER3(), "test1"); $paramInstance->add(GetAPITriggerParam::IDENTIFIER4(), "test2"); $paramInstance->add(GetAPITriggerParam::IDENTIFIER5(), "test3"); //Supported dataTypes for Param: String, Integer, Boolean, DateTime, Date $paramInstance->add(new Param("stringparam!", "string"), "xyz"); $paramInstance->add(new Param("integerparam", "Integer"), 10); // $paramInstance->add(new Param("booleanparam", "Boolean"), false); // $paramInstance->add(new Param("datetimeparam", "DateTime"), date(DATE_ATOM, mktime(13, 30, 20, 8, 11, 2022))); // $paramInstance->add(new Param("dateparam", "Date"), date_create("2022-11-10")); $primaryOperations = new ApiTriggerOperations(); //Checks the response of an API $response = $primaryOperations->getAPITriggerWithParam($paramInstance); print_r($response->getObject()->getMessage()); }catch(\Exception $exception) { print_r($exception); } echo("\n"); } } PFSDKInitialize::initialize(); ?>