PHPackages                             tourze/wechat-official-account-material-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. [File &amp; Storage](/categories/file-storage)
4. /
5. tourze/wechat-official-account-material-bundle

ActiveSymfony-bundle[File &amp; Storage](/categories/file-storage)

tourze/wechat-official-account-material-bundle
==============================================

微信公众号永久素材管理组件，支持图片、音频、视频等多媒体文件的上传和管理

0.1.0(6mo ago)00MITPHPCI failing

Since Jun 14Pushed 4mo ago1 watchersCompare

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

READMEChangelog (2)Dependencies (37)Versions (3)Used By (0)

WeChat Official Account Material Bundle
=======================================

[](#wechat-official-account-material-bundle)

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

[![Latest Version](https://camo.githubusercontent.com/132ec3aae606e7c9957420fa5bc0b8ffd83372e385a9bb6638e23c167c695c7d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f7765636861742d6f6666696369616c2d6163636f756e742d6d6174657269616c2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/wechat-official-account-material-bundle)[![Total Downloads](https://camo.githubusercontent.com/8ca1c58842439634e561070e89903cd6ec7fcac3f04f95e0a75850e617c49f44/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f7765636861742d6f6666696369616c2d6163636f756e742d6d6174657269616c2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/wechat-official-account-material-bundle)[![PHP Version](https://camo.githubusercontent.com/6abfc0800f237050f4238a79777193191db463f4c30b63ef62d9faffdf456131/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f7765636861742d6f6666696369616c2d6163636f756e742d6d6174657269616c2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/wechat-official-account-material-bundle)[![License](https://camo.githubusercontent.com/5c6cdf96bc05d0ddaf6e7d541d11f9859ee1a0b90c0e60a970bd8f430d8dbeeb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f7765636861742d6f6666696369616c2d6163636f756e742d6d6174657269616c2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/wechat-official-account-material-bundle)[![Build Status](https://camo.githubusercontent.com/408315339a0e42ad0e9adad1f61a7f8edf904fde7a6e6e38555e9cd93a98a90e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7068702d6d6f6e6f7265706f2f7068702d6d6f6e6f7265706f2f63692e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/php-monorepo/php-monorepo/actions)[![Code Coverage](https://camo.githubusercontent.com/a9ba522fc2f4802e4dcacbbc2cf426e70365ef6c0d9b92c523989057fb8a998d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f7068702d6d6f6e6f7265706f2f7068702d6d6f6e6f7265706f3f7374796c653d666c61742d737175617265)](https://codecov.io/gh/php-monorepo/php-monorepo)

Manage WeChat Official Account permanent materials, including sync, upload, delete and statistics.

Features
--------

[](#features)

- Sync permanent materials from WeChat to local database
- Upload local files to WeChat as permanent materials
- Automatically delete remote materials when deleting local records
- Track material count statistics
- Support multiple material types: image, voice, video, thumbnail
- Scheduled task for automatic material count synchronization

Requirements
------------

[](#requirements)

- PHP 8.1+
- Symfony 6.4+
- Doctrine ORM
- tourze/wechat-official-account-bundle

Installation
------------

[](#installation)

```
composer require tourze/wechat-official-account-material-bundle
```

Quick Start
-----------

[](#quick-start)

### 1. Register the Bundle

[](#1-register-the-bundle)

The bundle should be automatically registered if you're using Symfony Flex. Otherwise, add it to `config/bundles.php`:

```
return [
    // ...
    WechatOfficialAccountMaterialBundle\WechatOfficialAccountMaterialBundle::class => ['all' => true],
];
```

### 2. Update Database Schema

[](#2-update-database-schema)

```
php bin/console doctrine:schema:update --force
```

### 3. Sync Materials

[](#3-sync-materials)

Sync all materials from all accounts:

```
php bin/console wechat-official-account:material:sync
```

Sync materials from a specific account:

```
php bin/console wechat-official-account:material:sync --account-id=123
```

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

[](#configuration)

The bundle uses default configurations and doesn't require additional setup. However, you can customize the following aspects:

### Database Configuration

[](#database-configuration)

The bundle creates two main tables:

- `wechat_official_account_material` - Stores material records
- `wechat_official_account_material_count` - Stores daily statistics

### Material Type Settings

[](#material-type-settings)

Each material type has specific constraints:

- **IMAGE**: Supports bmp, png, jpeg, jpg, gif with max 10MB
- **VOICE**: Supports mp3, wma, wav, amr with max 2MB
- **VIDEO**: Supports mp4 with max 10MB
- **THUMB**: Supports jpg with max 64KB

### Cron Job Configuration

[](#cron-job-configuration)

The material count sync command runs automatically every 2 hours via cron job. The cron expression is `0 */2 * * *` and is configured in the bundle's service definition.

Available Commands
------------------

[](#available-commands)

### wechat-official-account:material:sync

[](#wechat-official-accountmaterialsync)

Synchronize permanent materials from WeChat Official Account to local database.

**Usage:**

```
php bin/console wechat-official-account:material:sync [options]
```

**Options:**

- `--account-id=ACCOUNT-ID`: Sync materials for a specific account only

**Description:**This command fetches all permanent materials from WeChat Official Account(s) and stores them in the local database. It iterates through all material types (image, voice, video, thumb) and syncs them in batches.

### wechat:official-account:sync-material-count

[](#wechatofficial-accountsync-material-count)

Get and save material count statistics for all active accounts.

**Usage:**

```
php bin/console wechat:official-account:sync-material-count
```

**Description:**This command retrieves the total count of each material type from WeChat and stores the statistics in the database. It runs automatically every 2 hours via cron job (`0 */2 * * *`).

Material Types
--------------

[](#material-types)

The bundle supports the following material types:

- **IMAGE**: bmp, png, jpeg, jpg, gif (max 10MB)
- **VOICE**: mp3, wma, wav, amr (max 2MB)
- **VIDEO**: mp4 (max 10MB)
- **THUMB**: jpg (max 64KB)

Entity Classes
--------------

[](#entity-classes)

### Material

[](#material)

Represents a permanent material with the following properties:

- Account association
- Material type (MaterialType enum)
- Media ID from WeChat
- Name and URL
- Optional content and local file reference
- Timestamps and IP tracking

### MaterialCount

[](#materialcount)

Tracks daily material count statistics:

- Account association
- Date
- Count for each material type (voice, video, image, news)
- Timestamps

Event Listeners
---------------

[](#event-listeners)

The bundle includes a `MaterialListener` that:

- Automatically uploads materials to WeChat when saved locally (postPersist)
- Automatically deletes remote materials when deleted locally (preRemove)

API Integration
---------------

[](#api-integration)

The bundle provides request classes for WeChat API integration:

- `AddMaterialRequest` - Add new permanent material
- `BatchGetMaterialRequest` - Get material list
- `DeleteMaterialRequest` - Delete permanent material
- `GetMaterialCountRequest` - Get material count statistics
- `UploadImageRequest` - Upload image

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

[](#advanced-usage)

### Custom Material Processing

[](#custom-material-processing)

You can extend the material processing by listening to Doctrine events:

```
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Event\PostPersistEventArgs;
use Doctrine\ORM\Events;
use WechatOfficialAccountMaterialBundle\Entity\Material;

#[AsDoctrineListener(event: Events::postPersist)]
class CustomMaterialListener
{
    public function postPersist(PostPersistEventArgs $args): void
    {
        $entity = $args->getObject();
        if ($entity instanceof Material) {
            // Custom processing after material is saved
        }
    }
}
```

### Programmatic Material Management

[](#programmatic-material-management)

```
use WechatOfficialAccountMaterialBundle\Entity\Material;
use WechatOfficialAccountMaterialBundle\Enum\MaterialType;

// Create a new material record
$material = new Material();
$material->setAccount($account);
$material->setType(MaterialType::IMAGE);
$material->setName('My Image');
$material->setLocalFile('/path/to/image.jpg');

$entityManager->persist($material);
$entityManager->flush(); // This triggers automatic upload to WeChat
```

### Batch Operations

[](#batch-operations)

For bulk operations, you can disable automatic listeners temporarily:

```
// Disable listeners
$entityManager->getEventManager()->removeEventListener(
    [Events::postPersist, Events::preRemove],
    $materialListener
);

// Perform batch operations
foreach ($materials as $material) {
    $entityManager->persist($material);
}
$entityManager->flush();

// Re-enable listeners
$entityManager->getEventManager()->addEventListener(
    [Events::postPersist, Events::preRemove],
    $materialListener
);
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance72

Regular maintenance activity

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~149 days

Total

2

Last Release

182d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (1 commits)")

---

Tags

wechat

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-wechat-official-account-material-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-wechat-official-account-material-bundle/health.svg)](https://phpackages.com/packages/tourze-wechat-official-account-material-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
