tourze/wechat-official-account-contracts
最新稳定版本:0.0.3
Composer 安装命令:
composer require tourze/wechat-official-account-contracts
包简介
微信公众号用户接口定义和合约规范
README 文档
README
WeChat Official Account contracts and interfaces for PHP applications.
Installation
composer require tourze/wechat-official-account-contracts
Quick Start
This package provides essential interfaces for WeChat Official Account integration:
<?php use Tourze\WechatOfficialAccountContracts\UserInterface; use Tourze\WechatOfficialAccountContracts\UserLoaderInterface; use Tourze\WechatOfficialAccountContracts\OfficialAccountInterface; // Implement user interface class MyUser implements UserInterface { public function getOpenId(): string { return 'user_open_id'; } public function getUnionId(): ?string { return 'user_union_id'; } public function getAvatarUrl(): ?string { return 'https://example.com/avatar.jpg'; } public function getOfficialAccount(): ?OfficialAccountInterface { return new MyOfficialAccount(); } } // Implement user loader interface class MyUserLoader implements UserLoaderInterface { public function loadUserByOpenId(string $openId): ?UserInterface { // Load user by OpenID return new MyUser(); } public function loadUserByUnionId(string $unionId): ?UserInterface { // Load user by UnionID return new MyUser(); } public function syncUserByOpenId(OfficialAccountInterface $officialAccount, string $openId): ?UserInterface { // Sync user data from WeChat API return new MyUser(); } }
Interfaces
UserInterface
Represents a WeChat user with the following methods:
getOpenId(): Get user's OpenIDgetUnionId(): Get user's UnionID (optional)getAvatarUrl(): Get user's avatar URL (optional)getOfficialAccount(): Get associated official account (optional)
UserLoaderInterface
Provides methods to load and sync WeChat users:
loadUserByOpenId(string $openId): Load user by OpenIDloadUserByUnionId(string $unionId): Load user by UnionIDsyncUserByOpenId(OfficialAccountInterface $officialAccount, string $openId): Sync user data
OfficialAccountInterface
Represents a WeChat Official Account:
getAppId(): Get the App ID of the official account (optional)
License
MIT License. See LICENSE for details.
统计信息
- 总下载量: 930
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-16