PHP code example of tourze / wechat-mini-program-custom-service-bundle

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


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

use WechatMiniProgramCustomServiceBundle\Entity\TextMessage;
use WechatMiniProgramCustomServiceBundle\Request\SendMessageRequest;

// Create a text message
$textMessage = new TextMessage();
$textMessage->setTouser('user_openid');
$textMessage->setContent('Hello from WeChat Mini Program!');
$textMessage->setAccount($account);

// Send the message
$request = new SendMessageRequest();
$request->setMessage($textMessage);
$request->setAccount($account);

// Use your HTTP client to send the request

$textMessage = new TextMessage();
$textMessage->setTouser('user_openid')
           ->setContent('Your message content')
           ->setAccount($account);

$imageMessage = new ImageMessage();
$imageMessage->setTouser('user_openid')
            ->setMediaId('media_id_from_wechat')
            ->setAccount($account);

$linkMessage = new LinkMessage();
$linkMessage->setTouser('user_openid')
           ->setTitle('Link Title')
           ->setDescription('Link Description')
           ->setUrl('https://example.com')
           ->setThumbUrl('https://example.com/thumb.jpg')
           ->setAccount($account);

$mpPageMessage = new MpPageMessage();
$mpPageMessage->setTouser('user_openid')
             ->setTitle('Page Title')
             ->setPagePath('pages/index/index')
             ->setThumbMediaId('thumb_media_id')
             ->setAccount($account);

use WechatMiniProgramCustomServiceBundle\EventSubscriber\MessageListener;

// The MessageListener automatically handles message events
// when integrated with the WeChat Mini Program bundle
bash
php bin/console doctrine:migrations:migrate