tourze/wechat-work-bundle
Composer 安装命令:
composer require tourze/wechat-work-bundle
包简介
企业微信集成能力模块
README 文档
README
WeChatWork Bundle provides WeChatWork API integration capabilities for Symfony applications.
Table of Contents
- Dependencies
- Installation
- Features
- Configuration
- Quick Start
- Console Commands
- Advanced Usage
- Entity Description
- Security
- Reference Documentation
- License
Dependencies
This bundle requires:
- PHP 8.1 or higher
- Symfony 7.3 or higher
- Doctrine ORM 3.0 or higher
tourze/wechat-work-contractsfor interface definitionstourze/doctrine-timestamp-bundlefor timestamp handlingtourze/doctrine-track-bundlefor tracking changestourze/doctrine-user-bundlefor user-related functionalitytourze/doctrine-ip-bundlefor IP trackingtourze/doctrine-resolve-target-entity-bundlefor entity resolutiontourze/http-client-bundlefor HTTP client functionalitytourze/symfony-cron-job-bundlefor scheduled taskstourze/enum-extrafor enum utilitiesnesbot/carbonfor date/time handlingyiisoft/jsonfor JSON processing
Installation
composer require tourze/wechat-work-bundle
Features
- WeChatWork application management
- Automatic access token refresh
- Application information synchronization
- Enterprise information management
- Full Doctrine ORM support
- Scheduled task support
Configuration
Basic Configuration
Enable the bundle in your config/bundles.php:
<?php return [ // Other bundles... WechatWorkBundle\WechatWorkBundle::class => ['all' => true], ];
Database Configuration
Run migrations to create required tables:
php bin/console doctrine:migrations:migrate
Quick Start
1. Configure Enterprise Information
First, create a Corp entity and at least one Agent:
use WechatWorkBundle\Entity\Corp; use WechatWorkBundle\Entity\Agent; // Create enterprise $corp = new Corp(); $corp->setName('My Company'); $corp->setCorpId('your_corp_id'); // Create application $agent = new Agent(); $agent->setName('My App'); $agent->setAgentId('your_agent_id'); $agent->setSecret('your_agent_secret'); $agent->setCorp($corp); $entityManager->persist($corp); $entityManager->persist($agent); $entityManager->flush();
2. Using Services
use WechatWorkBundle\Service\WorkService; class MyService { public function __construct( private WorkService $workService ) {} public function sendMessage(): void { // The service automatically handles access token refresh $this->workService->refreshAgentAccessToken($agent); // Use the service to make API calls // Implementation depends on your specific needs } }
3. Automatic Access Token Refresh
The bundle automatically handles access token refresh. You can also manually refresh tokens:
php bin/console wechat-work:refresh-agent-access-token
Console Commands
Refresh Access Token
Refresh access tokens for all agents:
php bin/console wechat-work:refresh-agent-access-token
Synchronize Application Information
Synchronize application information from WeChatWork API:
php bin/console wechat-work:sync-agent-info
Advanced Usage
Custom Request Implementation
You can extend the WorkService to implement custom API requests:
use WechatWorkBundle\Service\WorkService; use WechatWorkBundle\Entity\Agent; class CustomWorkService extends WorkService { public function sendTextMessage(Agent $agent, string $content): array { $this->refreshAgentAccessToken($agent); $data = [ 'touser' => '@all', 'msgtype' => 'text', 'agentid' => $agent->getAgentId(), 'text' => [ 'content' => $content ] ]; return $this->request([ 'url' => $this->getBaseUrl() . '/cgi-bin/message/send', 'method' => 'POST', 'query' => ['access_token' => $agent->getAccessToken()], 'json' => $data ]); } }
Service Extension
Create custom services that utilize the WeChatWork API:
use WechatWorkBundle\Service\WorkService; use WechatWorkBundle\Repository\AgentRepository; class NotificationService { public function __construct( private WorkService $workService, private AgentRepository $agentRepository ) {} public function sendNotification(string $message): void { $agents = $this->agentRepository->findBy(['active' => true]); foreach ($agents as $agent) { // Send notification via each active agent $this->workService->refreshAgentAccessToken($agent); // Implement your notification logic here } } }
Entity Description
Corp (Enterprise)
Represents a WeChatWork enterprise:
name: Enterprise namecorpId: Unique enterprise identifieragents: Collection of associated applications
Agent (Application)
Represents a WeChatWork application within an enterprise:
name: Application nameagentId: Application identifiersecret: Application secret for API accessaccessToken: Current access token (auto-managed)accessTokenExpireTime: Token expiration timecorp: Associated enterprise
Security
Access Token Management
Access tokens are automatically managed by the bundle:
- Tokens are refreshed before expiration
- Failed refresh attempts are logged
- Tokens are stored securely in the database
Sensitive Data
Ensure proper protection of sensitive information:
- Agent secrets should be stored securely
- Access tokens are auto-generated and managed
- Consider encryption for sensitive database fields
Reference Documentation
License
This bundle is released under the MIT License. See the bundled LICENSE file for details.
tourze/wechat-work-bundle 适用场景与选型建议
tourze/wechat-work-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.46k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tourze/wechat-work-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tourze/wechat-work-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 16
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-22