tourze/wechat-mini-program-user-contracts
Composer 安装命令:
composer require tourze/wechat-mini-program-user-contracts
包简介
微信用户定义
README 文档
README
A PHP contract package for WeChat Mini Program user management.
Installation
composer require tourze/wechat-mini-program-user-contracts
Overview
This package provides essential interfaces for managing WeChat Mini Program users within the PHP ecosystem. It defines contracts for user entities and user loading operations, ensuring consistent implementation across different applications.
Features
- User Entity Contract: Defines the structure and behavior of WeChat Mini Program users
- User Loading Contract: Provides interfaces for loading and creating users
- Type Safety: Uses strict typing for better code reliability
- PSR-4 Autoloading: Follows PHP standards for easy integration
Interfaces
UserInterface
Defines the contract for a WeChat Mini Program user entity:
<?php use Tourze\WechatMiniProgramUserContracts\UserInterface; use Tourze\WechatMiniProgramAppIDContracts\MiniProgramInterface; interface UserInterface { /** * Get the associated mini program */ public function getMiniProgram(): MiniProgramInterface; /** * Get the user's Open ID */ public function getOpenId(): string; /** * Get the user's Union ID (optional) */ public function getUnionId(): ?string; /** * Get the user's avatar URL (optional) */ public function getAvatarUrl(): ?string; }
UserLoaderInterface
Defines the contract for loading and creating WeChat Mini Program users:
<?php use Tourze\WechatMiniProgramUserContracts\UserLoaderInterface; use Tourze\WechatMiniProgramAppIDContracts\MiniProgramInterface; interface UserLoaderInterface { /** * Load a user by their Open ID */ public function loadUserByOpenId(string $openId): ?UserInterface; /** * Load a user by their Union ID */ public function loadUserByUnionId(string $unionId): ?UserInterface; /** * Create a new user */ public function createUser(MiniProgramInterface $miniProgram, string $openId, ?string $unionId = null): UserInterface; }
Usage Example
Here's a complete example of how to implement these interfaces:
<?php use Tourze\WechatMiniProgramUserContracts\UserInterface; use Tourze\WechatMiniProgramUserContracts\UserLoaderInterface; use Tourze\WechatMiniProgramAppIDContracts\MiniProgramInterface; class MyUser implements UserInterface { public function __construct( private MiniProgramInterface $miniProgram, private string $openId, private ?string $unionId = null, private ?string $avatarUrl = null ) {} public function getMiniProgram(): MiniProgramInterface { return $this->miniProgram; } public function getOpenId(): string { return $this->openId; } public function getUnionId(): ?string { return $this->unionId; } public function getAvatarUrl(): ?string { return $this->avatarUrl; } } class MyUserService implements UserLoaderInterface { public function __construct( private UserRepository $userRepository ) {} public function loadUserByOpenId(string $openId): ?UserInterface { return $this->userRepository->findByOpenId($openId); } public function loadUserByUnionId(string $unionId): ?UserInterface { return $this->userRepository->findByUnionId($unionId); } public function createUser(MiniProgramInterface $miniProgram, string $openId, ?string $unionId = null): UserInterface { $user = new MyUser($miniProgram, $openId, $unionId); $this->userRepository->save($user); return $user; } }
Dependencies
- PHP: 8.1 or higher
- tourze/wechat-mini-program-appid-contracts: For MiniProgramInterface dependency
- ext-json: Required for JSON operations
Development Dependencies
- phpstan/phpstan: ^2.1 - Static analysis
- phpunit/phpunit: ^11.5 - Unit testing
Quality Assurance
This package maintains high code quality standards:
- Static Analysis: Uses PHPStan for type checking and error detection
- Unit Testing: Comprehensive test coverage with PHPUnit
- Strict Types: Enforces strict typing throughout the codebase
- PSR Standards: Follows PSR-4 autoloading and PSR-12 coding standards
Versioning
This package follows Semantic Versioning. Major versions are introduced when breaking changes are made.
License
This package is licensed under the MIT License.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
- Clone the repository
- Install dependencies:
composer install - Run tests:
composer test - Run static analysis:
composer analyze
Testing
Run the test suite:
composer test
Run static analysis:
composer analyze
Support
If you encounter any issues or have questions, please:
- Check the GitHub Issues
- Create a new issue if needed
- Join our discussions for community support
tourze/wechat-mini-program-user-contracts 适用场景与选型建议
tourze/wechat-mini-program-user-contracts 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.43k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tourze/wechat-mini-program-user-contracts 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tourze/wechat-mini-program-user-contracts 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.43k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 9
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-10