's'
This commit is contained in:
@@ -66,9 +66,10 @@ async function checkVipByEmailFromPayjsapi(
|
||||
request: NextRequest,
|
||||
email: string,
|
||||
password: string,
|
||||
userId?: string
|
||||
userId?: string,
|
||||
wechatUserId?: string
|
||||
): Promise<PayjsVipEmailResult | null> {
|
||||
const inflightKey = `${email}::${userId || ""}`;
|
||||
const inflightKey = `${email}::${userId || ""}::${wechatUserId || ""}`;
|
||||
const existed = inflightEmailChecks.get(inflightKey);
|
||||
if (existed) {
|
||||
return existed;
|
||||
@@ -96,6 +97,7 @@ async function checkVipByEmailFromPayjsapi(
|
||||
email,
|
||||
password,
|
||||
...(userId ? { user_id: userId } : {}),
|
||||
...(wechatUserId ? { wechat_userid: wechatUserId } : {}),
|
||||
}),
|
||||
cache: "no-store",
|
||||
signal: AbortSignal.timeout(PAYJS_CHECK_BY_EMAIL_TIMEOUT),
|
||||
@@ -291,6 +293,9 @@ export async function POST(request: NextRequest) {
|
||||
const requestedAnonymousUserId = String(
|
||||
body?.user_id ?? body?.anonymousUserId ?? ""
|
||||
).trim();
|
||||
const wechatUserId = String(
|
||||
body?.wechat_userid ?? body?.userid ?? ""
|
||||
).trim();
|
||||
|
||||
console.log(
|
||||
"[check-by-email] request email=%s user_id=%s",
|
||||
@@ -326,7 +331,8 @@ export async function POST(request: NextRequest) {
|
||||
request,
|
||||
email,
|
||||
password,
|
||||
requestedAnonymousUserId || undefined
|
||||
requestedAnonymousUserId || undefined,
|
||||
wechatUserId || undefined
|
||||
);
|
||||
// PB 登录失败时,尝试使用 payjsapi 返回的 token/record 兜底恢复
|
||||
if (payjsResult?.vip && payjsResult.token && payjsResult.record?.id) {
|
||||
@@ -357,7 +363,8 @@ export async function POST(request: NextRequest) {
|
||||
request,
|
||||
email,
|
||||
password,
|
||||
requestedAnonymousUserId || undefined
|
||||
requestedAnonymousUserId || undefined,
|
||||
wechatUserId || undefined
|
||||
);
|
||||
}
|
||||
if (payjsResult?.vip) {
|
||||
@@ -397,7 +404,8 @@ export async function POST(request: NextRequest) {
|
||||
request,
|
||||
email,
|
||||
password,
|
||||
requestedAnonymousUserId || undefined
|
||||
requestedAnonymousUserId || undefined,
|
||||
wechatUserId || undefined
|
||||
);
|
||||
recovery = await resolveRecovery(
|
||||
adminToken,
|
||||
@@ -451,6 +459,20 @@ export async function POST(request: NextRequest) {
|
||||
anonymousUserId
|
||||
);
|
||||
|
||||
if (wechatUserId) {
|
||||
const apiUrl = resolvePayApiUrl(request);
|
||||
await fetch(`${apiUrl}/nomadvip/wechat_profile`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
user_id: anonymousUserId || authData.record.id,
|
||||
email,
|
||||
wechat_userid: wechatUserId,
|
||||
}),
|
||||
cache: "no-store",
|
||||
}).catch(() => null);
|
||||
}
|
||||
|
||||
console.log(
|
||||
"[check-by-email] success source=%s pbUserId=%s anonymousUserId=%s",
|
||||
recovery.source ?? "pocketbase",
|
||||
|
||||
32
app/api/vip/identity-diagnose/route.ts
Normal file
32
app/api/vip/identity-diagnose/route.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getApiUrlFromRequest, getPaymentConfig } from "@/config/services.config";
|
||||
|
||||
function resolvePayApiUrl(request: NextRequest): string {
|
||||
const payConfig = getPaymentConfig();
|
||||
const hostHeader =
|
||||
request.headers.get("host") || request.headers.get("x-forwarded-host");
|
||||
return (
|
||||
(hostHeader ? getApiUrlFromRequest(hostHeader) : null) || payConfig.apiUrl
|
||||
).replace(/\/$/, "");
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const body = await request.json().catch(() => ({}));
|
||||
const apiUrl = resolvePayApiUrl(request);
|
||||
const res = await fetch(`${apiUrl}/nomadvip/identity_diagnose`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body || {}),
|
||||
cache: "no-store",
|
||||
}).catch(() => null);
|
||||
|
||||
if (!res) {
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "upstream unavailable" },
|
||||
{ status: 502 }
|
||||
);
|
||||
}
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return NextResponse.json(data, { status: res.ok ? 200 : 502 });
|
||||
}
|
||||
|
||||
29
app/api/vip/wechat-profile/route.ts
Normal file
29
app/api/vip/wechat-profile/route.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getApiUrlFromRequest, getPaymentConfig } from "@/config/services.config";
|
||||
|
||||
function resolvePayApiUrl(request: NextRequest): string {
|
||||
const payConfig = getPaymentConfig();
|
||||
const hostHeader = request.headers.get("host") || request.headers.get("x-forwarded-host");
|
||||
return (
|
||||
(hostHeader ? getApiUrlFromRequest(hostHeader) : null) ||
|
||||
payConfig.apiUrl
|
||||
).replace(/\/$/, "");
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const body = await request.json().catch(() => ({}));
|
||||
const apiUrl = resolvePayApiUrl(request);
|
||||
const res = await fetch(`${apiUrl}/nomadvip/wechat_profile`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body || {}),
|
||||
cache: "no-store",
|
||||
}).catch(() => null);
|
||||
|
||||
if (!res) {
|
||||
return NextResponse.json({ ok: false, found: false, error: "upstream unavailable" }, { status: 502 });
|
||||
}
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return NextResponse.json(data, { status: res.ok ? 200 : 502 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user