1. Go to this page and download the library: Download pfinal/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/ */
pfinal / wechat example snippets
Final\Wechat\Kernel;
use PFinal\Wechat\Message\Receive;
use PFinal\Wechat\Message;
use PFinal\Wechat\WechatEvent;
use PFinal\Wechat\Support\Log;
//配置项
$config = array(
'appId' => 'xxxxxxxxx',
'appSecret' => 'xxxxxxxxxxxxxxxxxxxx',
'token' => 'xxxxxx',
'encodingAesKey' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
//更多详细配置请参考 demo/config-local.example
);
//初始化
Kernel::init($config);
//消息处理
Kernel::register(Receive::TYPE_TEXT, function (WechatEvent $event) {
$message = $event->getMessage();
$event->setResponse('你好');
$event->stopPropagation();
});
//关注事件
Kernel::register(Receive::TYPE_EVENT_SUBSCRIBE, function (WechatEvent $event) {
$event->setResponse('你关注或是不关注,我都在这里,不悲不喜~~');
$event->stopPropagation();
});
//处理微信服务器的请求
$response = Kernel::handle();
echo $response;