1. Go to this page and download the library: Download yfwz100/wechat 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/ */
yfwz100 / wechat example snippets
yfwz100\wechat as wechat;
// Do the verification and delegate requests to proper handlers.
wechat\Init::withToken('...YOUR TOKEN...');
$router = wechat\Router::get();
// Subscription event.
$router->event->on('subscribe', function () {
// use `echo` to output everything you want just like plain PHP.
// wechat\Reply class will generate the necessary XML for you.
echo wechat\Reply::text("Welcome subscribing~");
});
// click action is subsection of events.
$router->event->click->match('clicked', function ($matches) {
echo wechat\Reply::text("You've clicked 'clicked'!");
});
// Keyword reply.
$router->text->match('hello', function ($matches) {
echo wechat\Reply::text("Hello, world!");
});