From fb224c829fcc935c0ddb34c890da23a7793a0cb8 Mon Sep 17 00:00:00 2001 From: milky0217 Date: Wed, 17 Jun 2026 10:39:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=88=90=E5=8A=9F=E9=A1=B5sync-order?= =?UTF-8?q?=E8=BD=AE=E8=AF=A2=E4=BC=A0JWT-=E5=AE=9E=E6=97=B6=E7=A1=AE?= =?UTF-8?q?=E8=AE=A4=E6=94=AF=E4=BB=98=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/payment.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/handlers/payment.rs b/src/handlers/payment.rs index 101db78..8b621c8 100644 --- a/src/handlers/payment.rs +++ b/src/handlers/payment.rs @@ -710,7 +710,7 @@ pub async fn payment_page( let base_url = std::env::var("APP_BASE_URL") .unwrap_or_else(|_| "https://dev.xmclassmate.top".to_string()); let notify_url = format!("{}/payment/notify", base_url); - let return_url = format!("{}/payment/success?order_no={}", base_url, order_no); + let return_url = format!("{}/payment/success?order_no={}&jwt={}", base_url, order_no, token); let Some(config) = AlipayConfig::from_env() else { let jwt_for_mock = token.clone(); @@ -935,9 +935,10 @@ pub async fn alipay_notify( #[derive(Debug, Deserialize)] pub struct AlipaySuccessQuery { pub order_no: Option, + pub jwt: Option, } -fn build_success_html(order_no: &str) -> String { +fn build_success_html(order_no: &str, jwt_token: &str) -> String { let green = "#52c41a"; let white = "white"; let orange = "#fa8c16"; @@ -988,7 +989,7 @@ fn build_success_html(order_no: &str) -> String { if (!orderNo) return; fetch('/api/payment/sync-order', {{ method: 'POST', - headers: {{ 'Content-Type': 'application/json' }}, + headers: {{ 'Content-Type': 'application/json', 'Authorization': 'Bearer {4}' }}, body: JSON.stringify({{ order_id: orderNo }}) }}) .then(function(r){{ return r.json(); }}) @@ -1015,7 +1016,7 @@ fn build_success_html(order_no: &str) -> String { "##, - green, white, order_no, orange + green, white, order_no, orange, jwt_token ); html } @@ -1042,11 +1043,12 @@ pub async fn payment_success( query: web::Query, ) -> HttpResponse { let order_no = query.order_no.as_deref().unwrap_or(""); + let jwt_token = query.jwt.as_deref().unwrap_or(""); // 不再在此处确认订单(安全原因: 此端点无认证, 任何人知道 order_no 即可激活会员)。 // Mock 支付由 mock_confirm 在跳转前确认, 真实支付宝由 notify 异步回调确认。 - let html = build_success_html(order_no); + let html = build_success_html(order_no, jwt_token); HttpResponse::Ok() .content_type("text/html; charset=utf-8") .body(html)