PHP code example of tourze / wechat-work-server-bundle
1. Go to this page and download the library: Download tourze/wechat-work-server-bundle 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-server-bundle example snippets
use WechatWorkServerBundle\Entity\ServerMessage;
use WechatWorkServerBundle\Event\WechatWorkServerMessageRequestEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MessageHandler implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
WechatWorkServerMessageRequestEvent::class => 'onServerMessage',
];
}
public function onServerMessage(WechatWorkServerMessageRequestEvent $event)
{
$message = $event->getMessage();
// Process the message based on type
switch ($message->getMsgType()) {
case 'text':
$this->handleTextMessage($message);
break;
case 'event':
$this->handleEventMessage($message);
break;
}
}
}
use WechatWorkServerBundle\Entity\ServerMessage;
use WechatWorkServerBundle\Repository\ServerMessageRepository;
// Get message repository
$repository = $entityManager->getRepository(ServerMessage::class);
// Create message from XML
$message = $repository->createFromXML($xmlContent);
if ($message) {
$entityManager->persist($message);
$entityManager->flush();
}
// Find messages by type
$textMessages = $repository->findBy(['msgType' => 'text']);
// Find messages by user
$userMessages = $repository->findBy(['fromUserName' => 'user123']);
use WechatWorkServerBundle\Controller\ServerCallbackController;
use Symfony\Component\HttpFoundation\Request;
// Custom callback handling
class CustomCallbackController extends ServerCallbackController
{
protected function processMessage(array $messageData): void
{
// Custom processing logic
parent::processMessage($messageData);
}
}
use WechatWorkServerBundle\Repository\ServerMessageRepository;
class CustomMessageRepository extends ServerMessageRepository
{
public function findRecentMessages(int $limit = 50): array
{
return $this->createQueryBuilder('m')
->orderBy('m.createTime', 'DESC')
->setMaxResults($limit)
->getQuery()
->getResult();
}
}
bash
php bin/console doctrine:migrations:migrate
bash
# Clone the repository
git clone https://github.com/your-org/php-monorepo.git
cd php-monorepo
# Install dependencies
composer install
# Run tests
./vendor/bin/phpunit packages/wechat-work-server-bundle/tests
# Run static analysis
php -d memory_limit=2G ./vendor/bin/phpstan analyse packages/wechat-work-server-bundle
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.