PHP code example of tourze / wechat-work-msg-audit-bundle

1. Go to this page and download the library: Download tourze/wechat-work-msg-audit-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tourze / wechat-work-msg-audit-bundle example snippets


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);

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

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
        }
    }
}

// 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
]);
bash
# Simple test command for integration testing
php bin/console test:simple