tourze / wechat-work-server-bundle
企业微信服务端消息处理包,用于接收和处理企业微信回调消息
Installs: 253
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/wechat-work-server-bundle
Requires
- php: ^8.1
- ext-openssl: *
- doctrine/collections: ^2.3
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^3.1 || ^4
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/console: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/doctrine-bridge: ^6.4
- symfony/event-dispatcher: ^6.4
- symfony/event-dispatcher-contracts: ^2.5 | ^3
- symfony/framework-bundle: ^6.4
- symfony/http-foundation: ^6.4
- symfony/http-kernel: ^6.4
- symfony/lock: ^6.4
- symfony/routing: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/doctrine-snowflake-bundle: 0.1.*
- tourze/easy-admin-attribute: 0.1.*
- tourze/wechat-helper: 0.0.*
- tourze/wechat-work-bundle: 0.1.*
- tourze/wechat-work-contracts: 0.0.*
- tourze/xml-helper: 0.0.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-10-31 20:12:21 UTC
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.