fix(payment): payment_page支持URL参数传递JWT,payment_index页面跳转时携带JWT
This commit is contained in:
@@ -314,6 +314,9 @@ pub async fn payment_index() -> Result<HttpResponse, AppError> {
|
||||
<div class="notice">支付成功后额度将自动到账,如有疑问请联系客服</div>
|
||||
<script>
|
||||
let selected = null;
|
||||
// 从 URL 参数获取 JWT(来自小程序的跳转链接)
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const jwt = urlParams.get('jwt') || '';
|
||||
function selectPackage(pkg) {
|
||||
selected = pkg;
|
||||
document.querySelectorAll('.pkg-card').forEach(c => c.classList.remove('selected'));
|
||||
@@ -326,7 +329,7 @@ pub async fn payment_index() -> Result<HttpResponse, AppError> {
|
||||
}
|
||||
function goPay() {
|
||||
if (!selected) return;
|
||||
window.location.href = '/payment/page?package=' + selected;
|
||||
window.location.href = '/payment/page?package=' + selected + (jwt ? '&jwt=' + encodeURIComponent(jwt) : '');
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
@@ -343,6 +346,9 @@ pub async fn payment_index() -> Result<HttpResponse, AppError> {
|
||||
pub struct PaymentPageQuery {
|
||||
#[serde(rename = "package")]
|
||||
pub package_: String,
|
||||
/// JWT: 从 URL 参数传入(外部浏览器无 Cookie 时使用)
|
||||
#[serde(default)]
|
||||
pub jwt: Option<String>,
|
||||
}
|
||||
|
||||
#[get("/payment/page")]
|
||||
@@ -351,7 +357,9 @@ pub async fn payment_page(
|
||||
pool: web::Data<PgPool>,
|
||||
query: web::Query<PaymentPageQuery>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let token = extract_token(&req).ok_or_else(|| AppError::Unauthorized("未登录".to_string()))?;
|
||||
let token = extract_token(&req)
|
||||
.or_else(|| query.jwt.clone())
|
||||
.ok_or_else(|| AppError::Unauthorized("未登录".to_string()))?;
|
||||
|
||||
let claims = crate::auth::verify_token(&token, &get_jwt_secret())
|
||||
.map_err(|_| AppError::Unauthorized("Token 无效".to_string()))?;
|
||||
|
||||
Reference in New Issue
Block a user