PHP code example of easelify / xiaoet

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

    

easelify / xiaoet example snippets


use xiaoet\Client;
use xiaoet\request\AccessTokenRequest;
use xiaoet\request\UserInfoGetRequest;

// 创建 Client 对象
$config = [
    'app_id' => 'your app id',
    'client_id' => 'your client id',
    'app_secret' => 'your app secret',
];
$client = new Client($config);

// 获取 access token
$req = new AccessTokenRequest();
$req->setAppId($config['app_id']);
$req->setClientId($config['client_id']);
$req->setSecretKey($config['app_secret']);
$rs = $client->execute($req);

$accessToken = '';
if ($rs['code'] == 0) {
    // 可储存$accessToken到数据库或文件备用
    // 根据 expires_in 字段做统一获取
    $accessToken = $rs['data']['access_token'];
} else {
    throw new \Exception('Access Token 获取失败: ' . $rs['msg']);
}

// 获取用户信息
$req = new UserInfoGetRequest();
$req->setUserId('u_5ec2a39b6857a_vG4siBRLLy');
$rs = $client->execute($req, $accessToken);
print_r($rs);