PHP code example of tourze / wechat-work-external-contact-model

1. Go to this page and download the library: Download tourze/wechat-work-external-contact-model library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tourze / wechat-work-external-contact-model example snippets




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();



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;
    }
}



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);
    }
}