CaiWuXiTong/app/Support/EsignErrorMessage.php

33 lines
1.1 KiB
PHP
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
namespace App\Support;
final class EsignErrorMessage
{
public static function sanitize(?string $message, int $limit = 240): ?string
{
$message = trim((string) preg_replace('/[[:cntrl:]]+/u', ' ', (string) $message));
if ($message === '') {
return null;
}
$message = (string) preg_replace('/(?<!\d)(1[3-9]\d)\d{4}(\d{4})(?!\d)/u', '$1****$2', $message);
$message = (string) preg_replace_callback(
'/(?<![A-Z0-9._%+\-])([A-Z0-9._%+\-]+)@([A-Z0-9.\-]+\.[A-Z]{2,})(?![A-Z0-9._%+\-])/iu',
static fn (array $matches): string => mb_substr($matches[1], 0, 1) . '***@' . $matches[2],
$message,
);
$message = (string) preg_replace('/(?<!\d)(\d{6})\d{8}(\d{3}[0-9Xx])(?!\d)/u', '$1********$2', $message);
return mb_substr($message, 0, $limit);
}
public static function isDefinitiveFailure(?string $message): bool
{
$message = (string) $message;
return preg_match('/E\s*签宝接口返回业务错误/u', $message) === 1
|| preg_match('/E\s*签宝接口请求失败(HTTP\s+4\d{2})/iu', $message) === 1;
}
}