alexacrm / php-crm-toolkit
微软Dynamics CRM的PHP工具包
20230730
2023-07-30 08:05 UTC
Requires
- psr/log: *
Requires (Dev)
- phpunit/phpunit: >=5.6.3
This package is auto-updated.
Last update: 2024-08-30 01:09:46 UTC
README
PHP CRM Toolkit为PHP应用程序提供与微软Dynamics CRM的集成。
此工具包仅支持Dynamics 365 SOAP接口。有关Dynamics 365 Web API的PHP实现,请参阅dynamics-webapi-toolkit项目。
安装
使用以下命令安装最新版本
$ composer require alexacrm/php-crm-toolkit:dev-master
示例
/** * Use init.php if you didn't install the package via Composer */ require_once 'vendor/autoload.php'; use AlexaCRM\CRMToolkit\Client as OrganizationService; use AlexaCRM\CRMToolkit\Settings; $contactId = '1d2fc62f-1c56-448b-b546-edfb6d6fec5c'; /* * WS-Trust is now deprecated $options = [ 'serverUrl' => 'https://org.crmN.dynamics.com', 'username' => 'portal@org.onmicrosoft.com', 'password' => 'portalPassword', 'authMode' => 'OnlineFederation', ]; $serviceSettings = new Settings( $options ); */ $options = [ 'serverUrl' => 'https://org.crmN.dynamics.com', 'applicationId' => '1111c62f-dead-beef-dead-edfbffffec5c', 'clientSecret' => 'whateveristhesecretgenerated', 'authMode' => 'OnlineFederation', 'authMethod' => 'sharedSecretAuth', 'cache' => new AlexaCRM\CRMToolkit\NullCache(), ]; // This code uses NullCache which allows to connect and run the operations // but it is very inefficient and should not be used in production. // You can use any PSR-6 compliant cache implementation. $serviceSettings = new OnlineS2SSecretAuthenticationSettings( $options ); $service = new OrganizationService( $serviceSettings ); // retrieve a contact and update its fields $contact = $service->entity( 'contact', $guid ); $contact->firstname = explode( '@', $contact->emailaddress1 )[0]; $contact->update(); printf( 'Info for %s %s updated.', $contact->firstname, $contact->lastname ); // create a new contact $contact = $service->entity( 'contact' ); $contact->firstname = 'John'; $contact->lastname = 'Doe'; $contact->emailaddress1 = 'john.doe@example.com'; $contactId = $contact->create(); // delete a contact $contact->delete(); // execute an action $whoAmIResponse = $service->executeAction( 'WhoAmI' ); echo 'Organization ID: ' . $whoAmIResponse->OrganizationId; // inject cache repo // must be instance of AlexaCRM\CRMToolkit\CacheInterface $cacheRepo = Cache::instance(); $service = new Client( $serviceSettings, $cacheRepo );
在/examples/
目录中,您可以找到一些工具包使用示例。将config.example.php
复制到config.php
,设置CRM凭据,您就可以开始使用了!
贡献
在GitHub仓库中欢迎接受拉取请求。
许可证
版权所有 (c) 2016 AlexaCRM。
本程序是自由软件:您可以在自由软件基金会发布的GNU通用公共许可证的条款下重新分发和/或修改它,许可证版本为3。
本程序是在希望它有用的希望下分发的,但没有任何保证;甚至没有关于其商业性或适用于特定目的的隐含保证。有关更多详细信息,请参阅GNU通用公共许可证。
您应已收到一份GNU通用公共许可证副本。如果没有,请参阅https://gnu.ac.cn/licenses/。