生成详情json-debug
This commit is contained in:
@@ -468,32 +468,61 @@ EOF;
|
|||||||
* }
|
* }
|
||||||
* ]
|
* ]
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* 线上专用:分页生成 Video JSON
|
||||||
|
*
|
||||||
|
* 每个文件格式:
|
||||||
|
* [
|
||||||
|
* {
|
||||||
|
* "keyword": "...",
|
||||||
|
* "site": "...",
|
||||||
|
* "href": "https://www.xxx.com/...",
|
||||||
|
* "url": "#"
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
*/
|
||||||
public function generateVideoJsonByPage(int $intPage): void
|
public function generateVideoJsonByPage(int $intPage): void
|
||||||
{
|
{
|
||||||
|
// ===== 1. 显式输出,防止静默失败 =====
|
||||||
|
echo "[JSON] start page={$intPage}\n";
|
||||||
|
|
||||||
$intStart = ($intPage - 1) * $this->intPageSize;
|
$intStart = ($intPage - 1) * $this->intPageSize;
|
||||||
|
|
||||||
foreach ($this->getDomain() as $DomainModel) {
|
foreach ($this->getDomain() as $DomainModel) {
|
||||||
|
|
||||||
$strDomainDir = $this->strSiteMapPath . $DomainModel->d_domain;
|
// ===== 2. 安全路径处理 =====
|
||||||
|
$strDomainDir = rtrim($this->strSiteMapPath, '/') . '/' . $DomainModel->d_domain;
|
||||||
|
|
||||||
if (!is_dir($strDomainDir)) {
|
if (!is_dir($strDomainDir)) {
|
||||||
mkdir($strDomainDir, 0755, true);
|
if (!mkdir($strDomainDir, 0755, true) && !is_dir($strDomainDir)) {
|
||||||
|
file_put_contents(
|
||||||
|
'/tmp/video_json_error.log',
|
||||||
|
"[mkdir fail] {$strDomainDir}\n",
|
||||||
|
FILE_APPEND
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$strJsonFile = sprintf(
|
$strJsonFile = $strDomainDir . "/video-list-{$intPage}.json";
|
||||||
'%s/video-list-%d.json',
|
|
||||||
$strDomainDir,
|
$fp = @fopen($strJsonFile, 'w');
|
||||||
$intPage
|
if ($fp === false) {
|
||||||
|
file_put_contents(
|
||||||
|
'/tmp/video_json_error.log',
|
||||||
|
"[fopen fail] {$strJsonFile}\n",
|
||||||
|
FILE_APPEND
|
||||||
);
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$fp = fopen($strJsonFile, 'w');
|
// ===== 3. JSON 数组开始 =====
|
||||||
|
|
||||||
// JSON 数组开始
|
|
||||||
fwrite($fp, "[\n");
|
fwrite($fp, "[\n");
|
||||||
|
|
||||||
$isFirst = true;
|
$isFirst = true;
|
||||||
|
|
||||||
foreach ($this->fetchVideosByBatch($intStart, $this->intPageSize) as $Video) {
|
foreach ($this->fetchVideosByBatch($intStart, $this->intPageSize) as $Video) {
|
||||||
|
|
||||||
|
// ===== 4. 生成 URL =====
|
||||||
$strUri = $DomainModel->getFomartUrlEx(
|
$strUri = $DomainModel->getFomartUrlEx(
|
||||||
"VIDEO_INFO_URL",
|
"VIDEO_INFO_URL",
|
||||||
$DomainModel->d_domain,
|
$DomainModel->d_domain,
|
||||||
@@ -505,34 +534,51 @@ EOF;
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$strFullUrl = sprintf(
|
$strFullUrl = 'https://www.' . $DomainModel->d_domain . $strUri;
|
||||||
'https://www.%s%s',
|
|
||||||
$DomainModel->d_domain,
|
|
||||||
$strUri
|
|
||||||
);
|
|
||||||
|
|
||||||
|
// ===== 5. 构建数据(强制字符串) =====
|
||||||
$row = [
|
$row = [
|
||||||
'keyword' => $Video->v_name,
|
'keyword' => (string)$Video->v_name,
|
||||||
'site' => $DomainModel->d_domain,
|
'site' => (string)$DomainModel->d_domain,
|
||||||
'href' => $strFullUrl,
|
'href' => (string)$strFullUrl,
|
||||||
'url' => '#',
|
'url' => '#',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// ===== 6. UTF-8 强制修复(关键) =====
|
||||||
|
foreach ($row as $k => $v) {
|
||||||
|
if (is_string($v)) {
|
||||||
|
$row[$k] = mb_convert_encoding($v, 'UTF-8', 'UTF-8');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== 7. JSON 编码(容错) =====
|
||||||
|
$json = json_encode(
|
||||||
|
$row,
|
||||||
|
JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($json === false) {
|
||||||
|
file_put_contents(
|
||||||
|
'/tmp/video_json_error.log',
|
||||||
|
"[json_encode fail] " . json_last_error_msg() . "\n",
|
||||||
|
FILE_APPEND
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$isFirst) {
|
if (!$isFirst) {
|
||||||
fwrite($fp, ",\n");
|
fwrite($fp, ",\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
fwrite(
|
fwrite($fp, $json);
|
||||||
$fp,
|
|
||||||
json_encode($row, JSON_UNESCAPED_UNICODE)
|
|
||||||
);
|
|
||||||
|
|
||||||
$isFirst = false;
|
$isFirst = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSON 数组结束
|
// ===== 8. JSON 数组结束 =====
|
||||||
fwrite($fp, "\n]");
|
fwrite($fp, "\n]");
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
|
||||||
|
echo "[JSON] done {$strJsonFile}\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user