PHP code example of tourze / wechat-mini-program-subscribe-message-bundle

1. Go to this page and download the library: Download tourze/wechat-mini-program-subscribe-message-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-mini-program-subscribe-message-bundle example snippets



return [
    // ... other bundles
    WechatMiniProgramSubscribeMessageBundle\WechatMiniProgramSubscribeMessageBundle::class => ['all' => true],
];

use WechatMiniProgramSubscribeMessageBundle\Request\SendSubscribeMessageRequest;
use WechatMiniProgramBundle\Service\Client;

$request = new SendSubscribeMessageRequest();
$request->setToUser('user_openid');
$request->setTemplateId('your_template_id');
$request->setPage('pages/index');
$request->setData([
    'thing1' => ['value' => 'Message content'],
    'time2' => ['value' => '2023-01-01 10:00:00'],
]);

$response = $client->request($request);

// In your expression language context
sendWechatMiniProgramSubscribeMessage(user, 'template_id', ['param1' => 'value:context.data'])

use WechatMiniProgramSubscribeMessageBundle\Repository\SubscribeTemplateRepository;

// Get available templates
$templates = $subscribeTemplateRepository->findBy(['state' => 1]);

// Access template parameters
foreach ($template->getSubscribeParams() as $param) {
    echo $param->getName() . ': ' . $param->getExample();
}

use WechatMiniProgramSubscribeMessageBundle\Event\SubscribeMsgPopupEvent;

// Listen to subscribe message popup events
class SubscribeMessageListener
{
    public function onSubscribeMsgPopup(SubscribeMsgPopupEvent $event): void
    {
        // Handle the event
    }
}
bash
php bin/console doctrine:migrations:migrate