feat: 完整重构小程序匹配功能 + 修复UI对齐 + 文章数据API
主要更新: 1. 按H5网页端完全重构匹配功能(match页面) - 4种匹配类型: 创业合伙/资源对接/导师顾问/团队招募 - 资源对接等类型弹出手机号/微信号输入框 - 去掉重新匹配按钮,改为返回按钮 2. 修复所有卡片对齐和宽度问题 - 目录页附录卡片居中 - 首页阅读进度卡片满宽度 - 我的页面菜单卡片对齐 - 推广中心分享卡片统一宽度 3. 修复目录页图标和文字对齐 - section-icon固定40rpx宽高 - section-title与图标垂直居中 4. 更新真实完整文章标题(62篇) - 从book目录读取真实markdown文件名 - 替换之前的简化标题 5. 新增文章数据API - /api/db/chapters - 获取完整书籍结构 - 支持按ID获取单篇文章内容
This commit is contained in:
143
app/api/payment/query/route.ts
Normal file
143
app/api/payment/query/route.ts
Normal file
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* 查询支付状态 API
|
||||
* 基于 Universal_Payment_Module v4.0 设计
|
||||
*
|
||||
* GET /api/payment/query?tradeSn=xxx&gateway=wechat_native|alipay_wap
|
||||
*/
|
||||
|
||||
import { type NextRequest, NextResponse } from "next/server"
|
||||
import { PaymentFactory } from "@/lib/payment"
|
||||
|
||||
// 确保网关已注册
|
||||
import "@/lib/payment/alipay"
|
||||
import "@/lib/payment/wechat"
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const tradeSn = searchParams.get("tradeSn")
|
||||
const gateway = searchParams.get("gateway") // 可选:指定支付网关
|
||||
|
||||
if (!tradeSn) {
|
||||
return NextResponse.json(
|
||||
{ code: 400, message: "缺少交易号", data: null },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
console.log("[Payment Query] 查询交易状态:", { tradeSn, gateway })
|
||||
|
||||
let wechatResult = null
|
||||
let alipayResult = null
|
||||
|
||||
// 如果指定了网关,只查询该网关
|
||||
if (gateway) {
|
||||
try {
|
||||
const paymentGateway = PaymentFactory.create(gateway)
|
||||
const result = await paymentGateway.queryTrade(tradeSn)
|
||||
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
message: "success",
|
||||
data: {
|
||||
tradeSn: result?.tradeSn || tradeSn,
|
||||
status: result?.status || "paying",
|
||||
platformSn: result?.platformSn || null,
|
||||
payAmount: result?.payAmount || null,
|
||||
payTime: result?.payTime || null,
|
||||
gateway,
|
||||
},
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(`[Payment Query] ${gateway} 查询失败:`, e)
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
message: "success",
|
||||
data: {
|
||||
tradeSn,
|
||||
status: "paying",
|
||||
platformSn: null,
|
||||
payAmount: null,
|
||||
payTime: null,
|
||||
gateway,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 没有指定网关时,先查询微信
|
||||
try {
|
||||
const wechatGateway = PaymentFactory.create("wechat_native")
|
||||
wechatResult = await wechatGateway.queryTrade(tradeSn)
|
||||
|
||||
if (wechatResult && wechatResult.status === "paid") {
|
||||
console.log("[Payment Query] 微信支付成功:", { tradeSn, status: wechatResult.status })
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
message: "success",
|
||||
data: {
|
||||
tradeSn: wechatResult.tradeSn,
|
||||
status: wechatResult.status,
|
||||
platformSn: wechatResult.platformSn,
|
||||
payAmount: wechatResult.payAmount,
|
||||
payTime: wechatResult.payTime,
|
||||
gateway: "wechat_native",
|
||||
},
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("[Payment Query] 微信查询异常:", e)
|
||||
}
|
||||
|
||||
// 再查询支付宝
|
||||
try {
|
||||
const alipayGateway = PaymentFactory.create("alipay_wap")
|
||||
alipayResult = await alipayGateway.queryTrade(tradeSn)
|
||||
|
||||
if (alipayResult && alipayResult.status === "paid") {
|
||||
console.log("[Payment Query] 支付宝支付成功:", { tradeSn, status: alipayResult.status })
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
message: "success",
|
||||
data: {
|
||||
tradeSn: alipayResult.tradeSn,
|
||||
status: alipayResult.status,
|
||||
platformSn: alipayResult.platformSn,
|
||||
payAmount: alipayResult.payAmount,
|
||||
payTime: alipayResult.payTime,
|
||||
gateway: "alipay_wap",
|
||||
},
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("[Payment Query] 支付宝查询异常:", e)
|
||||
}
|
||||
|
||||
// 如果都未支付,优先返回微信的状态(因为更可靠)
|
||||
const result = wechatResult || alipayResult
|
||||
|
||||
// 返回等待支付状态
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
message: "success",
|
||||
data: {
|
||||
tradeSn,
|
||||
status: result?.status || "paying",
|
||||
platformSn: result?.platformSn || null,
|
||||
payAmount: result?.payAmount || null,
|
||||
payTime: result?.payTime || null,
|
||||
gateway: null,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("[Payment Query] Error:", error)
|
||||
return NextResponse.json(
|
||||
{
|
||||
code: 500,
|
||||
message: error instanceof Error ? error.message : "服务器错误",
|
||||
data: null,
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user