定制 tourze/wechat-work-app-chat-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tourze/wechat-work-app-chat-bundle

最新稳定版本:0.0.1

Composer 安装命令:

composer require tourze/wechat-work-app-chat-bundle

包简介

企业微信群聊管理服务组件

README 文档

README

PHP Version License Build Status Code Coverage

English | 中文

Enterprise WeChat group chat management bundle for Symfony applications.

Features

  • Create and manage Enterprise WeChat group chats
  • Send text, markdown, image, and file messages to group chats
  • Automatic message queue with retry mechanism
  • Symfony command-line tools for batch operations
  • Event-driven message sending

Requirements

  • PHP 8.1+
  • Symfony 6.4+
  • Enterprise WeChat Work API credentials

Installation

composer require tourze/wechat-work-app-chat-bundle

Configuration

Register the bundle in your application:

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

Usage

Services

AppChatService

Manages Enterprise WeChat group chats:

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

MessageService

Handles message sending to group chats:

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

Entities

  • AppChat: Represents an Enterprise WeChat group chat
  • TextMessage: Plain text messages with @mention support
  • MarkdownMessage: Markdown formatted messages
  • ImageMessage: Image messages with media ID
  • FileMessage: File messages with media ID

Commands

Send Unsent Messages

Sends all queued messages that haven't been sent yet:

bin/console wechat-work:app-chat:send-unsent

This command:

  • Retrieves all unsent messages from the database
  • Attempts to send each message via WeChat Work API
  • Updates message status upon successful sending
  • Handles errors gracefully with detailed output

Sync Group Chats

Synchronizes group chat information with WeChat Work API:

bin/console wechat-work:app-chat:sync

This command:

  • Fetches all unsynced group chats
  • Retrieves latest information from WeChat Work API
  • Updates local database with current group chat details
  • Reports sync status and any errors

Event Subscribers

The bundle includes an automatic message sending subscriber that triggers when new messages are persisted to the database. This ensures messages are sent immediately when created.

Examples

Creating and Sending Messages

// 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.');

Managing Group Chats

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

Testing

Run the test suite:

./vendor/bin/phpunit packages/wechat-work-app-chat-bundle/tests

Contributing

Please read the main repository's contributing guidelines before submitting pull requests.

License

This bundle is licensed under the same license as the parent monorepo.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-03