PHP code example of naixiaoxin / think-wechat

1. Go to this page and download the library: Download naixiaoxin/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/ */

    

naixiaoxin / think-wechat example snippets




namespace app\wechat\controller;


use think\Controller;

class Note extends Controller
{

    public function index()
    {
        //    先初始化微信
        $app = app('wechat.official_account');
        $app->server->push(function($message){
            return 'hello,world';
        });
        $app->server->serve()->send();
    }
}

use Naixiaoxin\ThinkWechat\Facade;

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

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

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

\think\facade\Route::rule('user','usere')->middleware(\Naixiaoxin\ThinkWechat\Middleware\OauthMiddleware::class);

// 该事件有以下属性
$params['user']; // 同 session('wechat_oauth_user_default') 一样
$params['is_new']; // 是不是新的会话(第一次创建 session 时为 true)