Files
zyt/server/config/logistics.php
T
2026-05-11 17:49:38 +08:00

52 lines
1.8 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.
<?php
declare(strict_types=1);
/**
* 物流轨迹(顺丰 / 京东等)
* 对接快递100「实时查询」: https://api.kuaidi100.com
*
* 规则:同时配置好 CUSTOMER、KEY 即自动走快递100(不必再设 ENABLE=true)。
* 若需临时关闭(保留密钥):LOGISTICS_KUAIDI100_DISABLE = true
*/
$stripQuotes = static function (string $v): string {
$v = trim($v);
if (strlen($v) >= 2 && (($v[0] === '"' && $v[strlen($v) - 1] === '"') || ($v[0] === "'" && $v[strlen($v) - 1] === "'"))) {
return substr($v, 1, -1);
}
return $v;
};
// .env 为 INI 格式:写在某个 [section](如 [trtc])下面的键会变成 trtc.xxx,读不到顶层 LOGISTICS_*
$envKuaidi = static function (string $suffix, $default = '') use ($stripQuotes) {
$top = 'LOGISTICS_KUAIDI100_' . $suffix;
$v = env($top, null);
if ($v !== null && $v !== '') {
return $stripQuotes((string) $v);
}
$nested = env('trtc.' . $top, $default);
return $stripQuotes((string) $nested);
};
$customer = $envKuaidi('CUSTOMER', '');
$key = $envKuaidi('KEY', '');
$hasCreds = $customer !== '' && $key !== '';
$forceDisableRaw = env('LOGISTICS_KUAIDI100_DISABLE', null);
if ($forceDisableRaw === null || $forceDisableRaw === '') {
$forceDisableRaw = env('trtc.LOGISTICS_KUAIDI100_DISABLE', false);
}
$forceDisable = filter_var($forceDisableRaw, FILTER_VALIDATE_BOOLEAN);
// 已填 CUSTOMER+KEY 即启用;需临时关闭时设 LOGISTICS_KUAIDI100_DISABLE=trueLOGISTICS_KUAIDI100_ENABLE 已废弃,可删)
$kuaidiEnabled = ! $forceDisable && $hasCreds;
return [
'kuaidi100' => [
'enable' => $kuaidiEnabled,
'customer' => $customer,
'key' => $key,
'query_url' => $envKuaidi('QUERY_URL', 'https://poll.kuaidi100.com/poll/query.do'),
],
];