diff --git a/app/api/cunkebao/route.ts b/app/api/cunkebao/route.ts new file mode 100644 index 0000000..4a8156e --- /dev/null +++ b/app/api/cunkebao/route.ts @@ -0,0 +1,95 @@ +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 = { + 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 }) + } +} diff --git a/app/match/page.tsx b/app/match/page.tsx index aab9d6f..c7b643e 100644 --- a/app/match/page.tsx +++ b/app/match/page.tsx @@ -2,7 +2,7 @@ import { useState } from "react" import { motion, AnimatePresence } from "framer-motion" -import { Mic } from "lucide-react" +import { Mic, X } from "lucide-react" import { Home, List, User } from "lucide-react" import { useRouter } from "next/navigation" @@ -18,18 +18,206 @@ interface MatchUser { } const matchTypes = [ - { id: "partner", label: "创业合伙", icon: "⭐", color: "#00E5FF" }, - { id: "investor", label: "资源对接", icon: "👥", color: "#7B61FF" }, - { id: "mentor", label: "导师顾问", icon: "❤️", color: "#E91E63" }, - { id: "team", label: "团队招募", icon: "🎮", color: "#4CAF50" }, + { id: "team", label: "团队招募", icon: "🎮", color: "#4CAF50", scenario: "team" }, + { id: "resource", label: "资源对接", icon: "👥", color: "#7B61FF", scenario: "resource" }, + { id: "mentor", label: "导师顾问", icon: "❤️", color: "#E91E63", scenario: "mentor" }, ] +interface JoinModalProps { + isOpen: boolean + onClose: () => void + type: (typeof matchTypes)[0] +} + +function JoinModal({ isOpen, onClose, type }: JoinModalProps) { + const [phone, setPhone] = useState("") + const [name, setName] = useState("") + const [remark, setRemark] = useState("") + const [isSubmitting, setIsSubmitting] = useState(false) + const [submitResult, setSubmitResult] = useState<{ success: boolean; message: string } | null>(null) + + const handleSubmit = async () => { + if (!phone) { + setSubmitResult({ success: false, message: "请输入手机号" }) + return + } + + // 简单的手机号验证 + if (!/^1[3-9]\d{9}$/.test(phone)) { + setSubmitResult({ success: false, message: "请输入正确的手机号" }) + return + } + + setIsSubmitting(true) + setSubmitResult(null) + + try { + const response = await fetch("/api/cunkebao", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + phone, + name, + scenario: type.scenario, + remark, + }), + }) + + const result = await response.json() + setSubmitResult(result) + + if (result.success) { + // 成功后清空表单 + setPhone("") + setName("") + setRemark("") + // 3秒后关闭弹窗 + setTimeout(() => { + onClose() + setSubmitResult(null) + }, 3000) + } + } catch (error) { + setSubmitResult({ success: false, message: "网络错误,请稍后重试" }) + } finally { + setIsSubmitting(false) + } + } + + if (!isOpen) return null + + const getTitle = () => { + switch (type.id) { + case "team": + return "加入切片团队" + case "resource": + return "加入资源群" + case "mentor": + return "预约导师顾问" + default: + return "加入" + } + } + + const getDescription = () => { + switch (type.id) { + case "team": + return "加入切片团队,一起创造价值,共享收益" + case "resource": + return "加入资源对接群,链接优质商业资源" + case "mentor": + return "预约一对一导师咨询,获取专业指导" + default: + return "" + } + } + + return ( + + + e.stopPropagation()} + > + {/* 头部 */} +
+ +
+ {type.icon} +

{getTitle()}

+
+

{getDescription()}

+
+ + {/* 表单 */} +
+
+ + setPhone(e.target.value)} + placeholder="请输入手机号" + className="w-full px-4 py-3 rounded-xl bg-black/30 border border-white/10 text-white placeholder-white/30 focus:border-[#00E5FF]/50 focus:outline-none transition-colors" + maxLength={11} + /> +
+ +
+ + setName(e.target.value)} + placeholder="请输入您的姓名" + className="w-full px-4 py-3 rounded-xl bg-black/30 border border-white/10 text-white placeholder-white/30 focus:border-[#00E5FF]/50 focus:outline-none transition-colors" + /> +
+ +
+ +