tourze / wechat-mini-program-qrcode-link-bundle
小程序 Short Link
Installs: 10
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/wechat-mini-program-qrcode-link-bundle
Requires
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- intervention/image: ^3.11
- league/flysystem: ^3.10
- spatie/color: ^1.8
- symfony/config: ^7.3
- symfony/console: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/doctrine-bridge: ^7.3
- symfony/framework-bundle: ^7.3
- symfony/http-foundation: ^7.3
- symfony/http-kernel: ^7.3
- symfony/property-access: ^7.3
- symfony/security-bundle: ^7.3
- symfony/security-core: ^7.3
- symfony/security-http: ^7.3
- symfony/serializer: ^7.3
- symfony/yaml: ^7.3
- tourze/bundle-dependency: 1.*
- tourze/file-name-generator: 1.0.*
- tourze/json-rpc-core: 1.0.*
- tourze/json-rpc-endpoint-bundle: 1.0.*
- tourze/json-rpc-lock-bundle: 1.0.*
- tourze/symfony-dependency-service-loader: 1.0.*
- tourze/wechat-mini-program-bundle: 1.0.*
- tourze/wechat-mini-program-share-bundle: 1.0.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
- tourze/http-client-bundle: 1.1.*
- tourze/phpunit-base: 1.*
- tourze/phpunit-symfony-kernel-test: 1.0.*
- tourze/phpunit-symfony-unit-test: 1.*
This package is auto-updated.
Last update: 2025-11-12 04:56:25 UTC
README
A powerful Symfony bundle for generating WeChat Mini Program QR codes and share links with advanced features including custom logos, colors, transparent backgrounds, and comprehensive JSON-RPC API integration.
Table of Contents
- Features
- Installation
- Dependencies
- Security
- Quick Start
- Command Parameters
- Configuration
- Advanced Usage
- API Reference
- Contributing
- License
Features
- 🔗 Generate unlimited WeChat Mini Program QR codes
- 🎨 Custom colors and transparent backgrounds
- 🖼️ Logo overlay support (including user avatars)
- 🚀 JSON-RPC API integration
- 💾 Share code management with database persistence
- 🔒 User authentication and security
- 🛠️ Console command for batch generation
- 📊 Multiple environment support (release, trial, develop)
Installation
composer require tourze/wechat-mini-program-qrcode-link-bundle
Dependencies
This bundle requires:
- PHP 8.1 or higher
- Symfony 6.4 or higher
- WeChat Mini Program Bundle
- Doctrine ORM
- Flysystem
- Intervention Image v3
Security
This bundle implements several security measures:
- User authentication required for JSON-RPC procedures
- Input validation for all parameters
- Safe image processing with size limits
- URL validation for logo sources
Quick Start
Basic Usage
<?php use WechatMiniProgramQrcodeLinkBundle\Request\CodeUnLimitRequest; use WechatMiniProgramBundle\Service\Client; // Create unlimited QR code request $request = new CodeUnLimitRequest(); $request->setAccount($account); $request->setScene('user-123'); $request->setPage('pages/product/detail'); $request->setCheckPath(false); $request->setEnvVersion('release'); $request->setWidth(750); // Generate QR code $png = $client->request($request); file_put_contents('qrcode.png', $png);
JSON-RPC API
// Get user share code with custom logo { "method": "GetUserShareCode", "params": { "appId": "wx1234567890abcdef", "link": "pages/share/index", "size": 200, "envVersion": "release", "hyaline": true, "lineColor": {"r": 255, "g": 0, "b": 0}, "logoUrl": "https://example.com/logo.png" } }
Console Command
Generate QR codes via command line:
# Generate unlimited QR code php bin/console wechat-mini-program:generate-unlimited-code \ --account-id=1 \ --path="pages/product/detail" \ --scene="product-123" \ --env="release" \ --width=750 \ --output="qrcode.png"
Command Parameters
accountId(required): WeChat Mini Program account IDpath(required): Target page path (e.g., "pages/index/index")scene(required): Scene value (max 32 characters)env(optional): Environment version (release|trial|develop, default: release)width(optional): QR code width in pixels (default: 750)output(optional): Output file path
Configuration
Environment Variables
# Default index page WECHAT_MINI_PROGRAM_INDEX_PAGE=/pages/index/index # Share redirect path WECHAT_MINI_PROGRAM_SHARE_REDIRECT_PATH=pages/share/index
Services Configuration
Register in your services.yaml:
services: WechatMiniProgramQrcodeLinkBundle\Command\GenerateUnlimitedCodeCommand: arguments: $accountRepository: '@WechatMiniProgramBundle\Repository\AccountRepository' $client: '@WechatMiniProgramBundle\Service\Client' tags: - { name: console.command }
Advanced Usage
Custom Logo Overlay
// Using direct URL $procedure = new GetUserShareCode(); $procedure->logoUrl = 'https://example.com/logo.png'; // Using user avatar $procedure->logoUrl = 'user-avatar';
Avatar Download Domains (Mini Program)
⚠️ When you fetch a head image inside a Mini Program (for example to upload it to your backend before calling this bundle),
wx.downloadFileonly works for hosts that exist in your allowlist. Missing entries are the reason whyhttps://thirdwx.qlogo.cn/...often fails.
- Go to WeChat Mini Program Console → Development → Development management → Development settings → downloadFile legal domain and add every WeChat avatar CDN host you rely on (wildcards are not accepted).
- Normalize any
http://avatar URL tohttps://before using it:const safeAvatar = avatarUrl.replace(/^http:\/\//, 'https://');. - If you are out of allowlist slots, proxy avatars through one of your own domains and whitelist that proxy once.
Known WeChat avatar domains you should keep in sync with the allowlist:
| Domain | Typical usage | Reference |
|---|---|---|
https://thirdwx.qlogo.cn |
wx.getUserProfile / newer Mini Program avatars |
WeChat Dev QA |
https://wx.qlogo.cn |
Legacy headimgurl, group avatars, some cached profiles |
WeChat Dev QA |
https://mmbiz.qlogo.cn |
Official account & Mini Program profile images | WeChat Dev QA |
https://mmbiz.qpic.cn |
Square/cropped avatar assets distributed via the MP backend | WeChat Dev QA |
Keep this list updated whenever WeChat announces new CDN domains so that poster generation using logoUrl=user-avatar never breaks in production.
Color Customization
// RGB color array $request->setLineColor(['r' => 255, 'g' => 0, 'b' => 0]); // Color string $request->setLineColor('#FF0000');
Transparent Background
$request->setHyaline(true);
Batch Processing
// Process multiple QR codes $codes = []; foreach ($products as $product) { $request = new CodeUnLimitRequest(); $request->setScene("product-{$product->getId()}"); $codes[] = $client->request($request); }
API Reference
CodeUnLimitRequest
Main request class for generating unlimited QR codes.
Properties
scene: Scene value (max 32 characters)page: Target page pathcheckPath: Validate page existenceenvVersion: Environment (release|trial|develop)width: QR code width (280-1280px)autoColor: Auto color configurationhyaline: Transparent backgroundlineColor: Custom line color
GetUserShareCode
JSON-RPC procedure for generating user share codes with logo support.
Parameters
appId: WeChat Mini Program App IDlink: Target page linksize: QR code size (default: 200)envVersion: Environment versionhyaline: Transparent backgroundlineColor: Custom line colorlogoUrl: Logo overlay URL
Contributing
Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see License File for more information.