PHPackages                             tourze/wechat-work-contact-way-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/wechat-work-contact-way-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

tourze/wechat-work-contact-way-bundle
=====================================

企业微信客户联系「联系我」管理功能

0.0.1(11mo ago)00MITPHPPHP ^8.1CI failing

Since Jun 4Pushed 4mo agoCompare

[ Source](https://github.com/tourze/wechat-work-contact-way-bundle)[ Packagist](https://packagist.org/packages/tourze/wechat-work-contact-way-bundle)[ RSS](/packages/tourze-wechat-work-contact-way-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (27)Versions (2)Used By (0)

WeChatWorkContactWayBundle
==========================

[](#wechatworkcontactwaybundle)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/dacd51ce49ac89f892ba737c4d4228cee936c8a6128f27b27c298575604298d8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f7765636861742d776f726b2d636f6e746163742d7761792d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/wechat-work-contact-way-bundle)[![PHP Version](https://camo.githubusercontent.com/2a60d0fd134363a013427621a5f1b3f513ebd7e4d72671bf2ceec7059caaf84f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f7765636861742d776f726b2d636f6e746163742d7761792d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/wechat-work-contact-way-bundle)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/14468ddc55e8d5492bc1f15cf4c2d0818c70b0516797d83d893267cc8e5d6623/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f7765636861742d776f726b2d636f6e746163742d7761792d62756e646c652f6d61696e2e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/tourze/wechat-work-contact-way-bundle/actions)[![Code Coverage](https://camo.githubusercontent.com/3c017e5088f2b2c235228c54cb3172407b7cbfbe02d0a32383d310fbac86d942/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7765636861742d776f726b2d636f6e746163742d7761792d62756e646c652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/tourze/wechat-work-contact-way-bundle)[![Quality Score](https://camo.githubusercontent.com/6471411123e970877cef4321521b4aa1369b21202e1273274ec072c4c2c30c45/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f746f75727a652f7765636861742d776f726b2d636f6e746163742d7761792d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/tourze/wechat-work-contact-way-bundle)[![Total Downloads](https://camo.githubusercontent.com/a33253116349f10dd45c692a38840ff9e0b84d50148423ae78e96aacead92130/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f7765636861742d776f726b2d636f6e746163742d7761792d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/wechat-work-contact-way-bundle)

A comprehensive Symfony bundle for managing WeChat Work customer contact ways ("Contact Me" feature) with full API support, automated synchronization, and enterprise-grade reliability.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Entity](#entity)
    - [Commands](#commands)
    - [Requests](#requests)
    - [Repository](#repository)
    - [Event Listeners](#event-listeners)
- [Advanced Usage](#advanced-usage)
- [API Reference](#api-reference)
- [Best Practices](#best-practices)
- [Testing](#testing)
- [Requirements](#requirements)
- [Contributing](#contributing)
- [Security](#security)
- [License](#license)

Features
--------

[](#features)

- Synchronize contact ways from WeChat Work
- Manage contact way configurations
- Support temporary and permanent contact ways
- Batch operations for contact ways
- Automated synchronization via cron jobs

Installation
------------

[](#installation)

Install the bundle via Composer:

```
composer require tourze/wechat-work-contact-way-bundle
```

Configuration
-------------

[](#configuration)

Add the bundle to your `config/bundles.php`:

```
return [
    // ...
    WechatWorkContactWayBundle\WechatWorkContactWayBundle::class => ['all' => true],
];
```

Usage
-----

[](#usage)

### Entity

[](#entity)

The bundle provides the `ContactWay` entity to store contact way information:

```
use WechatWorkContactWayBundle\Entity\ContactWay;

// Create a new contact way
$contactWay = new ContactWay();
$contactWay->setConfigId('contact_way_config_id');
$contactWay->setType(1); // 1: single user, 2: multiple users
$contactWay->setScene(1); // 1: QR code in group chat, 2: QR code in enterprise
```

### Commands

[](#commands)

#### Sync Contact Ways

[](#sync-contact-ways)

Synchronize all contact ways from WeChat Work:

```
php bin/console wechat-work:sync-contact-ways
```

This command will:

- Fetch all contact ways from WeChat Work API
- Update existing contact ways or create new ones
- Automatically run daily at 6:01 AM via cron job

### Requests

[](#requests)

The bundle includes several request classes for WeChat Work API:

- `AddContactWayRequest` - Add a new contact way
- `UpdateContactWayRequest` - Update an existing contact way
- `DeleteContactWayRequest` - Delete a contact way
- `GetContactWayRequest` - Get contact way details
- `ListContactWayRequest` - List all contact ways
- `CloseTempChatRequest` - Close temporary chat

### Repository

[](#repository)

Use the `ContactWayRepository` to query contact ways:

```
use WechatWorkContactWayBundle\Repository\ContactWayRepository;

// In your controller or service
public function __construct(private ContactWayRepository $contactWayRepository)
{
}

// Find by config ID
$contactWay = $this->contactWayRepository->findOneBy(['configId' => 'config_id']);

// Find all active contact ways
$contactWays = $this->contactWayRepository->findAll();
```

### Event Listeners

[](#event-listeners)

The bundle includes event listeners that automatically manage contact way data:

- `ContactWayListener` - Handles contact way entity lifecycle events
- Automatically updates contact way information when entities are persisted

Advanced Usage
--------------

[](#advanced-usage)

### Custom Contact Way Processing

[](#custom-contact-way-processing)

For advanced scenarios, you can extend the synchronization process with custom processing logic:

```
use WechatWorkContactWayBundle\Entity\ContactWay;
use WechatWorkContactWayBundle\Repository\ContactWayRepository;

class CustomContactWayProcessor
{
    public function __construct(private ContactWayRepository $repository)
    {
    }

    public function processContactWayData(array $data): ContactWay
    {
        $contactWay = $this->repository->findOneBy(['configId' => $data['config_id']]);

        if (!$contactWay) {
            $contactWay = new ContactWay();
            $contactWay->setConfigId($data['config_id']);
        }

        // Custom business logic here
        $this->applyCustomRules($contactWay, $data);

        return $contactWay;
    }

    private function applyCustomRules(ContactWay $contactWay, array $data): void
    {
        // Implement your custom business rules
        if ($data['scene'] === 1) {
            $contactWay->setRemark('Auto-generated QR code contact');
        }
    }
}
```

### Batch Operations

[](#batch-operations)

For processing multiple contact ways efficiently:

```
use Doctrine\ORM\EntityManagerInterface;

class BatchContactWayProcessor
{
    public function __construct(private EntityManagerInterface $em)
    {
    }

    public function batchUpdate(array $contactWays): void
    {
        $batchSize = 20;
        $i = 0;

        foreach ($contactWays as $contactWay) {
            $this->em->persist($contactWay);

            if (($i % $batchSize) === 0) {
                $this->em->flush();
                $this->em->clear();
            }

            ++$i;
        }

        $this->em->flush();
        $this->em->clear();
    }
}
```

### Event-Driven Architecture

[](#event-driven-architecture)

Listen to contact way events for custom integrations:

```
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Doctrine\ORM\Events;
use Doctrine\Persistence\Event\LifecycleEventArgs;

class ContactWayEventSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            Events::postPersist,
            Events::postUpdate,
        ];
    }

    public function postPersist(LifecycleEventArgs $args): void
    {
        $entity = $args->getObject();
        if ($entity instanceof ContactWay) {
            // Handle new contact way creation
            $this->handleNewContactWay($entity);
        }
    }

    public function postUpdate(LifecycleEventArgs $args): void
    {
        $entity = $args->getObject();
        if ($entity instanceof ContactWay) {
            // Handle contact way updates
            $this->handleContactWayUpdate($entity);
        }
    }

    private function handleNewContactWay(ContactWay $contactWay): void
    {
        // Custom logic for new contact ways
    }

    private function handleContactWayUpdate(ContactWay $contactWay): void
    {
        // Custom logic for contact way updates
    }
}
```

Best Practices
--------------

[](#best-practices)

### Performance

[](#performance)

- Use repository queries instead of entity manager for complex queries
- Leverage the built-in synchronization command for regular updates
- Monitor API rate limits when making frequent requests

### Security

[](#security)

- Validate all input data before processing
- Use environment variables for sensitive configuration
- Implement proper error handling for API failures

### Error Handling

[](#error-handling)

```
try {
    $contactWay = $this->contactWayRepository->findOneBy(['configId' => $configId]);
    if (!$contactWay) {
        throw new \RuntimeException('Contact way not found');
    }
} catch (\Exception $e) {
    // Handle the error appropriately
    $this->logger->error('Contact way operation failed', ['error' => $e->getMessage()]);
}
```

Testing
-------

[](#testing)

Run the test suite:

```
# Run all tests
vendor/bin/phpunit packages/wechat-work-contact-way-bundle/tests

# Run with coverage
vendor/bin/phpunit --coverage-html coverage packages/wechat-work-contact-way-bundle/tests

# Run PHPStan analysis
vendor/bin/phpstan analyse packages/wechat-work-contact-way-bundle
```

The bundle includes comprehensive tests covering:

- Unit tests for all request classes
- Integration tests for repository operations
- Command testing with various scenarios
- Entity validation and lifecycle events

API Reference
-------------

[](#api-reference)

### ContactWay Entity Properties

[](#contactway-entity-properties)

- `configId` - Unique configuration ID from WeChat Work
- `type` - Contact way type (1: single user, 2: multiple users)
- `scene` - Usage scene (1: QR code in group chat, 2: QR code in enterprise)
- `style` - Mini program widget style
- `remark` - Remark information
- `skipVerify` - Whether to skip verification when adding
- `state` - Channel parameter for tracking
- `qrCode` - QR code URL
- `user` - User IDs array
- `party` - Department IDs array
- `temp` - Whether it's a temporary session
- `expiresIn` - Temporary session QR code expiration time
- `chatExpiresIn` - Temporary session expiration time
- `unionId` - Temporary session union ID
- `conclusions` - Conclusion messages

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine ORM 3.0 or higher

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security-1)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance64

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

343d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (4 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-wechat-work-contact-way-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-wechat-work-contact-way-bundle/health.svg)](https://phpackages.com/packages/tourze-wechat-work-contact-way-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
