PHPackages                             tourze/wechat-work-msg-audit-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/wechat-work-msg-audit-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

tourze/wechat-work-msg-audit-bundle
===================================

企业微信会话内容存档管理 Symfony Bundle

0.0.1(11mo ago)00MITPHPPHP ^8.1CI failing

Since Jun 3Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/wechat-work-msg-audit-bundle)[ Packagist](https://packagist.org/packages/tourze/wechat-work-msg-audit-bundle)[ RSS](/packages/tourze-wechat-work-msg-audit-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (26)Versions (2)Used By (0)

WeChat Work Message Audit Bundle
================================

[](#wechat-work-message-audit-bundle)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/5432cc3e846663b70061e5202a5a00ebebb838eb6447361ef8ac5b1ca7e65abc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f7765636861742d776f726b2d6d73672d61756469742d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/wechat-work-msg-audit-bundle)[![Total Downloads](https://camo.githubusercontent.com/c4ea982b796108d17a1377639461d2ad76dc33f0776b06daae5548b7910ba514/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f7765636861742d776f726b2d6d73672d61756469742d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/wechat-work-msg-audit-bundle)[![PHP Version](https://camo.githubusercontent.com/ee0868400dff50390d9cbf28ba0bc9ea308eeda303ce6f2857ecb7f81fa5f892/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f7765636861742d776f726b2d6d73672d61756469742d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/wechat-work-msg-audit-bundle)[![License](https://camo.githubusercontent.com/194258502ed8de843715ca455822350e1f790edc563f70bb11010786b13ce8cc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f7765636861742d776f726b2d6d73672d61756469742d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/wechat-work-msg-audit-bundle)[![Build Status](https://camo.githubusercontent.com/3c75cbf80739d3f42836bab035102123295320544fd5b4157e0fec7fc34b2780/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f7068702d6d6f6e6f7265706f2f63692e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/tourze/php-monorepo/actions)[![Code Coverage](https://camo.githubusercontent.com/6ce0146325478eb7cebae4cc6139b2af2c161735dd0e3c6ff6802f2c5a708179/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f3f7374796c653d666c61742d737175617265)](https://codecov.io/gh/tourze/php-monorepo)

A Symfony bundle for WeChat Work (企业微信) conversation content archiving functionality.

Features
--------

[](#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
------------

[](#installation)

```
composer require tourze/wechat-work-msg-audit-bundle
```

Configuration
-------------

[](#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
-----

[](#usage)

### Console Commands

[](#console-commands)

#### Sync Archive Messages

[](#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

# Sync messages for a specific agent
php bin/console wechat-work:sync-archive-message
```

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

[](#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
------------

[](#api-requests)

### Get Permit User List

[](#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
--------

[](#entities)

### ArchiveMessage

[](#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
---------------

[](#message-actions)

The bundle supports three types of message actions:

- `send` - Regular message sending
- `recall` - Message recall
- `switch` - Enterprise switching log

Advanced Usage
--------------

[](#advanced-usage)

### Custom Message Processing

[](#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

[](#message-filtering)

Filter messages based on specific criteria:

```
// Filter by date range
$messages = $archiveMessageRepository->createQueryBuilder('m')
    ->where('m.msgTime >= :startDate')
    ->andWhere('m.msgTime
