PHPackages                             tourze/alipay-mini-program-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. [Payment Processing](/categories/payments)
4. /
5. tourze/alipay-mini-program-bundle

ActiveSymfony-bundle[Payment Processing](/categories/payments)

tourze/alipay-mini-program-bundle
=================================

支付宝小程序集成模块，提供用户认证、模板消息等功能

0.1.0(4mo ago)00MITPHPCI failing

Since Jun 1Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/alipay-mini-program-bundle)[ Packagist](https://packagist.org/packages/tourze/alipay-mini-program-bundle)[ RSS](/packages/tourze-alipay-mini-program-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (51)Versions (4)Used By (0)

AlipayMiniProgramBundle
=======================

[](#alipayminiprogrambundle)

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

[![Latest Version](https://camo.githubusercontent.com/f91142a3a200e3fb3d1c825abddcae1d4e778bc2b9f76fe8b77e9759a0379ba4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f616c697061792d6d696e692d70726f6772616d2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/alipay-mini-program-bundle)[![Total Downloads](https://camo.githubusercontent.com/28edb2069da1e1562914a8ea1af31079f6742be1046f95c4e748135849c7b22a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f616c697061792d6d696e692d70726f6772616d2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/alipay-mini-program-bundle)[![PHP Version](https://camo.githubusercontent.com/028f3f40a2a72259271b49bd783e8b2e3978e188ed7dd670615ca6181cfd36f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f616c697061792d6d696e692d70726f6772616d2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/alipay-mini-program-bundle)[![License](https://camo.githubusercontent.com/0593f9ed7309c0cfa479ce27316628979e61c714dac56c088e70cd4fb09a2f1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f616c697061792d6d696e692d70726f6772616d2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/alipay-mini-program-bundle)[![Code Coverage](https://camo.githubusercontent.com/0bee79379687762e1b713a606281f09928a2eabfb4c33d8265e8c9a5d609134b/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f2f6d61737465723f666c61673d616c697061792d6d696e692d70726f6772616d2d62756e646c65267374796c653d666c61742d737175617265)](https://codecov.io/gh/tourze/php-monorepo)

A comprehensive Symfony bundle for integrating Alipay Mini Program functionality, providing user authentication, form ID management, template message sending, and more.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Configuration](#configuration)
    - [Database Setup](#database-setup)
    - [Mini Program Configuration](#mini-program-configuration)
- [Quick Start](#quick-start)
    - [Basic Configuration](#basic-configuration)
    - [User Service Usage](#user-service-usage)
    - [Form ID Management](#form-id-management)
    - [Template Message Service](#template-message-service)
- [Console Commands](#console-commands)
    - [Clean Expired Form IDs](#clean-expired-form-ids)
    - [Send Pending Template Messages](#send-pending-template-messages)
- [JSON-RPC Procedures](#json-rpc-procedures)
- [Entities](#entities)
- [Admin Interface](#admin-interface)
- [Advanced Usage](#advanced-usage)
    - [Custom Event Listeners](#custom-event-listeners)
    - [Background Processing](#background-processing)
    - [Extending Services](#extending-services)
- [Events](#events)
- [Security](#security)
    - [Key Management](#key-management)
    - [Data Protection](#data-protection)
    - [Security Best Practices](#security-best-practices)
    - [Vulnerability Reporting](#vulnerability-reporting)
- [Requirements](#requirements)
- [Testing](#testing)
- [Contributing](#contributing)
- [Changelog](#changelog)
- [License](#license)

Features
--------

[](#features)

- **User Management**: Handle Alipay user authentication and information management
- **Form ID Collection**: Collect and manage form IDs for template message sending
- **Template Messages**: Send template messages with automatic queue processing
- **Phone Number Management**: Decrypt and manage user phone numbers
- **Multi-App Support**: Manage multiple Alipay mini programs in one application
- **Admin Interface**: EasyAdmin integration for managing users, messages, and configurations
- **Background Processing**: Symfony Messenger integration for asynchronous operations
- **Automatic Cleanup**: Commands for cleaning expired form IDs and sending pending messages

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

[](#installation)

```
composer require tourze/alipay-mini-program-bundle
```

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

[](#configuration)

### Database Setup

[](#database-setup)

Run the database migrations to create the necessary tables:

```
php bin/console doctrine:migrations:migrate
```

### Mini Program Configuration

[](#mini-program-configuration)

Configure your Alipay Mini Program settings in the admin interface or programmatically:

```
use AlipayMiniProgramBundle\Entity\MiniProgram;

$miniProgram = new MiniProgram();
$miniProgram->setAppId('your_app_id');
$miniProgram->setPrivateKey('your_private_key');
$miniProgram->setAlipayPublicKey('alipay_public_key');
$miniProgram->setEncryptKey('your_encrypt_key'); // Optional
```

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

[](#quick-start)

### Basic Configuration

[](#basic-configuration)

Register the bundle in your `config/bundles.php`:

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

### User Service Usage

[](#user-service-usage)

```
use AlipayMiniProgramBundle\Service\UserService;

// Update user information
$userService->updateUserInfo($user, [
    'nick_name' => 'John Doe',
    'avatar' => 'https://example.com/avatar.jpg',
    'province' => 'Guangdong',
    'city' => 'Shenzhen',
    'gender' => 'male'
]);

// Bind phone to user
$userService->bindPhone($user, '13800138000');
```

### Form ID Management

[](#form-id-management)

```
use AlipayMiniProgramBundle\Service\FormIdService;

// Save a form ID
$formId = $formIdService->saveFormId($miniProgram, $user, $formIdString);

// Get an available form ID
$availableFormId = $formIdService->getAvailableFormId($miniProgram, $user);

// Clean expired form IDs
$deletedCount = $formIdService->cleanExpiredFormIds();
```

### Template Message Service

[](#template-message-service)

```
use AlipayMiniProgramBundle\Service\TemplateMessageService;

// Send a template message
$success = $templateMessageService->send($templateMessage);

// Send pending messages (batch processing)
$templateMessageService->sendPendingMessages($limit = 10);
```

Console Commands
----------------

[](#console-commands)

### Clean Expired Form IDs

[](#clean-expired-form-ids)

Command: `alipay:mini-program:clean-expired-form-ids`

Remove expired form IDs from the database:

```
php bin/console alipay:mini-program:clean-expired-form-ids
```

### Send Pending Template Messages

[](#send-pending-template-messages)

Command: `alipay:template-message:send-pending`

Process and send queued template messages:

```
php bin/console alipay:template-message:send-pending [--limit=10]
```

Options:

- `--limit`, `-l`: Number of messages to process per run (default: 10)

JSON-RPC Procedures
-------------------

[](#json-rpc-procedures)

The bundle provides the following JSON-RPC procedures:

- `SaveAlipayMiniProgramFormId`: Save form IDs from mini program
- `UploadAlipayMiniProgramAuthCode`: Upload authorization codes
- `UploadAlipayMiniProgramPhoneNumber`: Upload encrypted phone numbers

Entities
--------

[](#entities)

- **User**: Alipay user information including nickname, avatar, location
- **MiniProgram**: Mini program configuration with app ID and keys
- **FormId**: Form IDs for template message sending
- **TemplateMessage**: Template messages with status tracking
- **Phone**: Decrypted phone numbers
- **AuthCode**: Authorization codes from mini program
- **AlipayUserPhone**: User-phone relationships

Admin Interface
---------------

[](#admin-interface)

The bundle integrates with EasyAdmin and provides the following admin controllers:

- `UserCrudController`: Manage Alipay users
- `MiniProgramCrudController`: Configure mini programs
- `TemplateMessageCrudController`: View and manage template messages
- `FormIdCrudController`: Monitor form ID collection
- `PhoneCrudController`: Manage phone numbers
- `AuthCodeCrudController`: View authorization codes
- `AlipayUserPhoneCrudController`: Manage user-phone relationships

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

[](#advanced-usage)

### Custom Event Listeners

[](#custom-event-listeners)

Create custom event listeners to handle template message processing:

```
use AlipayMiniProgramBundle\Entity\TemplateMessage;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;
use Doctrine\ORM\Event\PostPersistEventArgs;
use Doctrine\ORM\Events;

#[AsEntityListener(event: Events::postPersist, method: 'postPersist', entity: TemplateMessage::class)]
class CustomTemplateMessageListener
{
    public function postPersist(TemplateMessage $message, PostPersistEventArgs $args): void
    {
        // Custom processing logic
    }
}
```

### Background Processing

[](#background-processing)

Configure Symfony Messenger for asynchronous processing:

```
# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            alipay_messages: '%env(MESSENGER_TRANSPORT_DSN)%'
        routing:
            'AlipayMiniProgramBundle\Message\UpdateUserInfoMessage': alipay_messages
```

### Extending Services

[](#extending-services)

Extend the bundle services for custom functionality:

```
use AlipayMiniProgramBundle\Service\UserService;

class CustomUserService extends UserService
{
    public function updateUserInfo(User $user, array $userInfo): void
    {
        // Custom validation
        parent::updateUserInfo($user, $userInfo);
        // Additional processing
    }
}
```

Events
------

[](#events)

The bundle dispatches events during template message processing:

- Before sending: Allows modification of message data
- After sending: For logging and post-processing

Security
--------

[](#security)

### Key Management

[](#key-management)

- **Private Keys**: Store your private keys securely using environment variables or secure key management systems
- **Public Keys**: Ensure Alipay public keys are properly configured for signature verification
- **Encryption**: Use the encrypt key for sensitive data decryption when provided by Alipay

### Data Protection

[](#data-protection)

- **User Data**: User information is encrypted and stored securely
- **Form IDs**: Form IDs are automatically cleaned up after expiration to prevent accumulation
- **Logging**: All external API calls are logged for audit purposes

### Security Best Practices

[](#security-best-practices)

```
// Use environment variables for sensitive configuration
$miniProgram->setPrivateKey($_ENV['ALIPAY_PRIVATE_KEY']);
$miniProgram->setAlipayPublicKey($_ENV['ALIPAY_PUBLIC_KEY']);
$miniProgram->setEncryptKey($_ENV['ALIPAY_ENCRYPT_KEY']);
```

### Vulnerability Reporting

[](#vulnerability-reporting)

If you discover a security vulnerability, please send an email to . All security vulnerabilities will be promptly addressed.

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

[](#requirements)

- PHP 8.1 or higher
- Symfony 7.3 or higher
- Doctrine ORM 3.0 or higher
- OpenSSL extension
- EasyAdmin Bundle 4.0 or higher

Testing
-------

[](#testing)

Run the test suite:

```
vendor/bin/phpunit
```

Run static analysis:

```
vendor/bin/phpstan analyse
```

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

[](#contributing)

Contributions are welcome! Please follow these guidelines:

1. Fork the repository
2. Create a feature branch: `git checkout -b feature/new-feature`
3. Make your changes and add tests
4. Run tests: `vendor/bin/phpunit`
5. Run static analysis: `vendor/bin/phpstan analyse`
6. Commit your changes: `git commit -am 'Add new feature'`
7. Push to the branch: `git push origin feature/new-feature`
8. Submit a pull request

Changelog
---------

[](#changelog)

Please see [CHANGELOG.md](CHANGELOG.md) for details on version history.

License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance74

Regular maintenance activity

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity29

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 ~101 days

Total

3

Last Release

140d 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 (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-alipay-mini-program-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-alipay-mini-program-bundle/health.svg)](https://phpackages.com/packages/tourze-alipay-mini-program-bundle)
```

###  Alternatives

[sylius/sylius

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

8.4k5.6M648](/packages/sylius-sylius)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[sulu/sulu

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

1.3k1.3M152](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[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)[open-dxp/opendxp

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

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

PHPackages © 2026

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