tourze/wechat-mini-program-custom-service-bundle

微信小程序客服消息服务包,提供发送文本、图片、链接和小程序卡片消息的功能

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/tourze/wechat-mini-program-custom-service-bundle


README

English | 中文

Latest Version PHP Version Build Status Code Coverage License Total Downloads

A Symfony bundle for managing WeChat Mini Program custom service messages, providing comprehensive support for sending various message types including text, images, links, and mini program pages.

Features

  • 🎯 Multiple Message Types: Support for text, image, link, and mini program page messages
  • 📦 Doctrine Integration: Full ORM support with entity repositories
  • 🔄 Event System: Event subscribers for message handling
  • 🚀 Easy Configuration: Symfony bundle with auto-configuration
  • 📝 Type Safety: Comprehensive type annotations and PHPStan level 5 compliance
  • Fully Tested: 100% test coverage with PHPUnit

Dependencies

This bundle requires:

  • PHP 8.1 or higher
  • Symfony 6.4 or higher
  • Doctrine ORM 3.0 or higher
  • tourze/wechat-mini-program-bundle

Installation

composer require tourze/wechat-mini-program-custom-service-bundle

1. Register the Bundle

Add the bundle to your config/bundles.php:

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

2. Configure Database

Run database migrations to create the message tables:

php bin/console doctrine:migrations:migrate

Quick Start

use WechatMiniProgramCustomServiceBundle\Entity\TextMessage;
use WechatMiniProgramCustomServiceBundle\Request\SendMessageRequest;

// Create a text message
$textMessage = new TextMessage();
$textMessage->setTouser('user_openid');
$textMessage->setContent('Hello from WeChat Mini Program!');
$textMessage->setAccount($account);

// Send the message
$request = new SendMessageRequest();
$request->setMessage($textMessage);
$request->setAccount($account);

// Use your HTTP client to send the request

Advanced Usage

Message Types

Text Message

$textMessage = new TextMessage();
$textMessage->setTouser('user_openid')
           ->setContent('Your message content')
           ->setAccount($account);

Image Message

$imageMessage = new ImageMessage();
$imageMessage->setTouser('user_openid')
            ->setMediaId('media_id_from_wechat')
            ->setAccount($account);

Link Message

$linkMessage = new LinkMessage();
$linkMessage->setTouser('user_openid')
           ->setTitle('Link Title')
           ->setDescription('Link Description')
           ->setUrl('https://example.com')
           ->setThumbUrl('https://example.com/thumb.jpg')
           ->setAccount($account);

Mini Program Page Message

$mpPageMessage = new MpPageMessage();
$mpPageMessage->setTouser('user_openid')
             ->setTitle('Page Title')
             ->setPagePath('pages/index/index')
             ->setThumbMediaId('thumb_media_id')
             ->setAccount($account);

Configuration

The bundle provides auto-configuration for all services. Simply register the bundle and the services will be available for dependency injection.

# config/services.yaml
services:
    # Services are auto-configured
    _defaults:
        autowire: true
        autoconfigure: true

Event System

The bundle includes an event listener for message handling:

use WechatMiniProgramCustomServiceBundle\EventSubscriber\MessageListener;

// The MessageListener automatically handles message events
// when integrated with the WeChat Mini Program bundle

API Reference

For detailed API documentation, please refer to:

Contributing

Please see CONTRIBUTING.md for details.

License

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