修复反向代理导致站内跳转重复evus前缀

This commit is contained in:
2026-11-03 14:08:40 +08:00
parent 82612b653c
commit c119902262
8 changed files with 32 additions and 15 deletions

View File

@@ -26,6 +26,23 @@ const ESTA_INCOICETYPE = '6';
const BASE_PATH = '/evus'; // 可后端模板注入
// 站内跳转不使用 Location,避免反向代理再次给已有前缀的地址添加 /evus。
function site_redirect(string $url)
{
$prefix = rtrim(BASE_PATH, '/') . '/';
if (!str_starts_with($url, $prefix) || preg_match('/[\\\\\r\n]/', $url)) {
throw new InvalidArgumentException('无效的站内跳转地址');
}
$href = htmlspecialchars($url, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
$target = json_encode($url, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_THROW_ON_ERROR);
$html = '<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8">'
. '<meta name="viewport" content="width=device-width, initial-scale=1">'
. '<meta name="robots" content="noindex,nofollow"><title>正在跳转</title></head><body>'
. '<p>正在跳转,请稍候。<a href="' . $href . '">点击继续</a></p>'
. '<script>window.location.replace(' . $target . ');</script></body></html>';
return response($html, 200, ['Content-Type' => 'text/html; charset=utf-8', 'Cache-Control' => 'no-store']);
}
// 公共函数
function formDataToJson($fields, $postData, $kew_key, $checkField)
{

View File

@@ -15,7 +15,7 @@ class Invoice extends Base
{
parent::initialize();
if (!Session::has('user') || Session::get('user')['id'] <= 0) {
throw new HttpResponseException(redirect(url('home/login/index')->build()));
throw new HttpResponseException(site_redirect(url('home/login/index')->build()));
}
}

View File

@@ -108,6 +108,6 @@ class Login extends Base
public function logout()
{
Session::delete('user');
return redirect(url('home/index/index')->build());
return site_redirect(url('home/index/index')->build());
}
}

View File

@@ -37,11 +37,11 @@ class Pay extends Base
if (isMobile()) {
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
return redirect(url('pay/wxpay', ['order_sn' => $this->order_sn])->build());
return site_redirect(url('pay/wxpay', ['order_sn' => $this->order_sn])->build());
}
return redirect(url('pay/h5pay', ['order_sn' => $this->order_sn])->build());
return site_redirect(url('pay/h5pay', ['order_sn' => $this->order_sn])->build());
}
return redirect(url('pay/pcpay', ['order_sn' => $this->order_sn])->build());
return site_redirect(url('pay/pcpay', ['order_sn' => $this->order_sn])->build());
}
/**

View File

@@ -37,11 +37,11 @@ class Payesta extends Base
if (isMobile()) {
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
return redirect(url('payesta/wxpay', ['order_sn' => $this->order_sn])->build());
return site_redirect(url('payesta/wxpay', ['order_sn' => $this->order_sn])->build());
}
return redirect(url('payesta/h5pay', ['order_sn' => $this->order_sn])->build());
return site_redirect(url('payesta/h5pay', ['order_sn' => $this->order_sn])->build());
}
return redirect(url('payesta/pcpay', ['order_sn' => $this->order_sn])->build());
return site_redirect(url('payesta/pcpay', ['order_sn' => $this->order_sn])->build());
}
/**
@@ -78,7 +78,7 @@ class Payesta extends Base
}
$pay_result = $pay_result['data'];
if ($pay_result['pay_status']) {
return redirect(url('home/payesta/succ', ['order_sn' => $order_sn])->build());
return site_redirect(url('home/payesta/succ', ['order_sn' => $order_sn])->build());
}
//微信pc
$cfg = config('app.wechatpcpay');

View File

@@ -23,7 +23,7 @@ class User extends Base
{
parent::initialize();
if (!Session::has('user') || Session::get('user')['id'] <= 0) {
throw new HttpResponseException(redirect(url('home/login/index')->build()));
throw new HttpResponseException(site_redirect(url('home/login/index')->build()));
}
$this->userinfo = Session::get('user');
View::assign('userinfo', $this->userinfo);
@@ -97,7 +97,7 @@ class User extends Base
public function logout()
{
Session::delete('user');
return redirect(url('home/index/index')->build());
return site_redirect(url('home/index/index')->build());
}
public function checkInvoice()
@@ -271,7 +271,7 @@ class User extends Base
if (!$pay_result['code']) {
return $this->error($pay_result['msg'], url('visa/index'));
}
return redirect(url('home/pay/index', ['order_sn' => $pay_result['data']['order_sn']])->build());
return site_redirect(url('home/pay/index', ['order_sn' => $pay_result['data']['order_sn']])->build());
}
}

View File

@@ -33,7 +33,7 @@ class Wechatpay extends Base
$pay_result = $pay_result['data'];
if ($pay_result['pay_status']) {
return redirect(url('home/pay/succ', ['order_sn' => $order_sn])->build());
return site_redirect(url('home/pay/succ', ['order_sn' => $order_sn])->build());
}else{
return $this->error('支付失败,请稍后重试', url('home/detail/index')->build());
}
@@ -61,7 +61,7 @@ class Wechatpay extends Base
$pay_result = $pay_result['data'];
if ($pay_result['pay_status']) {
return redirect(url('home/payesta/succ', ['order_sn' => $order_sn])->build());
return site_redirect(url('home/payesta/succ', ['order_sn' => $order_sn])->build());
}else{
return $this->error('支付失败,请稍后重试', url('home/esta/index')->build());
}

View File

@@ -19,7 +19,7 @@ trait SelectedPayment
|| !in_array($order['pay_status'] ?? null, [0, 1, '0', '1'], true)) {
throw new \RuntimeException('订单信息获取失败,请稍后重试');
}
if ((int) $order['pay_status'] === 1) return redirect(url($route . '/succ', ['order_sn' => $this->order_sn])->build());
if ((int) $order['pay_status'] === 1) return site_redirect(url($route . '/succ', ['order_sn' => $this->order_sn])->build());
if (!isset($order['total_price']) || !ctype_digit((string) $order['total_price']) || (int) $order['total_price'] <= 0) {
throw new \RuntimeException('订单金额无效,请联系客服');
}