tourze/wechat-official-account-draft-bundle

微信公众号草稿管理包,提供草稿创建、存储和管理功能

Installs: 75

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/tourze/wechat-official-account-draft-bundle

0.0.1 2025-05-08 14:18 UTC

This package is auto-updated.

Last update: 2025-11-03 06:27:21 UTC


README

PHP Version License Build Status Code Coverage

English | 中文

A Symfony bundle for managing WeChat Official Account draft articles.

Table of Contents

Features

  • Draft entity management with Doctrine ORM
  • Draft deletion functionality
  • Support for WeChat Official Account API integration
  • Built-in repository for draft operations
  • Event-driven architecture with listeners

Dependencies

This bundle requires the following packages:

  • PHP 8.1 or higher
  • Symfony 6.4 or higher
  • Doctrine ORM 3.0 or higher
  • tourze/wechat-official-account-bundle

Installation

composer require tourze/wechat-official-account-draft-bundle

Configuration

The bundle integrates with the WeChat Official Account Bundle and requires proper configuration of the WeChat API credentials. Ensure you have configured the main WeChat bundle before using this draft extension.

Quick Start

1. Configure the bundle

Add the bundle to your config/bundles.php:

return [
    // ... other bundles
    WechatOfficialAccountDraftBundle\WechatOfficialAccountDraftBundle::class => ['all' => true],
];

2. Create database tables

Run the Doctrine migrations to create the necessary tables:

php bin/console doctrine:migrations:migrate

3. Basic Usage

use WechatOfficialAccountDraftBundle\Entity\Draft;
use WechatOfficialAccountDraftBundle\Request\DeleteDraftRequest;

// Create a draft
$draft = new Draft();
$draft->setAccount($account);
$draft->setMediaId('media_id_from_wechat');

// Delete a draft
$deleteRequest = new DeleteDraftRequest();
$deleteRequest->setAccount($account);
$deleteRequest->setMediaId('media_id_to_delete');

Advanced Usage

Working with Draft Repository

use WechatOfficialAccountDraftBundle\Repository\DraftRepository;

// Inject the repository
public function __construct(private DraftRepository $draftRepository)
{
}

// Find drafts by account
$drafts = $this->draftRepository->findBy(['account' => $account]);

// Find draft by media ID
$draft = $this->draftRepository->findOneBy(['mediaId' => $mediaId]);

Event Handling

The bundle provides event-driven architecture for handling draft operations. You can listen to draft-related events to implement custom business logic.

API Reference

Entities

  • Draft: Main entity for managing draft articles
    • account: Associated WeChat account
    • mediaId: WeChat media ID for the draft

Requests

  • DeleteDraftRequest: Request handler for deleting drafts via WeChat API

Repository

  • DraftRepository: Repository for draft database operations

Security

This bundle follows security best practices:

  • All input validation is handled through Symfony constraints
  • Media ID length is limited to prevent database overflow
  • Account associations use foreign key constraints with cascade deletion

If you discover any security vulnerabilities, please report them responsibly.

License

This bundle is released under the MIT License. See the LICENSE file for details.