PHP code example of tourze / wechat-work-app-chat-bundle

1. Go to this page and download the library: Download tourze/wechat-work-app-chat-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-app-chat-bundle example snippets


// config/bundles.php
return [
    // ...
    WechatWorkAppChatBundle\WechatWorkAppChatBundle::class => ['all' => true],
];

use WechatWorkAppChatBundle\Service\AppChatService;

// Create a new group chat
$appChatService->createAppChat($chatId, $name, $owner, $userList);

// Update group chat information
$appChatService->updateAppChat($appChat);

// Sync group chat information from WeChat Work API
$appChatService->syncAppChat($appChat);

// Sync all unsynced group chats
$appChatService->syncUnsynced();

use WechatWorkAppChatBundle\Service\MessageService;

// Send text message
$messageService->sendText($chatId, $content, $mentionedList = [], $mentionedMobileList = []);

// Send markdown message
$messageService->sendMarkdown($chatId, $content);

// Send image message
$messageService->sendImage($chatId, $mediaId);

// Send file message
$messageService->sendFile($chatId, $mediaId);

// Send all unsent messages
$messageService->sendUnsent();

// Create a text message
$textMessage = new TextMessage();
$textMessage->setChatId('your-chat-id');
$textMessage->setContent('Hello, World!');
$textMessage->setMentionedList(['@all']); // Mention everyone

// Save to database (automatically triggers sending)
$entityManager->persist($textMessage);
$entityManager->flush();

// Send markdown message directly
$messageService->sendMarkdown('your-chat-id', '# Important Notice\n\nPlease check the latest updates.');

// Create a new group chat
$appChat = new AppChat();
$appChat->setChatId('tech-team-001');
$appChat->setName('Tech Team Discussion');
$appChat->setOwner('john.doe');
$appChat->setUserList(['john.doe', 'jane.smith', 'bob.wilson']);

$entityManager->persist($appChat);
$entityManager->flush();

// Sync with WeChat Work API
$appChatService->syncAppChat($appChat);