tourze/wechat-work-server-bundle
最新稳定版本:0.1.0
Composer 安装命令:
composer require tourze/wechat-work-server-bundle
包简介
企业微信服务端消息处理包,用于接收和处理企业微信回调消息
README 文档
README
A Symfony bundle for handling WeChat Work (企业微信) server-side messages and callback events.
Table of Contents
- Features
- Installation
- Configuration
- Database Migration
- Quick Start
- Usage
- Advanced Usage
- Dependencies
- Contributing
- License
Features
- 🚀 Server Message Processing: Handle WeChat Work callback messages
- 🔒 Message Encryption/Decryption: Support for encrypted message processing
- 📊 Message Storage: Store and query server messages with Doctrine ORM
- 🎯 Event System: Dispatch events for message processing
- 📝 Console Commands: Import and manage server messages
- 🔄 Callback Controllers: Handle direct and server callbacks
Installation
composer require tourze/wechat-work-server-bundle
Configuration
Bundle Registration
Enable the bundle in your Symfony application:
// config/bundles.php return [ // ... WechatWorkServerBundle\WechatWorkServerBundle::class => ['all' => true], ];
Route Configuration
Configure the routes for server callbacks:
# config/routes.yaml wechat_work_server: resource: '@WechatWorkServerBundle/config/routes.yaml' prefix: /wechat-work/server
Database Migration
Run the following command to create the necessary database tables:
php bin/console doctrine:migrations:migrate
Quick Start
Handling Server Messages
use WechatWorkServerBundle\Entity\ServerMessage; use WechatWorkServerBundle\Event\WechatWorkServerMessageRequestEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class MessageHandler implements EventSubscriberInterface { public static function getSubscribedEvents() { return [ WechatWorkServerMessageRequestEvent::class => 'onServerMessage', ]; } public function onServerMessage(WechatWorkServerMessageRequestEvent $event) { $message = $event->getMessage(); // Process the message based on type switch ($message->getMsgType()) { case 'text': $this->handleTextMessage($message); break; case 'event': $this->handleEventMessage($message); break; } } }
Usage
Message Entity
The ServerMessage entity stores WeChat Work server messages:
use WechatWorkServerBundle\Entity\ServerMessage; use WechatWorkServerBundle\Repository\ServerMessageRepository; // Get message repository $repository = $entityManager->getRepository(ServerMessage::class); // Create message from XML $message = $repository->createFromXML($xmlContent); if ($message) { $entityManager->persist($message); $entityManager->flush(); } // Find messages by type $textMessages = $repository->findBy(['msgType' => 'text']); // Find messages by user $userMessages = $repository->findBy(['fromUserName' => 'user123']);
Console Commands
The bundle provides console commands for managing server messages:
# Import server messages from log file
php bin/console wechat-work:import-server-message /path/to/message.log
Command Details:
- wechat-work:import-server-message - Import WeChat Work server messages from a log file
Advanced Usage
Custom Message Processing
use WechatWorkServerBundle\Controller\ServerCallbackController; use Symfony\Component\HttpFoundation\Request; // Custom callback handling class CustomCallbackController extends ServerCallbackController { protected function processMessage(array $messageData): void { // Custom processing logic parent::processMessage($messageData); } }
Message Filtering
use WechatWorkServerBundle\Repository\ServerMessageRepository; class CustomMessageRepository extends ServerMessageRepository { public function findRecentMessages(int $limit = 50): array { return $this->createQueryBuilder('m') ->orderBy('m.createTime', 'DESC') ->setMaxResults($limit) ->getQuery() ->getResult(); } }
Dependencies
- PHP 8.1+
- Symfony 6.4+
- Doctrine ORM 3.0+
- tourze/wechat-work-bundle
- tourze/wechat-helper
- tourze/xml-helper
Contributing
We welcome contributions! Please follow these guidelines:
- Issues: Please use GitHub Issues to report bugs or request features
- Pull Requests:
- Fork the repository
- Create a feature branch
- Make your changes with proper tests
- Ensure PHPStan and PHPUnit tests pass
- Submit a pull request
Development Setup
# Clone the repository git clone https://github.com/your-org/php-monorepo.git cd php-monorepo # Install dependencies composer install # Run tests ./vendor/bin/phpunit packages/wechat-work-server-bundle/tests # Run static analysis php -d memory_limit=2G ./vendor/bin/phpstan analyse packages/wechat-work-server-bundle
License
This project is licensed under the MIT License - see the LICENSE file for details.
统计信息
- 总下载量: 268
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-18