"use client" import { useState, useEffect } from "react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { Input } from "@/components/ui/input" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Label } from "@/components/ui/label" import { Server, Copy, CheckCircle2, Key, RefreshCw, ExternalLink, Code, Zap, Users, Search, Tags, Brain, Database, FileText, Package, Activity, } from "lucide-react" // API端点接口 interface APIEndpoint { id: string method: 'GET' | 'POST' | 'PUT' | 'DELETE' path: string name: string description: string category: string auth: boolean params?: { name: string; type: string; required: boolean; desc: string }[] response?: string } // API分类 const API_CATEGORIES = [ { id: 'query', name: '用户查询', icon: Search }, { id: 'tag', name: '标签服务', icon: Tags }, { id: 'ai', name: 'AI服务', icon: Brain }, { id: 'data', name: '数据服务', icon: Database }, { id: 'report', name: '报告服务', icon: FileText }, { id: 'package', name: '流量包', icon: Package }, ] // 预定义API端点 const API_ENDPOINTS: APIEndpoint[] = [ // 用户查询 { id: 'api_1', method: 'GET', path: '/api/shensheshou/user', name: '用户画像查询', description: '根据手机号或QQ查询完整用户画像', category: 'query', auth: true, params: [ { name: 'phone', type: 'string', required: false, desc: '11位手机号' }, { name: 'qq', type: 'string', required: false, desc: 'QQ号码' }, ], response: '{ "user": { "phone": "138xxx", "rfm": 85, "level": "A", "tags": [...] } }', }, { id: 'api_2', method: 'POST', path: '/api/shensheshou/users/batch', name: '批量用户查询', description: '批量查询多个用户的画像信息', category: 'query', auth: true, params: [ { name: 'phones', type: 'array', required: false, desc: '手机号数组' }, { name: 'qqs', type: 'array', required: false, desc: 'QQ号数组' }, ], }, // 标签服务 { id: 'api_3', method: 'GET', path: '/api/shensheshou/tags', name: '标签列表', description: '获取所有可用标签', category: 'tag', auth: true, params: [ { name: 'category', type: 'string', required: false, desc: '标签分类' }, ], }, { id: 'api_4', method: 'POST', path: '/api/shensheshou/tags/apply', name: '应用标签', description: '为用户应用指定标签', category: 'tag', auth: true, params: [ { name: 'userId', type: 'string', required: true, desc: '用户ID' }, { name: 'tags', type: 'array', required: true, desc: '标签ID数组' }, ], }, // AI服务 { id: 'api_5', method: 'POST', path: '/api/shensheshou/chat', name: 'AI对话', description: '与神射手AI进行对话,支持自然语言查询', category: 'ai', auth: true, params: [ { name: 'message', type: 'string', required: true, desc: '对话内容' }, ], response: '{ "success": true, "response": { "content": "查询结果...", "data": {...} } }', }, { id: 'api_6', method: 'POST', path: '/api/shensheshou/ai/analyze', name: 'AI数据分析', description: 'AI自动分析数据并生成洞察', category: 'ai', auth: true, params: [ { name: 'type', type: 'string', required: true, desc: '分析类型: rfm/behavior/preference' }, { name: 'filters', type: 'object', required: false, desc: '筛选条件' }, ], }, { id: 'api_7', method: 'POST', path: '/api/shensheshou/ai/tag', name: 'AI智能打标', description: 'AI自动为用户打标签', category: 'ai', auth: true, params: [ { name: 'source', type: 'string', required: true, desc: '数据源' }, { name: 'model', type: 'string', required: false, desc: 'AI模型: qwen/deepseek' }, ], }, // 数据服务 { id: 'api_8', method: 'GET', path: '/api/shensheshou/sources', name: '数据源列表', description: '获取所有数据源连接状态', category: 'data', auth: true, }, { id: 'api_9', method: 'POST', path: '/api/shensheshou/ingest', name: '数据导入', description: '导入外部数据并通过AI标签引擎处理', category: 'data', auth: true, params: [ { name: 'source', type: 'string', required: true, desc: '数据源标识' }, { name: 'target', type: 'string', required: true, desc: '目标表' }, ], }, // 报告服务 { id: 'api_10', method: 'POST', path: '/api/shensheshou/report/generate', name: '生成报告', description: 'AI自动生成数据分析报告', category: 'report', auth: true, params: [ { name: 'template', type: 'string', required: true, desc: '报告模板ID' }, { name: 'dateRange', type: 'string', required: false, desc: '日期范围' }, ], }, // 流量包 { id: 'api_11', method: 'GET', path: '/api/shensheshou/packages', name: '流量包列表', description: '获取所有流量包', category: 'package', auth: true, }, { id: 'api_12', method: 'POST', path: '/api/shensheshou/packages/create', name: '创建流量包', description: '根据筛选条件创建流量包', category: 'package', auth: true, params: [ { name: 'name', type: 'string', required: true, desc: '流量包名称' }, { name: 'criteria', type: 'object', required: true, desc: '筛选条件' }, ], }, { id: 'api_13', method: 'POST', path: '/api/shensheshou/packages/send', name: '发送流量包', description: '发送流量包到邮箱/飞书/微信', category: 'package', auth: true, params: [ { name: 'packageId', type: 'string', required: true, desc: '流量包ID' }, { name: 'targets', type: 'array', required: true, desc: '发送目标' }, ], }, ] export default function APIServicePage() { const [activeCategory, setActiveCategory] = useState('all') const [apiBaseUrl, setApiBaseUrl] = useState('') const [showKeyDialog, setShowKeyDialog] = useState(false) const [copiedId, setCopiedId] = useState(null) useEffect(() => { const host = typeof window !== 'undefined' ? window.location.origin : '' setApiBaseUrl(host) }, []) const copyToClipboard = (text: string, id: string) => { navigator.clipboard.writeText(text) setCopiedId(id) setTimeout(() => setCopiedId(null), 2000) } const getMethodColor = (method: string) => { switch (method) { case 'GET': return 'bg-green-100 text-green-700' case 'POST': return 'bg-blue-100 text-blue-700' case 'PUT': return 'bg-yellow-100 text-yellow-700' case 'DELETE': return 'bg-red-100 text-red-700' default: return 'bg-gray-100 text-gray-700' } } const filteredEndpoints = activeCategory === 'all' ? API_ENDPOINTS : API_ENDPOINTS.filter(e => e.category === activeCategory) return (
{/* 顶部标题 */}

API服务

神射手开放API,支持第三方系统集成

{/* API基础信息 */}

API基础地址

{apiBaseUrl || 'https://your-domain.com'}
API版本
v1.0
{/* 认证说明 */} 认证方式

所有API请求需要在Header中携带API密钥:

{`curl -X GET "${apiBaseUrl}/api/shensheshou/user?phone=13800138000" \\
  -H "Authorization: Bearer YOUR_API_KEY" \\
  -H "Content-Type: application/json"`}
              
{/* API分类筛选 */}
{API_CATEGORIES.map(cat => { const count = API_ENDPOINTS.filter(e => e.category === cat.id).length const Icon = cat.icon return ( ) })}
{/* API端点列表 */}
{filteredEndpoints.map(endpoint => (
{endpoint.method} {endpoint.path}
{endpoint.auth && ( 需认证 )}

{endpoint.name}

{endpoint.description}

{/* 参数 */} {endpoint.params && endpoint.params.length > 0 && (

参数

{endpoint.params.map((param, i) => (
{param.name} {param.type} {param.required && 必填} {param.desc}
))}
)} {/* 响应示例 */} {endpoint.response && (

响应示例

                      {endpoint.response}
                    
)}
))}
{/* API密钥弹窗 */} API密钥管理 用于第三方系统调用神射手API

密钥创建于 2024-01-15,永不过期

⚠️ 请妥善保管API密钥,不要在客户端代码中暴露
) }