承接 bitrix24/b24phpsdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

bitrix24/b24phpsdk

Composer 安装命令:

composer require bitrix24/b24phpsdk

包简介

An official PHP library for the Bitrix24 REST API

README 文档

README

Total Downloads Latest Stable Version

An official PHP library for the Bitrix24 REST API

SDK Versions

This library ships two major versions that coexist on separate branches:

v1 (main branch) v3 (v3 branch)
PHP 8.2, 8.3, 8.4 8.4, 8.5
API endpoints {portal}/rest/{user_id}/{token}/{method} {portal}/rest/api/{user_id}/{token}/{method}
New REST methods
Breaking changes No
Semver 1.* 3.*
Status Stable / production-ready Active development

Which version should I use?

  • v1 — choose this for PHP 8.2–8.4 projects, production deployments, or when you don't need the newest Bitrix24 API methods.
  • v3 — choose this for PHP 8.4+ projects that need access to new REST API methods and are comfortable adopting breaking changes.

Build status

CI\CD check main v3
allowed licenses
php-cs-fixer
phpstan
rector
deptrac
unit tests

Integration tests run in GitHub actions with real Bitrix24 portal

Installation

Install the stable v1 version (PHP 8.2+):

composer require bitrix24/b24phpsdk:"^1.0"

Install the new v3 version (PHP 8.4+, breaking changes):

composer require bitrix24/b24phpsdk:"^3.3"

If you work on Windows:

  • please use WSL - Windows Subsystem for Linux
  • if your filesystem is NTFS, you can disable the flag git config --global core.protectNTFS false for checkout folders starting with a dot.

Branch status

Branch Purpose
main Stable v1.x production releases
dev v1.x integration and pre-release testing
v3 Stable v3.x production releases
v3-dev Active v3 development with breaking changes

Each major version has its own dev branch. Cross-version changes are applied via cherry-pick — branches are never merged across major versions.

B24PhpSdk ✨FEATURES✨

Support both auth modes:

  • work with auth tokens for mass-market Bitrix24 applications
  • work with incoming webhooks for simple integration projects for a single Bitrix24 account

Domain core events:

  • Access Token expired
  • Url of a Bitrix24 account domain changed

API - level features

  • Auto renew access tokens
  • List queries with «start=-1» support
  • offline queues

Performance improvements 🚀

  • Batch queries implemented with PHP Generators – constant low memory and low CPI usage:
  • batch read data from bitrix24
  • batch write data to bitrix24
  • read without count flag

Development principles

  • Good developer experience
    • auto-completion of methods at the IDE
    • typed method call signatures
    • typed results of method calls
    • helpers for typical operations
  • Good documentation
    • documentation on the operation of a specific method containing a link to the official documentation
    • documentation for working with the SDK
  • Performance first:
    • minimal impact on client code
    • ability to work with large amounts of data with constant memory consumption
    • efficient operation of the API using batch requests
  • Modern technology stack
  • Reliable:
    • test coverage: unit, integration, contract
    • typical examples typical for different modes of operation and they are optimized for memory \ performance

Architecture

Abstraction layers

- http2 protocol via json data structures
- symfony http client
- \Bitrix24\SDK\Core\ApiClient - work with b24 rest-api endpoints
    input: arrays \ strings
    output: Symfony\Contracts\HttpClient\ResponseInterface, operate with strings
    process: network operations 
- \Bitrix24\SDK\Services\* - work with b24 rest-api entities
    input: arrays \ strings
    output: b24 response dto
    process: b24 entities, operate with immutable objects  

Documentation

Requirements

  • php: >=8.2
  • ext-json: *
  • ext-curl: *

Examples

Work with webhook

  1. Install the SDK into your project:
composer require bitrix24/b24phpsdk
  1. Open Bitrix24 account: Developer resources → Other → Inbound webhook
  2. Create a PHP file (for example webhook-example.php) and insert your webhook url into $webhookUrl:
<?php

declare(strict_types=1);

use Bitrix24\SDK\Services\ServiceBuilderFactory;

require_once 'vendor/autoload.php';

// init bitrix24-php-sdk service from webhook
$b24Service = ServiceBuilderFactory::createServiceBuilderFromWebhook('INSERT_HERE_YOUR_WEBHOOK_URL');

// call some method
var_dump($b24Service->getMainScope()->main()->getApplicationInfo()->applicationInfo());
// call core for method in not implemented service
var_dump($b24Service->core->call('user.current'));
  1. Call php file in shell
php -f webhook-example.php

Work with local application

A complete, runnable local-application example (index.php, install.php, OAuth token storage and credentials provider) is available in tests/ApplicationBridge — use it as a reference implementation.

  1. Install the SDK into your project:
composer require bitrix24/b24phpsdk
  1. Start local development server
sudo php -S 127.0.0.1:80
  1. Expose local server to public via ngrok and remember temporally public url – https://****.ngrok-free.app
ngrok http 127.0.0.1
  1. Check public url from ngrok and see x-powered-by header with 200 status-code.
curl https://****.ngrok-free.app -I
HTTP/2 200 
content-type: text/html; charset=UTF-8
date: Mon, 26 Aug 2024 19:09:24 GMT
host: ****.ngrok-free.app
x-powered-by: PHP/8.3.8
  1. Open Bitrix24 account: Developer resources → Other → Local application and create new local application:
    • type: server
    • handler path: https://****.ngrok-free.app/index.php
    • Initial installation path: https://****.ngrok-free.app/install.php
    • Menu item text: Test local app
    • scope: crm
  2. Save application parameters in index.php file:
    • Application ID (client_id)BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID
    • Application key (client_secret)BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET
    • Assing permitions (scope)BITRIX24_PHP_SDK_APPLICATION_SCOPE
see index.php file
declare(strict_types=1);

use Bitrix24\SDK\Core\Credentials\ApplicationProfile;
use Bitrix24\SDK\Services\ServiceBuilderFactory;
use Symfony\Component\HttpFoundation\Request;

require_once 'vendor/autoload.php';
?>
    <pre>
    Application is worked, auth tokens from bitrix24:
    <?= print_r($_REQUEST, true) ?>
</pre>
<?php

$appProfile = ApplicationProfile::initFromArray([
    'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => 'INSERT_HERE_YOUR_DATA',
    'BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET' => 'INSERT_HERE_YOUR_DATA',
    'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'INSERT_HERE_YOUR_DATA'
]);

$b24Service = ServiceBuilderFactory::createServiceBuilderFromPlacementRequest(Request::createFromGlobals(), $appProfile);

var_dump($b24Service->getMainScope()->main()->getCurrentUserProfile()->getUserProfile());
7. Save local application in Bitrix24 tab and press «OPEN APPLICATION» button.

Create application for Bitrix24 marketplace

if you want to create application you can use production-ready contracts in namespace Bitrix24\SDK\Application\Contracts:

  • Bitrix24Accounts — Store auth tokens and provides methods for work with Bitrix24 account.
  • ApplicationInstallations — Store information about application installation, linked with Bitrix24 Account with auth tokens. Optional can store links to:
    • Client contact person: client person who responsible for application usage
    • Bitrix24 Partner contact person: partner contact person who supports client and configure application
    • Bitrix24 Partner: partner who supports client portal
  • ContactPersons – Store information about person who installed application.
  • Bitrix24Partners – Store information about Bitrix24 Partner who supports client portal and install or configure application.

Steps:

  1. Create own entity of this bounded contexts.
  2. Implement all methods in contract interfaces.
  3. Test own implementation behavior with contract-tests tests/Unit/Application/Contracts/* – examples.

Tests

Tests locate in folder tests and we have two test types. In folder tests create file .env.local and fill environment variables from .env.

PHP Static Analysis Tool – phpstan

Call in command line

make lint-phpstan

PHP Static Analysis Tool – rector

Call in command line for validate

make lint-rector

Call in command line for fix codebase

make lint-rector-fix

Unit tests

Fast, in-memory tests without a network I\O For run unit tests you must call in command line

make test-unit

Integration tests

Slow tests with full lifecycle with your test Bitrix24 account via webhook.

❗️Do not run integration tests with production Bitrix24 accounts

For running integration test you must:

  1. Create new Bitrix24 account for development tests.
  2. Go to left menu, click «Sitemap».
  3. Find menu item «Developer resources».
  4. Click on menu item «Other».
  5. Click on menu item «Inbound webhook».
  6. Assign all permisions with webhook and click «save» button.
  7. Create file /tests/.env.local with same settings, see comments in /tests/.env file.
BITRIX24_WEBHOOK=https://your-portal.bitrix24.com/rest/1/your-webhook-token/
INTEGRATION_TEST_LOG_LEVEL=100
  1. call in command line
make test-integration-core
make test-integration-scope-telephony
make test-integration-scope-workflows
make test-integration-scope-user

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub

Thanks to all the people who contributed so far!

License

B24PhpSdk is licensed under the MIT License - see the MIT-LICENSE.txt file for details

bitrix24/b24phpsdk 适用场景与选型建议

bitrix24/b24phpsdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 43.54k 次下载、GitHub Stars 达 102, 最近一次更新时间为 2024 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 bitrix24/b24phpsdk 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 43.54k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 102
  • 点击次数: 10
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 102
  • Watchers: 8
  • Forks: 57
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-03