PHP code example of jiangslee / think-wechat

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();
    }
}

$official_account = app('wechat.official_account');
$mini = app('wechat.mini_app');
$payment = app('wechat.payment');
$work = app('wechat.work');
$open_platform = app('wechat.open_platform');
$open_work = app('wechat.open_work');

use jiangslee\ThinkWechat\Facade;

$officialAccount = Facade::officialAccount();  // 公众号
$miniApp = Facade::miniApp(); // 小程序
$payment = Facade::payment(); // 微信支付
$openPlatform = Facade::openPlatform(); // 开放平台
$work = Facade::work(); // 企业微信
$openWork = Facade::openWork(); // 企业微信第三方服务商

$officialAccount = Facade::officialAccount('test'); // 公众号

$officialAccount = Facade::officialAccount('',$config); // 公众号

\think\facade\Route::rule('user','wechat/user')->middleware(\jiangslee\ThinkWechat\Middleware\OauthMiddleware::class);