feat: 新增举报详情功能及相关接口、页面

新增举报详情页面路由与配置
新增举报详情接口及路由规则
新增举报列表状态筛选功能
新增错误信息标准化处理方法
优化举报列表页面UI交互
完善微信登录异常提示处理
这个提交包含在:
2026-11-19 09:16:58 +08:00
父节点 7e22a66de0
当前提交 134267fcd9
共有 31 个文件被更改,包括 2849 次插入 和 572 次删除

查看文件

@@ -134,10 +134,15 @@ class WxMini
{
$code = trim((string)$code);
if ($code === '') {
throw new \RuntimeException('缺少微信授权 code');
throw new \RuntimeException('缺少微信授权凭证,请重试');
}
try {
$res = self::toArray(self::app()->auth->session($code));
} catch (\Throwable $e) {
throw new \RuntimeException(self::translateException($e, '微信登录失败,请重试'));
}
$res = self::toArray(self::app()->auth->session($code));
if (empty($res['openid'])) {
throw new \RuntimeException(self::errorMessage($res, '微信登录失败,请重试'));
}
@@ -171,13 +176,17 @@ class WxMini
{
$code = trim((string)$code);
if ($code === '') {
throw new \RuntimeException('缺少手机号授权 code');
throw new \RuntimeException('缺少手机号授权凭证,请重试');
}
// SDK 的 BaseClient 会自动带上 access_token(含缓存与 401 重试)
$res = self::toArray(
self::app()->getClient()->httpPostJson('wxa/business/getuserphonenumber', ['code' => $code])
);
try {
$res = self::toArray(
self::app()->getClient()->httpPostJson('wxa/business/getuserphonenumber', ['code' => $code])
);
} catch (\Throwable $e) {
throw new \RuntimeException(self::translateException($e, '微信手机号获取失败,请改用手动输入'));
}
$info = (isset($res['phone_info']) && is_array($res['phone_info'])) ? $res['phone_info'] : [];
$phone = '';
@@ -284,7 +293,7 @@ class WxMini
*
* @param array $res 微信应答
* @param string $fallback 兜底文案
* @return string
* @return string 用户可理解的中文提示
*/
protected static function errorMessage(array $res, $fallback)
{
@@ -292,16 +301,98 @@ class WxMini
$msg = isset($res['errmsg']) ? (string)$res['errmsg'] : '';
$known = [
40029 => '微信登录凭证已失效,请重新授权',
40163 => '微信登录凭证已被使用,请重新授权',
41004 => '小程序 AppSecret 不正确,请在后台检查微信登录配置',
45011 => '微信接口调用过于频繁,请稍后再试',
-1 => '微信服务繁忙,请稍后再试',
40001 => '微信授权凭证无效,请联系管理员检查小程序配置',
40002 => '微信授权参数异常,请重新尝试',
40013 => '小程序 AppID 配置无效,请联系管理员检查',
40029 => '微信登录凭证已失效,请重新授权',
40125 => '小程序 AppSecret 配置无效,请联系管理员检查',
40163 => '微信登录凭证已被使用,请重新授权',
40164 => '服务器 IP 未加入微信白名单,请联系管理员处理',
40226 => '当前微信账号存在安全风险,暂无法登录',
41002 => '缺少小程序 AppID 配置,请联系管理员检查',
41004 => '小程序 AppSecret 不正确,请在后台检查微信登录配置',
43002 => '微信接口请求方式异常,请重试',
45009 => '今日微信接口调用次数已达上限,请稍后再试',
45011 => '微信接口调用过于频繁,请稍后再试',
48001 => '当前小程序暂未开通该接口权限,请联系管理员',
50002 => '当前微信账号状态受限,无法完成操作',
89503 => '微信接口调用受限,请稍后再试',
89506 => '微信接口调用受限,请稍后再试',
89507 => '微信接口调用受限,请稍后再试',
];
if (isset($known[$code])) {
return $known[$code];
}
return $msg !== '' ? $fallback . '(' . $code . ': ' . $msg . ')' : $fallback;
if ($msg !== '') {
$lower = strtolower($msg);
if (strpos($lower, 'invalid appid') !== false) {
return '小程序 AppID 配置无效,请联系管理员检查';
}
if (strpos($lower, 'invalid appsecret') !== false) {
return '小程序 AppSecret 配置无效,请联系管理员检查';
}
if (strpos($lower, 'invalid code') !== false) {
return '微信登录凭证已失效,请重新授权';
}
if (strpos($lower, 'code been used') !== false) {
return '微信登录凭证已被使用,请重新授权';
}
if (strpos($lower, 'freq') !== false || strpos($lower, 'limit') !== false) {
return '微信接口调用过于频繁,请稍后再试';
}
if (strpos($lower, 'system error') !== false || strpos($lower, 'busy') !== false) {
return '微信服务繁忙,请稍后再试';
}
\think\Log::error('[WxMini] 微信接口返回未映射错误: errcode=' . $code . ', errmsg=' . $msg);
}
return $code !== 0 ? $fallback . '(错误码:' . $code . ')' : $fallback;
}
/**
* 将微信 SDK / 网络 / 系统异常转换为用户可理解的中文提示
*
* @param \Throwable $e 捕获的异常
* @param string $fallback 默认中文兜底文案
* @return string 中文错误提示
*/
public static function translateException(\Throwable $e, $fallback = '微信服务异常,请稍后再试')
{
$raw = trim((string)$e->getMessage());
if ($raw === '') {
return $fallback;
}
// 若消息本身已包含中文且不含底层英文错误特征(如 SQLSTATE / cURL / JSON 报错),直接透传
if (preg_match('/[\x{4e00}-\x{9fa5}]/u', $raw)
&& stripos($raw, 'SQLSTATE') === false
&& stripos($raw, 'cURL error') === false
&& stripos($raw, 'Request access_token fail') === false
) {
return $raw;
}
// 尝试从 EasyWeChat 异常消息中解析微信 JSON 错误(如 Request access_token fail: {"errcode":40013,"errmsg":"invalid appid"})
if (preg_match('/\{.*"errcode"\s*:\s*-?\d+.*\}/s', $raw, $matches)) {
$decoded = json_decode($matches[0], true);
if (is_array($decoded) && isset($decoded['errcode'])) {
return self::errorMessage($decoded, $fallback);
}
}
$lower = strtolower($raw);
if (strpos($lower, 'timed out') !== false || strpos($lower, 'timeout') !== false || strpos($lower, 'curl error 28') !== false) {
\think\Log::error('[WxMini] 请求微信超时: ' . $raw);
return '连接微信服务器超时,请稍后重试';
}
if (strpos($lower, 'curl error') !== false || strpos($lower, 'could not resolve') !== false || strpos($lower, 'failed to connect') !== false || strpos($lower, 'ssl') !== false) {
\think\Log::error('[WxMini] 请求微信网络异常: ' . $raw);
return '网络连接微信服务器失败,请稍后重试';
}
\think\Log::error('[WxMini] 微信调用异常: ' . $raw);
return $fallback;
}
}