import { del, get, post, put } from './request' import type { Paged } from './account' /** 上家(通道方)。 */ export interface Upstream { id: number name: string contact: string phone: string category: string status: number remark: string created_at: string } /** 通道。 */ export interface Channel { id: number name: string code: string protocol: 'cmpp' | 'http' | 'sgip' | 'smpp' upstream_id: number upstream_name?: string host: string port: number username: string password?: string speed: number conn_count: number status: number is_default: number priority: number weight: number day_limit: number night_limit: number sign_mode: number ext_length: number black_keywords: string block_regions: string template_mode: number remark: string created_at: string // ---- Day 31 扩展:协议接入参数 ---- sp_id?: string // 企业代码(CMPP SourceAddr ≤6B/SGIP CorpID) protocol_version?: number // cmpp:20|30 sgip:12 smpp:34 heartbeat_interval?: number // 心跳周期(秒) reconnect_max?: number // 重连退避上限(秒) service_id?: string // 服务代码 // ---- Day 31 扩展:运营属性 ---- carrier?: string // 运营商逗号分隔 cmcc,cucc,ctcc billing_length?: number // 计费长度(字/条) payment_type?: string // prepay_monthly/postpaid_monthly/prepay_realtime billing_mode?: string // success_unknown/success/all price?: number // 元/条 category?: string mo_forward_channel_id?: number // 上行组合通道(0=不转发) number_rule?: number // 0~3 code_truncate?: number // 通道号截断位数 ext_params?: string service_remark?: string } /** 通道组成员(四步路由)。 */ export interface GroupItem { id: number group_id: number channel_id: number channel_name?: string step: 1 | 2 | 3 | 4 // 1条件过滤 2优先 3权重 4兜底 priority: number weight: number region: string carrier: string keyword: string } /** 通道组。 */ export interface ChannelGroup { id: number name: string remark: string status: number items?: GroupItem[] created_at: string } export const PROTOCOLS = [ { value: 'cmpp', label: 'CMPP' }, { value: 'http', label: 'HTTP' }, { value: 'sgip', label: 'SGIP' }, { value: 'smpp', label: 'SMPP' }, ] as const export const ROUTE_STEPS = [ { value: 1, label: '条件过滤', desc: '黑白名单/关键字/签名/地区/频次' }, { value: 2, label: '优先通道', desc: '省网分流/关键字命中走优先通道' }, { value: 3, label: '权重分发', desc: '按权重比例随机分发' }, { value: 4, label: '默认兜底', desc: '以上均未命中时的兜底通道' }, ] as const /** 常驻链路状态(Day 39)。 */ export interface LinkStatus { channel_id: number running: boolean total: number healthy: number started_at?: string } /** 回执/上行(Day 39;is_report=true 为状态报告 stat,false 为上行短信)。 */ export interface Receipt { channel_id: number msg_id: string is_report: boolean stat?: string submit_time?: string done_time?: string dest?: string src?: string content?: string at: string } /** 通道分时成本价时间线(Issue#5·P0-A 封装 Day38 端点;出账成本唯一事实源)。 */ export interface ChannelPriceEntry { id: number channel_id: number price: number effective_at: string created_at?: string } /** 通道实时快照(Day 40:/channels/monitor,与 WS 帧同构;60s 窗口均值)。 */ export interface ChannelSnapshot { channel_id: number name: string protocol: string status: number running: boolean total: number healthy: number submit_ps: number deliver_ps: number fail_rate: number latency_p50_ms: number updated_at: string } export const channelApi = { // ---- 实时监控(Day 40:HTTP 快照,与 /channels/monitor/ws 帧同构) ---- monitor: () => get('/channels/monitor'), // ---- 上家 ---- upstreamList: (q?: { page: number; page_size: number; name?: string }) => get>('/channels/upstreams', q as Record), upstreamCreate: (body: Partial) => post('/channels/upstreams', body), upstreamUpdate: (id: number, body: Partial) => put(`/channels/upstreams/${id}`, body), upstreamRemove: (id: number) => del<{ id: number }>(`/channels/upstreams/${id}`), // ---- 通道 ---- list: (q: Record) => get>('/channels', q), get: (id: number) => get(`/channels/${id}`), create: (body: Partial) => post('/channels', body), update: (id: number, body: Partial) => put(`/channels/${id}`, body), remove: (id: number) => del<{ id: number }>(`/channels/${id}`), test: (id: number, body: { mobile: string; content: string }) => post<{ message_id: string; protocol: string; elapsed_ms: number; ok?: boolean; latency_ms?: number; message?: string }>( `/channels/${id}/test`, body, ), // ---- Day 39:链路状态/回执复核 ---- linkStatus: (id: number) => get(`/channels/${id}/link-status`), linkReceipts: (id: number, limit = 50) => get<{ channel_id: number; total: number; list: Receipt[] }>(`/channels/${id}/receipts`, { limit }), // ---- Issue#5·P0-A:分时成本价时间线(Day38 端点 FE 封装,出账成本事实源) ---- priceList: (id: number) => get>(`/channels/${id}/prices`), priceSet: (id: number, body: { price: number; effective_at?: string }) => post(`/channels/${id}/prices`, body), priceRemove: (id: number, priceId: number) => del<{ id: number; price_id: number; deleted: boolean }>(`/channels/${id}/prices/${priceId}`), // ---- 通道组(四步路由) ---- groupList: () => get>('/channel-groups'), groupCreate: (body: { name: string; remark?: string }) => post('/channel-groups', body), groupRemove: (id: number) => del<{ id: number }>(`/channel-groups/${id}`), groupItems: (groupId: number) => get>(`/channel-groups/${groupId}/items`), groupItemAdd: (groupId: number, body: Partial) => post(`/channel-groups/${groupId}/items`, body), groupItemUpdate: (groupId: number, itemId: number, body: Partial) => put(`/channel-groups/${groupId}/items/${itemId}`, body), groupItemRemove: (groupId: number, itemId: number) => del<{ id: number }>(`/channel-groups/${groupId}/items/${itemId}`), }