php代码调用氚云平台的数据!
废话就不说了,直接止代码!
<?php
// 请求地址
$apiAddress = "https://www.h3yun.com/OpenApi/Invoke";
// 认证参数(请填写你的实际 EngineCode 和 EngineSecret)
$engineCode = ""; // 氚云的 EngineCode
$engineSecret = ""; // 氚云的 EngineSecret
// 获取当天日期,格式 yyyy/m/d
$today = date('Y/n/j');
// 请求参数数组
$params = [
"ActionName" => "LoadBizObjects",
"SchemaCode" => "", // 氚云的 SchemaCode
"Filter" => json_encode([
"FromRowNum" => 0,
"RequireCount" => false,
"ReturnItems" => [],
"SortByCollection" => [],
"ToRowNum" => 500,
"Matcher" => [
"Type" => "And",
"Matchers" => []
]
])
];
// JSON 编码请求参数
$jsonData = json_encode($params);
// 初始化 cURL
$ch = curl_init($apiAddress);
// 设置 HTTP 请求头
$headers = [
"Content-Type: application/json",
"EngineCode: $engineCode",
"EngineSecret: $engineSecret"
];
// 设置 cURL 选项
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
// 发送请求并获取响应
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo "cURL Error: " . curl_error($ch);
} else {
$data = json_decode($response, true);
if ($data["Successful"] && isset($data["ReturnData"]["BizObjectArray"])) {
$items = $data["ReturnData"]["BizObjectArray"];
// 按来访时间排序,降序(越早的时间越靠后)
usort($items, function($a, $b) {
$timeA = $a["F0000047"] ?? ''; // F0000047 为字段的编号
$timeB = $b["F0000047"] ?? '';
// 如果时间格式是标准可比较字符串,直接比较
return strcmp($timeB,$timeA);
});
$result = [];
foreach ($items as $item) {
if (strpos($item["F0000047"], $today) === 0) { // 只显示当天的信息,可以根据需要修改。
$result[] = [
"名称" => $item["F0000036"] ?? "无", // F0000036 为字段的编号
"日期" => $item["F0000047"] ?? "无",
"等级" => $item["F0000072"] ?? "无",
];
}
}
json_encode($result, true);
} else {
echo "请求失败或无数据";
}
}
// 关闭 cURL 资源
curl_close($ch);
正文完
微信扫码打开小程序体验更多功能
