PHPackages                             tourze/wechat-mini-program-share-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/wechat-mini-program-share-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

tourze/wechat-mini-program-share-bundle
=======================================

微信小程序分享功能包，支持邀请码生成、分享统计和用户追踪

1.1.0(6mo ago)01061MITPHPCI passing

Since May 14Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/tourze/wechat-mini-program-share-bundle)[ Packagist](https://packagist.org/packages/tourze/wechat-mini-program-share-bundle)[ RSS](/packages/tourze-wechat-mini-program-share-bundle/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (50)Versions (7)Used By (1)

WeChat Mini Program Share Bundle
================================

[](#wechat-mini-program-share-bundle)

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

[![Build Status](https://github.com/tourze/php-monorepo/actions/workflows/ci.yml/badge.svg)](https://github.com/tourze/php-monorepo/actions)[![Code Coverage](https://camo.githubusercontent.com/f613e51be1087f0d304eb6b376019e4a48edc93dbc80ef2a900ca0e1538fee9c/68747470733a2f2f636f6465636f762e696f2f67682f746f75727a652f7068702d6d6f6e6f7265706f2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/tourze/php-monorepo)[![PHP Version Require](https://camo.githubusercontent.com/6518db1335bf20fdff07253dc6d6d0cec955b5fb6a8ef1382ac6d73687ecc07f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d626c7565)](https://packagist.org/packages/tourze/wechat-mini-program-share-bundle)
[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://github.com/tourze/wechat-mini-program-share-bundle/blob/master/LICENSE)[![Symfony](https://camo.githubusercontent.com/fb474138c0adf07f744db21840842fb1ab8f404c0ed3c989375b93045d903899/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73796d666f6e792d253345253344372e332d707572706c65)](https://symfony.com/)

A Symfony bundle for handling WeChat Mini Program sharing functionality, including share code generation, visit tracking, and invitation management.

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

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Configuration](#configuration)
- [Quick Start](#quick-start)
    - [1. Generate Share Configuration](#1-generate-share-configuration)
    - [2. Handle Share Code Information](#2-handle-share-code-information)
    - [3. Track Invitations](#3-track-invitations)
- [Entities](#entities)
- [Events](#events)
- [Advanced Usage](#advanced-usage)
    - [Custom Event Listeners](#custom-event-listeners)
    - [Custom Share Code Validation](#custom-share-code-validation)
    - [Extending Share Analytics](#extending-share-analytics)
- [Requirements](#requirements)
- [License](#license)

Features
--------

[](#features)

- **Share Code Management**: Generate and manage mini program share codes
- **Visit Tracking**: Track user visits through shared links
- **Invitation System**: Handle user invitations and track referral relationships
- **Analytics**: Comprehensive logging and analytics for sharing behavior
- **Event-Driven**: Symfony event system integration for extensibility

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

[](#installation)

```
composer require tourze/wechat-mini-program-share-bundle
```

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

[](#configuration)

Add the bundle to your `bundles.php`:

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

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

[](#quick-start)

### 1. Generate Share Configuration

[](#1-generate-share-configuration)

Use the `GetWechatMiniProgramPageShareConfig` procedure to generate share paths with tracking parameters:

```
use WechatMiniProgramShareBundle\Procedure\GetWechatMiniProgramPageShareConfig;

$procedure = new GetWechatMiniProgramPageShareConfig($hashids, $security);
$procedure->path = '/pages/product/detail';
$procedure->params = ['id' => 123];
$procedure->config = [
    'title' => 'Product Title',
    'path' => '/pages/product/detail?id=123'
];

$shareConfig = $procedure->execute();
```

### 2. Handle Share Code Information

[](#2-handle-share-code-information)

Use the `GetWechatMiniProgramShareCodeInfo` procedure to process share codes:

```
use WechatMiniProgramShareBundle\Procedure\GetWechatMiniProgramShareCodeInfo;

$procedure = new GetWechatMiniProgramShareCodeInfo(
    $codeRepository,
    $doctrineService,
    $security,
    $logger
);
$procedure->id = 'share-code-id';

$result = $procedure->execute();
// Returns redirect information for the mini program
```

### 3. Track Invitations

[](#3-track-invitations)

The bundle automatically tracks user invitations through the `InviteVisitSubscriber`:

```
// The subscriber listens to CodeToSessionResponseEvent
// and automatically creates InviteVisitLog entries
```

Entities
--------

[](#entities)

### ShareCode

[](#sharecode)

Represents a share code with validation and tracking information.

### ShareVisitLog

[](#sharevisitlog)

Tracks visits through share codes.

### InviteVisitLog

[](#invitevisitlog)

Records invitation relationships between users.

### ShareTicketLog

[](#shareticketlog)

Logs share ticket operations.

Events
------

[](#events)

### InviteUserEvent

[](#inviteuserevent)

Dispatched when a user is invited through sharing.

```
use WechatMiniProgramShareBundle\Event\InviteUserEvent;

// Listen to the event
public function onInviteUser(InviteUserEvent $event): void
{
    $log = $event->getInviteVisitLog();
    // Handle invitation logic
}
```

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

[](#advanced-usage)

### Custom Event Listeners

[](#custom-event-listeners)

You can create custom event listeners to extend the sharing functionality:

```
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use WechatMiniProgramShareBundle\Event\InviteUserEvent;

#[AsEventListener]
class CustomInviteListener
{
    public function onInviteUser(InviteUserEvent $event): void
    {
        $log = $event->getInviteVisitLog();

        // Custom logic for handling invitations
        if ($log->isNewUser()) {
            // Send welcome message
            $this->sendWelcomeMessage($log->getVisitUser());
        }

        // Award points to the inviter
        $this->awardInvitationPoints($log->getShareUser());
    }
}
```

Custom Share Code Validation
----------------------------

[](#custom-share-code-validation)

Implement custom validation logic for share codes:

```
use WechatMiniProgramShareBundle\Entity\ShareCode;
use Symfony\Component\Validator\Context\ExecutionContextInterface;

class CustomShareCodeValidator
{
    public function validate(ShareCode $shareCode, ExecutionContextInterface $context): void
    {
        if (!$this->isValidDomain($shareCode->getLinkUrl())) {
            $context->buildViolation('Invalid domain for share URL')
                ->atPath('linkUrl')
                ->addViolation();
        }
    }
}
```

### Extending Share Analytics

[](#extending-share-analytics)

Create custom analytics by listening to share events:

```
use WechatMiniProgramShareBundle\Entity\ShareVisitLog;
use Doctrine\ORM\Event\PostPersistEventArgs;

class ShareAnalyticsListener
{
    public function postPersist(PostPersistEventArgs $args): void
    {
        $entity = $args->getObject();

        if ($entity instanceof ShareVisitLog) {
            // Send analytics data to external service
            $this->analyticsService->track('share_visit', [
                'code_id' => $entity->getCode()->getId(),
                'user_id' => $entity->getUser()?->getId(),
                'timestamp' => $entity->getCreateTime(),
            ]);
        }
    }
}
```

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

[](#requirements)

- PHP 8.1+
- Symfony 7.3+
- Doctrine ORM 3.0+
- WeChat Mini Program Bundle (tourze/wechat-mini-program-bundle)
- WeChat Mini Program Auth Bundle (tourze/wechat-mini-program-auth-bundle)
- Hashids PHP 5.0+

License
-------

[](#license)

MIT

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance66

Regular maintenance activity

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

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

Recently: every ~52 days

Total

6

Last Release

197d ago

Major Versions

0.0.3 → 1.0.02025-11-07

### Community

Maintainers

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

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[oro/platform

Business Application Platform (BAP)

645143.5k115](/packages/oro-platform)[open-dxp/opendxp

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

9421.6k61](/packages/open-dxp-opendxp)[sylius/sylius

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

8.5k5.9M737](/packages/sylius-sylius)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[contao/core-bundle

Contao Open Source CMS

1231.6M2.8k](/packages/contao-core-bundle)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k14](/packages/2lenet-crudit-bundle)

PHPackages © 2026

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