1. Go to this page and download the library: Download jiangslee/think-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/ */
jiangslee / think-wechat example snippets
namespace app\index\controller;
use app\BaseController;
class Wechat extends BaseController
{
public function index()
{
// 初始化微信
$app = app('wechat.official_account');
$server = $app->getServer();
$server->addMessageListener('text', function ($message) {
return sprintf("你对 overtrue 说:“%s”", $message->Content);
});
// return $server->serve();
$response = $server->serve();
return $response->getBody();
}
}