feat(shopro_huifu): 添加分账扩展材料上传功能并优化图片处理

- 新增 UploadSplitExtendedMaterials 命令用于上传 F469/F330 等分账补充材料
- 优化 ProbeSplitConfigDeps 命令中扩展材料配置的检查逻辑
- 支持 PDF 文件上传,增加文件大小限制(PDF 5MB,图片 2MB)
- 修复 MCC 编码可作为 online_busi_type 备选值的问题

```
这个提交包含在:
可乐加冰
2026-10-16 09:59:32 +08:00
父节点 7767298a43
当前提交 420367200c
共有 4 个文件被更改,包括 175 次插入 和 11 次删除

查看文件

@@ -29,10 +29,14 @@ class HuifuOnboardPicture
$request->setFileType($fileType);
list($sourcePath, $sourceTemp) = $this->resolveUploadFile($imageUrl);
list($uploadPath, $uploadTemp) = $this->normalizeImageForHuifu($sourcePath, $sourceTemp);
if ($this->isPdfFile($sourcePath)) {
list($uploadPath, $uploadTemp) = [$sourcePath, $sourceTemp];
} else {
list($uploadPath, $uploadTemp) = $this->normalizeImageForHuifu($sourcePath, $sourceTemp);
}
$filename = $this->buildUploadFilename($fileType, $uploadPath);
$mime = $this->detectMime($uploadPath);
$mime = $this->isPdfFile($uploadPath) ? 'application/pdf' : $this->detectMime($uploadPath);
$merchantHuifuId = $this->sdk->getPictureMerchantHuifuId();
$extend = $this->sdk->mergeSkillHuifuId([
@@ -166,9 +170,11 @@ class HuifuOnboardPicture
'F12' => 'bank_card',
'F13' => 'bank_card',
];
$base = $map[$fileType] ?? 'upload';
$base = $map[$fileType] ?? strtolower($fileType);
$ext = strtolower(pathinfo($localPath, PATHINFO_EXTENSION));
if (!in_array($ext, ['jpg', 'jpeg', 'png'], true)) {
if ($this->isPdfFile($localPath)) {
$ext = 'pdf';
} elseif (!in_array($ext, ['jpg', 'jpeg', 'png'], true)) {
$ext = 'jpg';
}
if ($ext === 'jpeg') {
@@ -177,6 +183,15 @@ class HuifuOnboardPicture
return substr($base, 0, 20) . '.' . $ext;
}
protected function isPdfFile($localPath)
{
if (!is_file($localPath)) {
return false;
}
$head = @file_get_contents($localPath, false, null, 0, 5);
return is_string($head) && strncmp($head, '%PDF-', 5) === 0;
}
protected function detectMime($localPath)
{
if (function_exists('mime_content_type')) {
@@ -293,6 +308,12 @@ class HuifuOnboardPicture
{
$localPath = $this->resolveLocalPath($imageUrl);
if ($localPath && is_file($localPath)) {
$isPdf = $this->isPdfFile($localPath);
$maxBytes = $isPdf ? (5 * 1024 * 1024) : (2 * 1024 * 1024);
$size = filesize($localPath);
if ($size !== false && $size > $maxBytes) {
throw new \RuntimeException($isPdf ? 'PDF 超过 5MB,请压缩后重新上传' : '图片超过 2MB,请压缩后重新上传');
}
return [$localPath, false];
}
$absoluteUrl = $this->resolveAbsoluteUrl($imageUrl);
@@ -300,10 +321,12 @@ class HuifuOnboardPicture
if ($content === '') {
throw new \RuntimeException('无法读取图片:' . $absoluteUrl);
}
if (strlen($content) > 2 * 1024 * 1024) {
throw new \RuntimeException('图片超过 2MB,请压缩后重新上传');
$isPdf = strncmp($content, '%PDF-', 5) === 0;
$maxBytes = $isPdf ? (5 * 1024 * 1024) : (2 * 1024 * 1024);
if (strlen($content) > $maxBytes) {
throw new \RuntimeException($isPdf ? 'PDF 超过 5MB,请压缩后重新上传' : '图片超过 2MB,请压缩后重新上传');
}
$ext = $this->guessImageExt($content, $absoluteUrl);
$ext = $isPdf ? 'pdf' : $this->guessImageExt($content, $absoluteUrl);
$tmp = tempnam(sys_get_temp_dir(), 'hf_pic_');
if ($tmp === false) {
throw new \RuntimeException('创建临时图片文件失败');
@@ -345,7 +368,10 @@ class HuifuOnboardPicture
}
$path = parse_url($url, PHP_URL_PATH);
$ext = strtolower(pathinfo((string) $path, PATHINFO_EXTENSION));
if (in_array($ext, ['jpg', 'jpeg', 'png'], true)) {
if (strncmp($binary, '%PDF-', 5) === 0) {
return 'pdf';
}
if (in_array($ext, ['jpg', 'jpeg', 'png', 'pdf'], true)) {
return $ext === 'jpeg' ? 'jpg' : $ext;
}
return 'jpg';

查看文件

@@ -448,8 +448,14 @@ class HuifuMerchantSplitService
try {
$basic = $this->client->queryMerchantBasicdata($mainHuifuId);
if (!empty($basic['ok']) && is_array($basic['data'] ?? null)) {
$found = HuifuClient::collectNestedKeys($basic['data'], ['online_busi_type']);
$found = HuifuClient::collectNestedKeys($basic['data'], ['online_busi_type', 'mcc']);
$v = trim((string) ($found['online_busi_type'] ?? ''));
if ($v === '') {
$mcc = trim((string) ($found['mcc'] ?? ''));
if ($mcc !== '' && preg_match('/^H[A-Z0-9]{4,}$/i', $mcc)) {
$v = strtoupper($mcc);
}
}
if ($v !== '') {
return $v;
}