tourze/wechat-mini-program-security-bundle
Symfony bundle that wires WeChat Mini Program content security checks into your PHP app, wrapping the msgSecCheck and mediaCheckAsync APIs so you can screen user text and images for policy violations with configurable credentials and service definitions.
Scope of this release: 0.2.1 is a patch bump from 0.2.0 with no published changelog entries — only a compare link. There are no documented features, breaking changes, or deprecations to react to. Treat this as a maintenance release and validate by diffing 0.2.0...0.2.1 in the repository rather than relying on release notes.
Minimal steps
composer require tourze/wechat-mini-program-security-bundle:0.2.1
src/DependencyInjection/Configuration.php — the actual config tree (this is where undocumented options live)src/DependencyInjection/*Extension.php — which services get registered and under what IDssrc/Resources/config/*.yaml — service definitions and constructor argumentstourze/*-bundle family is Symfony-first (bundles, Extension classes, service YAML). There is no Laravel service provider or extra.laravel auto-discovery in the typical layout. In Laravel you will not get zero-config registration — plan to wrap it manually.First use case
Server-side verification of a WeChat Mini Program request (signature check and/or encrypted-payload decryption) before your controller logic runs. That is the smallest slice of value and the easiest to test in isolation — get that working end-to-end before touching anything that calls the WeChat API.
Bridge it into the Laravel container. Register the bundle's services yourself in a dedicated provider and resolve them through the container rather than instantiating directly:
// app/Providers/WechatSecurityServiceProvider.php
public function register(): void
{
$this->app->singleton(SignatureVerifier::class, function ($app) {
return new SignatureVerifier(
token: config('wechat-security.token'),
// ...map constructor args explicitly
);
});
}
Do this deliberately: explicit constructor mapping is your guard against constructor signature changes that patch releases can slip in without a changelog.
Mirror config into config/wechat-security.php. The bundle's Symfony config tree won't be read by Laravel. Translate it once, keep 1:1 key names, and read it only inside the provider — never config() from inside domain code, or you lose the ability to swap the implementation in tests.
Wrap behind your own interface. Expose the bundle behind a narrow contract (RequestVerifier, ContentSecurityChecker) so the third-party classes stay at the edge. Given the project's low documentation surface, this is what makes the dependency replaceable.
Centralize access_token handling. Any class that calls the WeChat API needs a shared token, and WeChat enforces a global token validity window — fetching per-request will invalidate tokens for other processes. Wrap acquisition in a cached provider (Cache::remember with a TTL slightly under the expiry, plus a lock to prevent concurrent refresh storms), refresh on 40001/42001, and retry once.
Use it in middleware for request verification. Verification is cross-cutting; a wechat.verify middleware keeps controllers clean and makes the check trivially testable and skippable per-route.
Testing pattern. Because these services are HTTP clients under the hood, fake at the transport boundary (Http::fake() in Laravel, MockHttpClient in Symfony) rather than mocking the bundle's classes. For crypto/signature paths, use known-good fixtures with fixed timestamps and nonces — deterministic inputs are the only way to make signature assertions stable.
composer update --dry-run and review the actual diff for constructor and service-ID changes before promoting. A patch bump is not evidence of a non-breaking change in a pre-1.0 package.0.x, minor bumps may break. Pin to exact versions in composer.json and upgrade intentionally rather than floating ^0.2.401s will look like library bugs.vendor/. Implement your own verifier against the same contract and keep the package only for the pieces you actually use — the surface area is small enough to reimplement if you hit a wall.How can I help you explore Laravel packages today?