PHP code example of tsaotai / tsaotai-helper

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

    

tsaotai / tsaotai-helper example snippets


// GET 请求
$result = pull('https://api.example.com/users', 'GET', ['page' => 1]);

// POST 请求
$result = pull('https://api.example.com/users', 'POST', [
    'name' => '张三',
    'email' => '[email protected]'
]);

// 返回格式
// ['code' => 200, 'data' => [...], 'http_code' => 200]

// 成功响应
return push(0, '操作成功', $data);

// 失败响应
return push(404, '资源不存在');

// 返回格式
// {
//     "success": true,
//     "code": 0,
//     "message": "操作成功",
//     "data": [...],
//     "timestamp": 1685700000,
//     "request_id": "uuid-xxx",
//     "version": "1.0.0"
// }

$id = uuid();
// "a1b2c3d4-e5f6-7890-abcd-ef1234567890"