Download the PHP package tourze/wechat-official-account-mass-bundle without Composer
On this page you can find all versions of the php package tourze/wechat-official-account-mass-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tourze/wechat-official-account-mass-bundle
More information about tourze/wechat-official-account-mass-bundle
Files in tourze/wechat-official-account-mass-bundle
Package wechat-official-account-mass-bundle
Short Description 微信公众号群发消息功能包,提供文本、语音等消息类型的群发能力
License MIT
Informations about the package wechat-official-account-mass-bundle
WeChat Official Account Mass Bundle
中文
A Symfony bundle for WeChat Official Account mass messaging functionality, supporting scheduled broadcasts to all users, specific user groups by tag, or individual users by OpenID.
Table of Contents
- Features
- Requirements
- Installation
- Quick Start
- Configuration
- API Reference
- Advanced Usage
- Security
- Troubleshooting
- Contributing
- License
- References
Features
- Flexible Targeting: Send messages to all users, specific user groups by tag, or individual users by OpenID
- Multiple Message Types: Support for text and voice messages
- Scheduled Broadcasting: Schedule messages to be sent at specific times
- Automatic Sending: Built-in cron task for automatic message dispatch
- Database-backed Task Management: Persistent storage of tasks with status tracking
- WeChat API Integration: Full integration with WeChat Official Account API
- Response Tracking: Stores WeChat API response data (msg_id, msg_data_id)
- Multi-account Support: Handle multiple WeChat Official Accounts
Installation
Quick Start
1. Enable the Bundle
Register the bundle in your config/bundles.php:
2. Configure Database
Update your database schema to create the required tables:
3. Create a Mass Task
2. Send Messages via Command
The bundle provides a console command for sending mass messages:
This command will:
- Find all valid, unsent tasks where send time has passed
- Send messages via WeChat API
- Update task status and store response data
3. Automatic Sending with Cron
The SendMassCommand is configured to run automatically every minute using the cron job attribute:
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine ORM 3.0 or higher
- WeChat Official Account with API credentials
Configuration
This bundle requires the tourze/wechat-official-account-bundle to be properly configured with your WeChat Official Account credentials.
Required Environment Variables
Configure your WeChat credentials in .env:
API Reference
Entities
MassTask
Main entity for managing mass messaging tasks.
Properties:
title(string): Task name for identificationtype(MassType): Message type (TEXT, VOICE)content(string): Message content for text messagessendTime(DateTimeImmutable): Scheduled send timetagId(string|null): Target tag ID for group messagingopenIds(array): Target user OpenIDs for individual messagingmediaId(string|null): Media ID for voice messagessent(bool): Send status indicatorvalid(bool): Task validity flagaccount(Account|null): Associated WeChat Official AccountmsgTaskId(string|null): WeChat API response task IDmsgDataId(string|null): WeChat API response data ID
Methods:
formatMessage(): Formats message data for WeChat API- Standard getters and setters for all properties
Enums
MassType
Supported message types:
TEXT= '1': Text messagesVOICE= '3': Voice messages
Repositories
MassTaskRepository
Extends Doctrine's ServiceEntityRepository for custom query methods.
Request Classes
SendToAllRequest: Send to all usersSendByTagRequest: Send to users with specific tagSendByOpenIdRequest: Send to specific users by OpenIDPreviewTaskRequest: Preview message before sendingDeleteTaskRequest: Delete scheduled task
Commands
wechat:send-mass
Sends scheduled mass messages. Configured to run automatically every minute via cron.
Usage:
Process:
- Queries all valid, unsent tasks where send time has passed
- Marks tasks as sent to prevent duplicate processing
- Determines target audience (all users, by tag, or by OpenID)
- Sends messages via WeChat API
- Stores API response data (msg_task_id, msg_data_id)
Advanced Usage
Voice Message Example
Multi-account Support
Task Status Monitoring
Security
Data Protection
- Sensitive Information: Never store WeChat API credentials in your source code. Always use environment variables or secure configuration management.
- Access Control: Implement proper authentication and authorization for mass messaging functionality to prevent unauthorized usage.
- Input Validation: All user inputs are validated using Symfony's validation constraints to prevent malicious data injection.
Best Practices
- Rate Limiting: Be aware of WeChat API rate limits to avoid account suspension.
- Audit Logging: Consider implementing audit logs for mass messaging activities.
- User Consent: Ensure you have proper consent from users before sending mass messages.
- Content Monitoring: Implement content review processes for mass messages to comply with platform policies.
Vulnerability Reporting
If you discover a security vulnerability, please report it to the project maintainers following responsible disclosure practices.
Troubleshooting
Common Issues
-
Messages not sending
- Ensure cron job is running: Check system cron configuration
- Verify task validity: Task must have
valid = true - Check send time: Must be in the past for immediate sending
-
API Errors
- Verify WeChat credentials in configuration
- Check account permissions for mass messaging
- Ensure media IDs are valid and not expired
- Database Issues
- Run
doctrine:schema:validateto check entity mappings - Ensure database user has proper permissions
- Run
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
Development Setup
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Running Tests
License
The MIT License (MIT). Please see License File for more information.
References
All versions of wechat-official-account-mass-bundle with dependencies
doctrine/doctrine-bundle Version ^2.13
doctrine/doctrine-fixtures-bundle Version ^4.0
doctrine/orm Version ^3.0
doctrine/persistence Version ^4.1
easycorp/easyadmin-bundle Version ^4
knplabs/knp-menu Version ^3.7
monolog/monolog Version ^3.1
nesbot/carbon Version ^2.72 || ^3
psr/log Version ^3|^2|^1
symfony/config Version ^7.3
symfony/console Version ^7.3
symfony/dependency-injection Version ^7.3
symfony/doctrine-bridge Version ^7.3
symfony/framework-bundle Version ^7.3
symfony/http-kernel Version ^7.3
symfony/property-access Version ^7.3
symfony/security-http Version ^7.3
symfony/yaml Version ^7.3
tourze/bundle-dependency Version 1.*
tourze/doctrine-indexed-bundle Version 1.0.*
tourze/doctrine-snowflake-bundle Version 1.1.*
tourze/doctrine-timestamp-bundle Version 1.1.*
tourze/doctrine-track-bundle Version 1.1.*
tourze/easy-admin-menu-bundle Version 1.0.*
tourze/enum-extra Version 1.0.*
tourze/symfony-cron-job-bundle Version 1.1.*
tourze/symfony-dependency-service-loader Version 1.0.*
tourze/wechat-official-account-bundle Version 0.1.*