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