pangu-user-platform/scripts/test/quickstart.php

65 lines
1.9 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env php
<?php
/**
* 快速开始 - 最简单的调用示例
*
* 使用方法:
* php quickstart.php
*
* @author pangu
* @date 2026-02-04
*/
require_once __DIR__ . '/OpenApiClient.php';
// ============================================================
// 配置信息(请修改为您的应用信息)
// ============================================================
$config = [
'baseUrl' => 'http://localhost:8080',
'appCode' => 'YY000001', // 替换为您的应用编码
'appSecret' => '2221c3d6f00c4baabfabfd4f679693f1', // 替换为您的应用密钥(从应用管理获取)
];
// ============================================================
// 创建客户端
// ============================================================
$client = new OpenApiClient(
$config['baseUrl'],
$config['appCode'],
$config['appSecret'],
false // 调试模式false=关闭, true=开启
);
// ============================================================
// 调用接口
// ============================================================
try {
// 查询学生列表
$result = $client->get('/open/api/student/list', [
'pageNum' => 1,
'pageSize' => 10,
// 'studentName' => '张', // 可选:按姓名模糊查询
// 'schoolId' => 1, // 可选:按学校筛选
]);
// 处理结果
if ($result['code'] === 200) {
echo "✅ 调用成功!\n\n";
echo "总记录数: {$result['total']}\n";
echo "当前页数据量: " . count($result['rows']) . "\n\n";
// 输出学生列表
foreach ($result['rows'] as $index => $student) {
echo ($index + 1) . ". {$student['studentName']} - {$student['studentCode']}\n";
}
} else {
echo "❌ 调用失败: {$result['msg']}\n";
}
} catch (Exception $e) {
echo "❌ 异常: {$e->getMessage()}\n";
}