tourze/wechat-work-external-contact-model

企业微信外部联系人定义

Installs: 460

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/tourze/wechat-work-external-contact-model

0.0.4 2025-06-04 17:40 UTC

This package is auto-updated.

Last update: 2025-10-31 07:56:32 UTC


README

English | 中文

Latest Version Total Downloads License [PHP Version] Build Status Code Coverage

A PHP library that provides interface definitions and type enumerations for WeChat Work (Enterprise WeChat) external contacts.

Installation

composer require tourze/wechat-work-external-contact-model

Quick Start

Contact Type Enumeration

<?php

use Tourze\WechatWorkExternalContactModel\ContactType;

// Get contact type label
echo ContactType::WECHAT->getLabel(); // 'WeChat User'
echo ContactType::WEWORK->getLabel(); // 'WeChat Work User'

// Get all contact types for select options
$options = ContactType::getSelectOptions();

External Contact Interface

<?php

use Tourze\WechatWorkExternalContactModel\ExternalContactInterface;

class MyExternalContact implements ExternalContactInterface
{
    public function getExternalUserId(): ?string
    {
        // Return the external user ID
        return $this->externalUserId;
    }

    public function getUnionId(): ?string
    {
        // Return the union ID
        return $this->unionId;
    }

    public function getNickname(): ?string
    {
        // Return the nickname
        return $this->nickname;
    }

    public function getAvatar(): ?string
    {
        // Return the avatar URL
        return $this->avatar;
    }
}

External User Loader Interface

<?php

use Tourze\WechatWorkExternalContactModel\ExternalUserLoaderInterface;
use Tourze\WechatWorkContracts\CorpInterface;

class MyExternalUserLoader implements ExternalUserLoaderInterface
{
    public function loadByUnionIdAndCorp(string $unionId, CorpInterface $corp): ?ExternalContactInterface
    {
        // Load external contact by union ID and corporation
        return $this->findExternalContact($unionId, $corp);
    }
}

Components

ContactType Enum

Defines the type of external contact:

  • WECHAT (1): WeChat user
  • WEWORK (2): WeChat Work user

ExternalContactInterface

Defines the contract for external contact entities with methods:

  • getExternalUserId(): Get external user ID
  • getUnionId(): Get union ID
  • getNickname(): Get nickname
  • getAvatar(): Get avatar URL

ExternalUserLoaderInterface

Defines the contract for loading external contacts:

  • loadByUnionIdAndCorp(): Load by union ID and corporation

Dependencies

  • PHP 8.1+
  • tourze/enum-extra: Enhanced enum functionality
  • tourze/wechat-work-contracts: WeChat Work contracts

Reference

License

MIT