定制 tourze/wechat-official-account-contracts 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

tourze/wechat-official-account-contracts

最新稳定版本:0.0.3

Composer 安装命令:

composer require tourze/wechat-official-account-contracts

包简介

微信公众号用户接口定义和合约规范

README 文档

README

PHP Version License Build Status Code Coverage

English | 中文

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 OpenID
  • getUnionId(): 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 OpenID
  • loadUserByUnionId(string $unionId): Load user by UnionID
  • syncUserByOpenId(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

GitHub 信息

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

其他信息

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