tourze/wechat-mini-program-share-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tourze/wechat-mini-program-share-bundle

Composer 安装命令:

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

包简介

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

README 文档

README

English | 中文

Build Status Code Coverage PHP Version Require
License Symfony

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

Table of Contents

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

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

Configuration

Add the bundle to your bundles.php:

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

Quick Start

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

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

The bundle automatically tracks user invitations through the InviteVisitSubscriber:

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

Entities

ShareCode

Represents a share code with validation and tracking information.

ShareVisitLog

Tracks visits through share codes.

InviteVisitLog

Records invitation relationships between users.

ShareTicketLog

Logs share ticket operations.

Events

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

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

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

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

  • 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

MIT

tourze/wechat-mini-program-share-bundle 适用场景与选型建议

tourze/wechat-mini-program-share-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 106 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 tourze/wechat-mini-program-share-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tourze/wechat-mini-program-share-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 tourze/wechat-mini-program-share-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 106
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 13
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-17