jithvar/yii2-ringcentral
Composer 安装命令:
composer require jithvar/yii2-ringcentral
包简介
Send Fax using RingCentral with Yii2
关键字:
README 文档
README
This extension provides RingCentral Fax integration for Yii2 framework with OAuth 2.0 support.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist jithvar/yii2-ringcentral
or add
"jithvar/yii2-ringcentral": "*"
to the require section of your composer.json file.
Configuration
Basic Configuration
'components' => [ 'ringcentralFax' => [ 'class' => 'ringcentral\fax\RingCentralFax', 'clientId' => 'YOUR_CLIENT_ID', 'clientSecret' => 'YOUR_CLIENT_SECRET', 'serverUrl' => 'https://platform.ringcentral.com', // Use 'https://platform.devtest.ringcentral.com' for sandbox 'redirectUrl' => 'https://your-app.com/ringcentral/callback', 'tokenRefreshCallback' => function($tokens) { // Save new tokens to your storage Yii::$app->cache->set('ringcentral_access_token', $tokens['access_token']); Yii::$app->cache->set('ringcentral_refresh_token', $tokens['refresh_token']); } ], ]
OAuth 2.0 Setup
- Go to RingCentral Developer Portal
- Select your application
- Under "Auth & Security":
- Enable "OAuth 2.0"
- Enable "Issue refresh tokens"
- Add your redirect URI (e.g.,
https://your-app.com/ringcentral/callback)
Implementing OAuth Flow
- Create a controller to handle the OAuth flow:
namespace app\controllers; use Yii; use yii\web\Controller; class RingCentralController extends Controller { /** * Initiates OAuth flow */ public function actionAuth() { // Generate a random state for CSRF protection $state = Yii::$app->security->generateRandomString(); Yii::$app->session->set('ringcentral_state', $state); // Get authorization URL and redirect $authUrl = Yii::$app->ringcentralFax->getAuthorizationUrl($state); return $this->redirect($authUrl); } /** * Handles OAuth callback */ public function actionCallback() { // Verify state parameter $state = Yii::$app->request->get('state'); $savedState = Yii::$app->session->get('ringcentral_state'); if (!$state || $state !== $savedState) { throw new \yii\web\BadRequestHttpException('Invalid state parameter'); } // Exchange authorization code for tokens $code = Yii::$app->request->get('code'); try { $tokens = Yii::$app->ringcentralFax->handleOAuthCallback($code); // Tokens are automatically saved via tokenRefreshCallback Yii::$app->session->setFlash('success', 'Successfully connected to RingCentral'); return $this->redirect(['site/index']); } catch (\Exception $e) { Yii::$app->session->setFlash('error', 'Failed to connect to RingCentral: ' . $e->getMessage()); return $this->redirect(['site/index']); } } }
- Add routes in
config/web.php:
'urlManager' => [ 'enablePrettyUrl' => true, 'rules' => [ 'ringcentral/auth' => 'ring-central/auth', 'ringcentral/callback' => 'ring-central/callback', ], ],
- Add a link to start the OAuth flow:
use yii\helpers\Html; echo Html::a('Connect RingCentral', ['ring-central/auth'], ['class' => 'btn btn-primary']);
Token Management
The extension handles token management automatically:
-
When tokens are first obtained via OAuth:
- Both access and refresh tokens are saved via your
tokenRefreshCallback - The tokens are used for subsequent API calls
- Both access and refresh tokens are saved via your
-
When the access token expires:
- The extension automatically uses the refresh token to get a new access token
- Your
tokenRefreshCallbackis called with the new tokens - The failed request is automatically retried
-
If the refresh token expires:
- The user will need to re-authenticate via OAuth
- You can catch this case by checking for the 'refresh_token_expired' error
Usage
try { // Send a fax $result = Yii::$app->ringcentralFax->send([ 'to' => '+1234567890', 'files' => ['/path/to/file.pdf'], 'text' => 'Optional cover page text' ]); } catch (\yii\base\Exception $e) { if (strpos($e->getMessage(), 'refresh_token_expired') !== false) { // Redirect user to re-authenticate return $this->redirect(['ring-central/auth']); } // Handle other errors Yii::error('Fax sending failed: ' . $e->getMessage()); }
Best Practices
- Store sensitive credentials securely:
'ringcentralFax' => [ 'class' => 'ringcentral\fax\RingCentralFax', 'clientId' => getenv('RINGCENTRAL_CLIENT_ID'), 'clientSecret' => getenv('RINGCENTRAL_CLIENT_SECRET'), 'redirectUrl' => getenv('RINGCENTRAL_REDIRECT_URL'), 'serverUrl' => getenv('RINGCENTRAL_SERVER_URL'), ],
- Use environment-specific URLs:
'serverUrl' => YII_DEBUG ? 'https://platform.devtest.ringcentral.com' : 'https://platform.ringcentral.com', 'redirectUrl' => YII_DEBUG ? 'http://localhost:8080/ringcentral/callback' : 'https://your-app.com/ringcentral/callback',
- Always implement the tokenRefreshCallback to persist new tokens:
'tokenRefreshCallback' => function($tokens) { // Save to database Yii::$app->db->createCommand() ->update('settings', [ 'access_token' => $tokens['access_token'], 'refresh_token' => $tokens['refresh_token'] ], ['name' => 'ringcentral']) ->execute(); },
License
This project is licensed under the MIT License - see the LICENSE file for details.
jithvar/yii2-ringcentral 适用场景与选型建议
jithvar/yii2-ringcentral 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 01 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extension」 「yii2」 「fax」 「ringcentral」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jithvar/yii2-ringcentral 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jithvar/yii2-ringcentral 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jithvar/yii2-ringcentral 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
OpenEMR Sinch Fax integration module for secure fax sending and receiving, by OpenCoreEMR Inc
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
Adds more BBCode
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-10