tourze / wechat-work-msg-audit-bundle
企业微信会话内容存档管理 Symfony Bundle
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/wechat-work-msg-audit-bundle
Requires
- php: ^8.1
- doctrine/collections: ^2.3
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^3.1 || ^4
- league/flysystem: ^3.10
- mochat/wework-finance-sdk: ^1.1
- nesbot/carbon: ^2.72 || ^3
- symfony/config: ^6.4
- symfony/console: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/doctrine-bridge: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-kernel: ^6.4
- symfony/var-exporter: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/doctrine-snowflake-bundle: 0.1.*
- tourze/easy-admin-attribute: 0.1.*
- tourze/enum-extra: 0.1.*
- tourze/http-client-bundle: 0.1.*
- tourze/symfony-cron-job-bundle: 0.1.*
- tourze/wechat-work-bundle: 0.1.*
- tourze/wechat-work-contracts: 0.0.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
- symfony/phpunit-bridge: ^6.4
This package is auto-updated.
Last update: 2025-11-01 19:33:45 UTC
README
A Symfony bundle for WeChat Work (企业微信) conversation content archiving functionality.
Features
- Automatic synchronization of archived messages from WeChat Work
- Support for various message types (text, image, voice, video, etc.)
- Media file download and storage
- Message querying and management
- Integration with WeChat Work Finance SDK
- Cron job support for automatic message synchronization
Installation
composer require tourze/wechat-work-msg-audit-bundle
Configuration
This bundle requires the following configuration:
- WeChat Work Corp Configuration: Set up your corporation and agent with the message archive application (Special Agent ID: 1000022)
- Private Key: Configure the private key for message decryption in your agent settings
- Storage: Configure filesystem storage for media files
Usage
Console Commands
Sync Archive Messages
Synchronize archived messages from WeChat Work:
# Sync all messages for all configured corporations php bin/console wechat-work:sync-archive-message # Sync messages for a specific corporation php bin/console wechat-work:sync-archive-message <corpId> # Sync messages for a specific agent php bin/console wechat-work:sync-archive-message <corpId> <agentId>
This command:
- Fetches new messages from WeChat Work archive API
- Downloads media files (images, voice, video) automatically
- Stores messages in the database
- Can be configured to run as a cron job (runs every minute by default)
Test Commands
For testing purposes, the bundle includes test commands:
# Simple test command for integration testing
php bin/console test:simple
This command is used internally for testing CommandTester integration.
API Requests
Get Permit User List
Retrieve the list of users who have enabled message archiving:
use WechatWorkMsgAuditBundle\Request\GetPermitUserListRequest; $request = new GetPermitUserListRequest(); $request->setAgent($agent); $request->setType(1); // 1: Office edition, 2: Service edition, 3: Enterprise edition $response = $httpClient->sendRequest($request);
Entities
ArchiveMessage
The main entity for storing archived messages:
use WechatWorkMsgAuditBundle\Entity\ArchiveMessage; // Query messages $messages = $archiveMessageRepository->findBy([ 'corp' => $corp, 'fromUserId' => 'user123', ]); // Access message data $message = $messages[0]; $msgId = $message->getMsgId(); $action = $message->getAction(); // send, recall, or switch $msgType = $message->getMsgType(); // text, image, voice, video, etc. $content = $message->getContent(); // Message content array $msgTime = $message->getMsgTime(); // Message timestamp
Message Actions
The bundle supports three types of message actions:
send- Regular message sendingrecall- Message recallswitch- Enterprise switching log
Advanced Usage
Custom Message Processing
You can extend the message processing functionality by implementing custom handlers:
use WechatWorkMsgAuditBundle\Entity\ArchiveMessage; // Custom message processor class CustomMessageProcessor { public function processMessage(ArchiveMessage $message): void { // Your custom processing logic $content = $message->getContent(); $msgType = $message->getMsgType(); // Handle different message types switch ($msgType) { case 'text': $this->processTextMessage($content); break; case 'image': $this->processImageMessage($content); break; // ... other types } } }
Message Filtering
Filter messages based on specific criteria:
// Filter by date range $messages = $archiveMessageRepository->createQueryBuilder('m') ->where('m.msgTime >= :startDate') ->andWhere('m.msgTime <= :endDate') ->setParameter('startDate', $startDate) ->setParameter('endDate', $endDate) ->getQuery() ->getResult(); // Filter by message type $textMessages = $archiveMessageRepository->findBy([ 'msgType' => 'text', 'corp' => $corp ]);
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine ORM 3.0 or higher
- WeChat Work Finance SDK
Contributing
Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see License File for more information.