添加虚拟支付日志

This commit is contained in:
Dev
2026-10-27 16:47:23 +08:00
parent ed5c1e8c48
commit f1d03be571
5 changed files with 47 additions and 8 deletions
@@ -45,6 +45,7 @@ class VirtualPayService
{
$offerId = (string)config('common.virtual_pay.offer_id');
if ($offerId === '') {
self::logMissingOfferId();
throw new \Exception('未配置虚拟支付 OfferID');
}
$buyQuantity = self::coinQuantity($amountYuan);
@@ -377,6 +378,48 @@ class VirtualPayService
return (string)$sessionKey;
}
/**
* OfferID 为空时记下 .env 有没有被读到,不记录密钥内容
*/
private static function logMissingOfferId()
{
$envFile = (defined('ROOT_PATH') ? ROOT_PATH : '') . '.env';
$exists = $envFile !== '.env' && is_file($envFile);
$section = '';
$found = null;
if ($exists) {
$lines = file($envFile, FILE_IGNORE_NEW_LINES);
if (is_array($lines)) {
foreach ($lines as $line) {
$trim = trim($line);
if ($trim === '' || $trim[0] === ';' || $trim[0] === '#') {
continue;
}
if (preg_match('/^\[(.+)\]$/', $trim, $sectionMatch)) {
$section = $sectionMatch[1];
continue;
}
if (preg_match('/^vp_offer_id\s*=\s*(.*)$/', $trim, $valueMatch)) {
$value = trim($valueMatch[1], " \t\"'");
$found = [
'section' => $section,
'len' => strlen($value),
];
}
}
}
}
$fromEnv = getenv('PHP_WECHAT_VP_OFFER_ID');
$virtualPay = config('common.virtual_pay');
Log::error('虚拟支付 OfferID 为空 ' . json_encode([
'env_file' => $envFile,
'env_exists' => $exists,
'file_item' => $found ?: 'missing',
'getenv' => $fromEnv === false ? 'false' : ('len:' . strlen(trim((string)$fromEnv))),
'config_keys' => is_array($virtualPay) ? array_keys($virtualPay) : gettype($virtualPay),
], JSON_UNESCAPED_UNICODE));
}
/**
* @param float|string $amountYuan
* @return int