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

This package is auto-updated.

Last update: 2025-11-01 19:33:45 UTC


README

English | 中文

Latest Version Total Downloads PHP Version License Build Status Code Coverage

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:

  1. WeChat Work Corp Configuration: Set up your corporation and agent with the message archive application (Special Agent ID: 1000022)
  2. Private Key: Configure the private key for message decryption in your agent settings
  3. 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 sending
  • recall - Message recall
  • switch - 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.

Reference