feat: implement CKB API integration

Add CKB API routes and update match page for joining features

#VERCEL_SKIP

Co-authored-by: null <4804959+fnvtk@users.noreply.github.com>
This commit is contained in:
v0
2026-01-14 07:50:53 +00:00
parent e7008a8ed8
commit b487855d44
3 changed files with 291 additions and 299 deletions

86
app/api/ckb/join/route.ts Normal file
View File

@@ -0,0 +1,86 @@
import { type NextRequest, NextResponse } from "next/server"
import crypto from "crypto"
// 存客宝API配置
const CKB_API_KEY = "fyngh-ecy9h-qkdae-epwd5-rz6kd"
const CKB_API_URL = "https://ckbapi.quwanzhi.com/v1/api/scenarios"
// 生成签名
function generateSign(apiKey: string, timestamp: number): string {
const signStr = `${apiKey}${timestamp}`
return crypto.createHash("md5").update(signStr).digest("hex")
}
// 不同类型对应的source标签
const sourceMap: Record<string, string> = {
team: "团队招募",
investor: "资源对接",
mentor: "导师顾问",
}
const tagsMap: Record<string, string> = {
team: "切片团队,团队招募",
investor: "资源对接,资源群",
mentor: "导师顾问,咨询服务",
}
export async function POST(request: NextRequest) {
try {
const body = await request.json()
const { type, phone, name, wechatId, remark } = body
// 验证必填参数
if (!type || !phone) {
return NextResponse.json({ success: false, message: "缺少必填参数" }, { status: 400 })
}
// 验证类型
if (!["team", "investor", "mentor"].includes(type)) {
return NextResponse.json({ success: false, message: "无效的加入类型" }, { status: 400 })
}
// 生成时间戳和签名
const timestamp = Math.floor(Date.now() / 1000)
const sign = generateSign(CKB_API_KEY, timestamp)
// 构建请求参数
const requestBody = {
apiKey: CKB_API_KEY,
sign,
timestamp,
phone,
name: name || "",
wechatId: wechatId || "",
source: sourceMap[type],
remark: remark || `来自创业实验APP-${sourceMap[type]}`,
tags: tagsMap[type],
}
// 调用存客宝API
const response = await fetch(CKB_API_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(requestBody),
})
const result = await response.json()
if (response.ok && result.code === 0) {
return NextResponse.json({
success: true,
message: `成功加入${sourceMap[type]}`,
data: result.data,
})
} else {
return NextResponse.json({
success: false,
message: result.message || "加入失败,请稍后重试",
})
}
} catch (error) {
console.error("存客宝API调用失败:", error)
return NextResponse.json({ success: false, message: "服务器错误,请稍后重试" }, { status: 500 })
}
}

View File

@@ -1,95 +0,0 @@
import { type NextRequest, NextResponse } from "next/server"
import crypto from "crypto"
// 存客宝API配置
const CKB_CONFIG = {
apiKey: "fyngh-ecy9h-qkdae-epwd5-rz6kd",
apiUrl: "https://ckbapi.quwanzhi.com/v1/api/scenarios",
}
// 生成签名
function generateSign(apiKey: string, timestamp: number): string {
const signStr = `${apiKey}${timestamp}`
return crypto.createHash("md5").update(signStr).digest("hex")
}
// 不同场景的source和tags配置
const SCENARIO_CONFIG: Record<string, { source: string; tags: string }> = {
team: {
source: "卡若创业实验-切片团队招募",
tags: "切片团队,团队招募,创业合作",
},
resource: {
source: "卡若创业实验-资源对接",
tags: "资源对接,资源群,商业合作",
},
mentor: {
source: "卡若创业实验-导师顾问",
tags: "导师顾问,创业指导,商业咨询",
},
}
export async function POST(request: NextRequest) {
try {
const body = await request.json()
const { phone, name, scenario, remark } = body
// 验证必填参数
if (!phone) {
return NextResponse.json({ success: false, message: "手机号不能为空" }, { status: 400 })
}
if (!scenario || !SCENARIO_CONFIG[scenario]) {
return NextResponse.json({ success: false, message: "无效的场景类型" }, { status: 400 })
}
// 生成时间戳和签名
const timestamp = Math.floor(Date.now() / 1000)
const sign = generateSign(CKB_CONFIG.apiKey, timestamp)
// 获取场景配置
const config = SCENARIO_CONFIG[scenario]
// 构建请求体
const requestBody = {
apiKey: CKB_CONFIG.apiKey,
sign,
timestamp,
phone,
name: name || "",
source: config.source,
remark: remark || `来自${config.source}`,
tags: config.tags,
}
// 调用存客宝API
const response = await fetch(CKB_CONFIG.apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(requestBody),
})
const result = await response.json()
if (response.ok && result.code === 0) {
return NextResponse.json({
success: true,
message: "提交成功,我们会尽快与您联系",
data: result.data,
})
} else {
return NextResponse.json(
{
success: false,
message: result.message || "提交失败,请稍后重试",
},
{ status: 400 },
)
}
} catch (error) {
console.error("存客宝API调用失败:", error)
return NextResponse.json({ success: false, message: "服务器错误,请稍后重试" }, { status: 500 })
}
}