michaelhull/connectwise-php-client 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

michaelhull/connectwise-php-client

Composer 安装命令:

composer require michaelhull/connectwise-php-client

包简介

SPINEN's PHP Client for ConnectWise.

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version Dependency Status License

PHP client for the RestFull ConnectWise APIs. This package used to be based on the SOAP APIs & had 3 separate repositories, but as of this version there is only this one.

We solely use Laravel for our applications, so there is some Laravel specific files that you can use if you are using this client in a Laravel application. We have tried to make sure that you can use the client outside of Laravel, and have some documentation about it below.

Note about the integration

We are using the "Member Impersonation" model where you setup an integrator username & password with access to the "Member API", which makes all calls to ConnectWise performed under the permission of the user (member id) of the application.

We make all of our ConnectWise users' member ID equal to their email (i.e. joe.doe@spinen.com has a member ID of joedoe in connectwise) [NOTE: The "." was removed from joe.doe as ConnectWise does not allow dots in the member ID]. By following this convention, we can infer the member ID from the logged in user's email address in our applications. We have included a trait that you can use on the User model that will preform the logic above.

Laravel Configuration and Usage

Configuration

  1. Add the following to config/services.php...
    'connectwise' =>  [
        'company_id' => env('CW_COMPANY_ID'),
        'integrator' => env('CW_INTEGRATOR'),
        'password' => env('CW_PASSWORD'),
        'url' => env('CW_URL'),
    ],
  1. Add the appropriate values to your .env...
CW_COMPANY_ID=<company_id>
CW_INTEGRATOR=<integrator username>
CW_PASSWORD=<integrator password>
CW_URL=https://<FQDN to ConnectWise server>
  1. Add the provider to config/app.php
'providers' => [
    # other providers omitted
    Spinen\ConnectWise\Laravel\ServiceProvider::class,
],
  1. [Optional] Add the alias to config/app.php
'aliases' => [
    # other aliases omitted
    'ConnectWise' => Spinen\ConnectWise\Laravel\Facades\ConnectWise::class,
],
  1. Use the ConnectWiseMemberIdFromEmail trait on the User model, which is located at Spinen\ConnectWise\Laravel\ConnectWiseMemberIdFromEmail, if your ConnectWise member_id is a match to your email as described above. If you do not follow that convention, then you can define your own getConnectWiseMemberIdAttribute accessor on the User model or just add a connect_wise_member_id column to your user table that you populate with the appropriate values.

Usage

Here is an example of getting the system information...

As of version 3.1.0, the response is either a Laravel collection of models or a single model. You can see the models in src/Models. They all extend Spinen\ConnectWise\Support, so you can see the methods that they provide.

$ php artisan tinker
Psy Shell v0.8.0 (PHP 7.0.14 — cli) by Justin Hileman
>>> Auth::loginUsingId(1);
PHP warning:  unlink(/Users/jimmy.puckett/git/swaginator.com/storage/framework/sessions/1aMf1yhUe6h4Ij2GRvq5UYab1IqK7GVn1qkyWPY6): No such file or directory in /Users/jimmy.puckett/git/swaginator.com/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php on line 172
=> App\User {#983
     id: "1",
     first_name: "Joe",
     last_name: "Doe",
     email: "joe.doe@domain.tld",
     admin: "0",
     created_at: "2017-01-02 18:30:47",
     updated_at: "2017-01-12 22:22:39",
     logged_in_at: "2017-01-12 22:22:39",
     deleted_at: null,
   }
>>> $cw = app('Spinen\ConnectWise\Api\Client');
=> Spinen\ConnectWise\Api\Client {#934}
>>> $info = $cw->get('system/info');
=> Spinen\ConnectWise\Models\System\Info {#1008}
>>> $info->toArray();
=> [
     "version" => "v2016.6.43325",
     "isCloud" => false,
     "serverTimeZone" => "Eastern Standard Time",
   ]
>>> $info->toJson()
=> "{"version":"v2016.6.43325","isCloud":false,"serverTimeZone":"Eastern Standard Time"}"
>>> $info->isCloud
=> false
>>> $info['isCloud'];
=> false

Same call using the facade...

$ php artisan tinker
Psy Shell v0.8.0 (PHP 7.0.14 — cli) by Justin Hileman
>>> Auth::loginUsingId(1);
PHP warning:  unlink(/Users/jimmy.puckett/git/swaginator.com/storage/framework/sessions/1aMf1yhUe6h4Ij2GRvq5UYab1IqK7GVn1qkyWPY6): No such file or directory in /Users/jimmy.puckett/git/swaginator.com/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php on line 172
=> App\User {#983
     id: "1",
     first_name: "Joe",
     last_name: "Doe",
     email: "joe.doe@domain.tld",
     admin: "0",
     created_at: "2017-01-02 18:30:47",
     updated_at: "2017-01-12 22:22:39",
     logged_in_at: "2017-01-12 22:22:39",
     deleted_at: null,
   }
>>> ConnectWise::get('system/info');
=> Spinen\ConnectWise\Models\System\Info {#1005}
>>> ConnectWise::get('system/info')->toArray();
=> [
     "version" => "v2016.6.43325",
     "isCloud" => false,
     "serverTimeZone" => "Eastern Standard Time",
   ]
>>> ConnectWise::get('system/info')->toJson();
=> "{"version":"v2016.6.43325","isCloud":false,"serverTimeZone":"Eastern Standard Time"}"
>>> ConnectWise::get('system/info')->isCloud;
=> false
>>> ConnectWise::get('system/info')['isCloud'];
=> false
>>>

Non-Laravel Usage

To use the client outside of Laravel, you just need to new-up the objects...

$ php -a
Interactive shell

php > // Autoload classes
php > require 'vendor/autoload.php';
php > // New-up objects
php > $token = new Spinen\ConnectWise\Api\Token();
php > $guzzle = new GuzzleHttp\Client();
php > $resolver = new Spinen\ConnectWise\Support\ModelResolver();
php > $client = new Spinen\ConnectWise\Api\Client($token, $guzzle, $resolver);
php > // Now set your configs
php > $token->setCompanyId('<company_id>')->setMemberId('<member_id>');
php > $client->setIntegrator('<integrator>')->setPassword('<password>')->setUrl('https://<domain.tld>');
php > $info = $client->get('system/info');
php > var_export($info, false);
Spinen\ConnectWise\Models\System\Info::__set_state(array(
   'casts' =>
  array (
    'version' => 'string',
    'isCloud' => 'boolean',
    'serverTimeZone' => 'string',
  ),
   'attributes' =>
  array (
    'version' => 'v2016.6.43325',
    'isCloud' => false,
    'serverTimeZone' => 'Eastern Standard Time',
  ),
))
php > var_export($info->toArray(), false);
array (
  'version' => 'v2016.6.43325',
  'isCloud' => false,
  'serverTimeZone' => 'Eastern Standard Time',
)
php > var_export($info->tojson(), false);
'{"version":"v2016.6.43325","isCloud":false,"serverTimeZone":"Eastern Standard Time"}'
php > var_export($info->isCloud, false);
false
php > var_export($info['isCloud'], false);
false
php >

michaelhull/connectwise-php-client 适用场景与选型建议

michaelhull/connectwise-php-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 05 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「client」 「spinen」 「connectwise」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 michaelhull/connectwise-php-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 michaelhull/connectwise-php-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 michaelhull/connectwise-php-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-05-08