soga-client-v1 API 文件
介紹
soga-client-v1 是 soga 客戶端使用的一系列使用者端介面,面板按以下文件實作後,客戶端即可登入、查看訂閱、購買套餐、提交工單等。
base_url 設定
可自訂路徑,客戶端存取介面時自動拼接 base_url 與介面 uri,例如 https://www.website.com/your/custom/uri/api/v1/me
base_url=https://www.website.com/your/custom/uri/通用約定
所有介面均使用 json 格式傳遞資料,GET 介面的參數放在 query 中
每個請求均會帶上以下請求標頭
| Key | 說明 |
|---|---|
| Authorization | Bearer <access_token>,登入後的介面必須攜帶,access_token 由登入、註冊介面回傳 |
| Accept-Language | 客戶端語言,如 zh-CN en-US,面板按此語言回傳提示文字 |
| User-Agent | 客戶端名稱和版本,如 soga-client/1.2.0 (windows) |
HTTP 狀態碼正常為 200,請求是否成功以回傳資料中的 success 為準
成功時 success 為 true,回傳資料放在 data 中
{
"success": true,
"data": {}
}列表分頁的介面,請求參數為 page(從 1 開始,預設 1)和 page_size(預設 20,最大 100),回傳資料多一個 pagination
{
"success": true,
"data": [],
"pagination": {
"page": 1,
"page_size": 20,
"total": 57 // 總筆數
}
}失敗時 success 為 false,錯誤訊息放在 error 中
{
"success": false,
"error": {
"message": "信箱或密碼錯誤" // 直接顯示給使用者的提示文字
}
}以下錯誤需要客戶端做特殊處理,需在 error 中帶上 code
{
"success": false,
"error": {
"code": 1001,
"message": "登入已過期,請重新登入"
}
}| 錯誤碼 | 說明 |
|---|---|
| 1001 | 未登入或登入已過期,客戶端會清除登入狀態並回到登入頁 |
其他錯誤只需回傳 message,客戶端直接顯示
客戶端同時識別常見的 HTTP 狀態碼,面板也可以直接回傳這些狀態碼
| HTTP 狀態碼 | 客戶端處理 |
|---|---|
| 200 | 按 success 判斷 |
| 401 | 同錯誤碼 1001,清除登入狀態並回到登入頁 |
| 403 | 提示無權存取 |
| 404 | 提示面板不支援該功能 |
| 429 | 提示請求過於頻繁 |
| 500 502 503 504 | 提示伺服器錯誤,請稍後重試 |
非 200 時,如果回傳資料是 json 且帶有 error.message,優先顯示 error.message
資料格式約定
- 時間統一為 Unix 時間戳記,單位秒
- 金額統一為整數,單位分
- 流量統一為整數,單位位元組
- 布林值統一為
true/false - 值不存在時回傳
null,列表為空時回傳[]
只回傳成功、沒有資料的介面回傳
{
"success": true
}公共介面
以下介面不需要登入
取得站點設定 GET <base_url>/api/v1/config
回傳資料
{
"success": true,
"data": {
"site_name": "Example",
"site_url": "https://www.website.com", // 網頁面板位址
"tos_url": "https://www.website.com/tos", // 服務條款,可為 null
"currency": "CNY", // 貨幣代碼
"currency_symbol": "¥", // 貨幣符號
"register": {
"enabled": true, // 開放註冊
"email_verify": true, // 註冊需要信箱驗證碼
"invite_required": false, // 註冊必須填寫邀請碼
"email_whitelist": ["gmail.com", "qq.com"] // 允許註冊的信箱後綴,[] 表示不限制
},
"telegram": {
"enabled": true, // 啟用 Telegram 機器人
"bot_username": "example_bot", // 機器人使用者名稱,不含 @
"discuss_url": "https://t.me/example_group" // 交流群組,可為 null
},
"commission": {
"withdraw_enabled": true, // 開放佣金提現
"withdraw_methods": ["支付寶", "USDT"], // 提現方式
"withdraw_minimum": 10000, // 最低提現金額
"distribution_enabled": false, // 開啟三級分銷
"distribution_rates": [50, 30, 20] // 一至三級分銷比例,百分比
},
"features": { // 功能開關,缺少的項視為 false
"deposit": true, // 餘額儲值
"gift_card": true, // 禮品卡兌換
"gift_card_preview": true, // 禮品卡兌換前預覽、兌換記錄
"telegram_unbind": true, // 解除綁定 Telegram
"new_period": true, // 流量用盡後提前開啟新週期
"sessions": true // 查看、移除登入裝置
}
}
}取得套餐列表 GET <base_url>/api/v1/plans
回傳可購買的套餐。帶 Authorization 請求時,目前訂閱的套餐即使已下架,只要允許續費也會回傳
回傳資料
{
"success": true,
"data": [
{
"id": 1,
"name": "年付套餐",
"content": "<p>100G 流量</p>", // 套餐說明,HTML,可為 null
"transfer_enable": 107374182400, // 每週期流量,位元組
"device_limit": 3, // 裝置數限制,null 表示不限制
"speed_limit": null, // 限速 Mbps,null 表示不限制
"sold_out": false, // 名額已滿,不可新購
"prices": [ // 可購買的週期及價格,未開放的週期不回傳
{ "period": "month", "amount": 1500 },
{ "period": "year", "amount": 15000 },
{ "period": "reset_traffic", "amount": 500 }
]
}
]
}period 可選值: month quarter half_year year two_year three_year onetime reset_traffic(流量重置包)
取得套餐詳情 GET <base_url>/api/v1/plan
請求參數
id=1回傳資料
{
"success": true,
"data": {
// 同套餐列表中的一項
}
}取得客戶端版本 GET <base_url>/api/v1/app/version
回傳資料
{
"success": true,
"data": {
"windows": { // 未設定的平台為 null
"version": "1.4.0", // 最新版本
"download_url": "https://www.website.com/app.exe"
},
"macos": null,
"android": {
"version": "1.4.0",
"download_url": "https://www.website.com/app.apk"
}
}
}登入註冊
傳送信箱驗證碼 POST <base_url>/api/v1/auth/email_code
提交資料
{
"email": "[email protected]",
"scene": "register" // 可選: register 註冊,reset_password 重置密碼
}回傳資料
{
"success": true
}註冊 POST <base_url>/api/v1/auth/register
提交資料
{
"email": "[email protected]",
"password": "password",
"email_code": "123456", // 可省略,站點開啟信箱驗證時必填
"invite_code": "abcd" // 可省略,站點要求邀請碼時必填
}回傳資料
{
"success": true,
"data": {
"access_token": "xxxxxxxx", // 登入憑證,之後的請求放在 Authorization: Bearer <access_token>
"expires_at": 1796112000, // 憑證過期時間
"is_admin": false
}
}登入 POST <base_url>/api/v1/auth/login
提交資料
{
"email": "[email protected]",
"password": "password"
}回傳資料
{
"success": true,
"data": {
"access_token": "xxxxxxxx",
"expires_at": 1796112000,
"is_admin": false
}
}重置密碼 POST <base_url>/api/v1/auth/reset_password
重置成功後該帳戶所有登入裝置都需要重新登入
提交資料
{
"email": "[email protected]",
"email_code": "123456",
"password": "new_password"
}回傳資料
{
"success": true
}登出 POST <base_url>/api/v1/auth/logout
使目前 access_token 失效
回傳資料
{
"success": true
}帳戶
以下介面都需要登入
取得使用者資訊 GET <base_url>/api/v1/me
回傳資料
{
"success": true,
"data": {
"email": "[email protected]",
"avatar_url": "https://www.website.com/avatar.png", // 可為 null
"balance": 1000, // 餘額
"commission_balance": 500, // 可用佣金
"discount": 90, // 專屬折扣百分比,null 表示無
"commission_rate": 10, // 專屬佣金比例百分比,null 表示使用站點預設
"remind_expire": true, // 到期提醒
"remind_traffic": true, // 流量提醒
"telegram_id": 123456, // 已綁定的 Telegram id,未綁定為 null
"created_at": 1700000000,
"last_login_at": 1764547200
}
}修改提醒設定 POST <base_url>/api/v1/me/update
提交資料
{
"remind_expire": true, // 可省略,省略表示不修改
"remind_traffic": false // 可省略,省略表示不修改
}回傳資料
{
"success": true
}取得待處理數量 GET <base_url>/api/v1/me/stat
回傳資料
{
"success": true,
"data": {
"pending_orders": 1, // 待支付訂單數
"open_tickets": 0, // 未關閉工單數
"invited_users": 5 // 已邀請使用者數
}
}修改密碼 POST <base_url>/api/v1/me/change_password
修改成功後其他登入裝置需要重新登入
提交資料
{
"old_password": "password",
"new_password": "new_password"
}回傳資料
{
"success": true
}取得網頁免登入連結 POST <base_url>/api/v1/me/web_login_url
提交資料
{
"redirect": "plan" // 可省略,登入後跳轉的網頁面板路徑,預設首頁
}回傳資料
{
"success": true,
"data": {
"url": "https://www.website.com/#/login?verify=xxxx", // 一次性連結,60 秒內有效
"expires_at": 1764547260
}
}取得登入裝置 GET <base_url>/api/v1/me/sessions
回傳資料
{
"success": true,
"data": [
{
"id": "a1b2c3", // 工作階段 id
"ip": "1.2.3.4", // 可為 null
"user_agent": "soga-client/1.2.0 (windows)", // 可為 null
"login_at": 1764547200,
"last_used_at": 1764550800, // 可為 null
"is_current": true // 是目前裝置
}
]
}移除登入裝置 POST <base_url>/api/v1/me/session/remove
提交資料
{
"id": "a1b2c3"
}回傳資料
{
"success": true
}解除綁定 Telegram POST <base_url>/api/v1/me/telegram/unbind
回傳資料
{
"success": true
}訂閱
以下介面都需要登入
取得訂閱資訊 GET <base_url>/api/v1/subscription
回傳資料
{
"success": true,
"data": {
"plan": { // 目前套餐,未購買為 null
"id": 1,
"name": "年付套餐"
},
"upload": 1073741824, // 本週期已用上傳流量,位元組
"download": 5368709120, // 本週期已用下載流量,位元組
"transfer_enable": 107374182400, // 流量額度,位元組
"expired_at": 1811808000, // 到期時間,null 表示長期有效
"is_expired": false, // 已過期或從未購買
"next_reset_at": 1767225600, // 下次流量重置時間,null 表示不重置
"device_limit": 3, // 裝置數限制,null 表示不限制
"speed_limit": null, // 限速 Mbps,null 表示不限制
"alive_ip": 1, // 目前線上裝置數,可為 null
"subscribe_url": "https://sub.website.com/s/xxxx",
"can_new_period": false // 可以提前開啟新週期
}
}重置訂閱位址 POST <base_url>/api/v1/subscription/reset
重置訂閱位址和節點認證資訊,舊訂閱位址立即失效
回傳資料
{
"success": true,
"data": {
"subscribe_url": "https://sub.website.com/s/yyyy" // 新的訂閱位址
}
}提前開啟新週期 POST <base_url>/api/v1/subscription/new_period
流量用盡時歸零已用流量,到期時間提前一個流量重置週期,僅 can_new_period 為 true 時可用
回傳資料
{
"success": true
}取得訂閱內容 GET <subscribe_url>
供其他客戶端匯入使用,不需要 Authorization;soga 客戶端透過 /servers 取得節點,不請求訂閱位址
請求參數
flag=sing-box/1.12.0 // 設定格式,可選: general clash-meta sing-box,sing-box 可帶核心版本回傳資料
對應格式的設定文字,回應標頭需帶上
subscription-userinfo: upload=1073741824; download=5368709120; total=107374182400; expire=1811808000訂閱不可用(未購買、已過期、已封禁)時回傳
{
"success": false,
"error": {
"message": "訂閱已過期"
}
}取得流量記錄 GET <base_url>/api/v1/traffic_logs
回傳本月每天的流量記錄,按日期倒序
回傳資料
{
"success": true,
"data": [
{
"record_at": 1764547200, // 當天 0 點
"upload": 10485760, // 上傳流量,位元組
"download": 524288000, // 下載流量,位元組
"rate": 1.5 // 節點倍率,計入額度的流量 = (upload + download) × rate
}
]
}取得節點設定 GET <base_url>/api/v1/servers
回傳節點的連線設定和分流規則,見 soga-client-v1 節點介面文件
訂單
以下介面都需要登入
購買流程: 取得套餐列表 → 建立訂單 → 支付訂單 → 輪詢訂單詳情直到狀態不是 pending processing
驗證優惠券 POST <base_url>/api/v1/coupon/check
提交資料
{
"code": "NEWUSER",
"plan_id": 1,
"period": "year"
}回傳資料
{
"success": true,
"data": {
"name": "新使用者九折",
"type": "percent", // 可選: amount 減免金額,percent 減免百分比
"value": 10 // type 為 amount 時是金額,percent 時是百分比
}
}建立訂單 POST <base_url>/api/v1/order/create
提交資料
{
"plan_id": 1,
"period": "year",
"coupon_code": "NEWUSER" // 可省略
}回傳資料
{
"success": true,
"data": {
"trade_no": "2026120108300012345" // 訂單編號
}
}建立儲值訂單 POST <base_url>/api/v1/order/deposit
features.deposit 為 true 時可用
提交資料
{
"amount": 10000 // 儲值金額
}回傳資料
{
"success": true,
"data": {
"trade_no": "2026120108300012346"
}
}取得訂單列表 GET <base_url>/api/v1/orders
請求參數
status=pending // 可省略,可選: pending processing completed cancelled
page=1
page_size=20回傳資料
{
"success": true,
"data": [
// 同訂單詳情
],
"pagination": {
"page": 1,
"page_size": 20,
"total": 3
}
}取得訂單詳情 GET <base_url>/api/v1/order
請求參數
trade_no=2026120108300012345回傳資料
{
"success": true,
"data": {
"trade_no": "2026120108300012345",
"plan": { // 儲值訂單為 null
"id": 1,
"name": "年付套餐"
},
"period": "year", // 儲值訂單為 null
"status": "pending", // 可選: pending 待支付,processing 開通中,completed 已完成,cancelled 已取消,discounted 已折抵
"total_amount": 13500, // 應付金額
"discount_amount": 1500, // 優惠金額
"surplus_amount": 0, // 舊訂閱折抵金額
"balance_amount": 0, // 餘額抵扣金額
"handling_amount": 0, // 支付手續費
"created_at": 1764547200,
"paid_at": null
}
}取消訂單 POST <base_url>/api/v1/order/cancel
提交資料
{
"trade_no": "2026120108300012345"
}回傳資料
{
"success": true
}取得支付方式 GET <base_url>/api/v1/payment_methods
回傳資料
{
"success": true,
"data": [
{
"id": 1,
"name": "支付寶",
"icon": "https://www.website.com/alipay.png", // 可為 null
"handling_fee_fixed": 0, // 固定手續費
"handling_fee_percent": 0, // 百分比手續費
"stripe_public_key": null // Stripe 信用卡支付時的公鑰,其他支付方式為 null
}
]
}支付訂單 POST <base_url>/api/v1/order/checkout
提交資料
{
"trade_no": "2026120108300012345",
"method": 1, // 支付方式 id,應付金額為 0 時可省略
"stripe_token": "tok_xxx" // 可省略,Stripe 信用卡支付時必填
}回傳資料
{
"success": true,
"data": {
"type": "redirect", // 可選: paid 已支付無需跳轉,qrcode 顯示 QR Code,redirect 開啟連結
"url": "https://pay.website.com/xxxx" // type 為 paid 時為 null
}
}禮品卡
以下介面都需要登入
預覽禮品卡 POST <base_url>/api/v1/gift_card/check
features.gift_card_preview 為 true 時可用
提交資料
{
"code": "GIFT-XXXX-XXXX"
}回傳資料
{
"success": true,
"data": {
"name": "30 天體驗卡",
"description": "贈送 30 天有效期", // 可為 null
"can_redeem": true, // 目前帳戶能否兌換
"reason": null, // 不能兌換的原因
"balance": null, // 獎勵餘額
"transfer_enable": null, // 獎勵流量,位元組
"expire_days": 30, // 延長有效期天數
"device_limit": null, // 增加裝置數
"plan_name": null, // 開通的套餐名稱
"plan_days": null, // 開通套餐的天數
"reset_traffic": false // 歸零已用流量
}
}兌換禮品卡 POST <base_url>/api/v1/gift_card/redeem
提交資料
{
"code": "GIFT-XXXX-XXXX"
}回傳資料
{
"success": true
}取得兌換記錄 GET <base_url>/api/v1/gift_card/history
features.gift_card_preview 為 true 時可用
回傳資料
{
"success": true,
"data": [
{
"id": 1,
"code": "GIFT-****-XXXX", // 部分遮蔽的兌換碼
"name": "30 天體驗卡",
"created_at": 1764547200
}
]
}邀請
以下介面都需要登入
取得邀請資訊 GET <base_url>/api/v1/invite
回傳資料
{
"success": true,
"data": {
"codes": [ // 未使用的邀請碼
{
"code": "abcd",
"pv": 12, // 造訪次數
"created_at": 1764547200
}
],
"invited_users": 5, // 已邀請使用者數
"commission_rate": 10, // 佣金比例,百分比
"total_commission": 3000, // 累計獲得佣金
"pending_commission": 500, // 確認中佣金
"available_commission": 2500 // 可用佣金
}
}產生邀請碼 POST <base_url>/api/v1/invite/create
回傳資料
{
"success": true
}取得佣金記錄 GET <base_url>/api/v1/invite/commissions
請求參數
page=1
page_size=20回傳資料
{
"success": true,
"data": [
{
"id": 1,
"trade_no": "2026120108300012345",
"order_amount": 15000, // 訂單金額
"get_amount": 1500, // 獲得的佣金
"created_at": 1764547200
}
],
"pagination": {
"page": 1,
"page_size": 20,
"total": 1
}
}佣金轉入餘額 POST <base_url>/api/v1/invite/transfer
提交資料
{
"amount": 1000 // 轉入金額
}回傳資料
{
"success": true
}申請提現 POST <base_url>/api/v1/invite/withdraw
提現全部可用佣金,面板會產生一個工單人工處理
提交資料
{
"method": "支付寶", // 取自站點設定 commission.withdraw_methods
"account": "[email protected]" // 收款帳號
}回傳資料
{
"success": true
}公告與知識庫
以下介面都需要登入
取得公告 GET <base_url>/api/v1/notices
請求參數
page=1
page_size=20回傳資料
{
"success": true,
"data": [
{
"id": 1,
"title": "系統維護通知",
"content": "<p>今晚 22 點維護</p>", // HTML
"img_url": null,
"created_at": 1764547200
}
],
"pagination": {
"page": 1,
"page_size": 20,
"total": 1
}
}取得知識庫 GET <base_url>/api/v1/knowledge
回傳目前語言的文章目錄,按分類分組,不含內文
請求參數
keyword=windows // 可省略,按標題和內文搜尋回傳資料
{
"success": true,
"data": [
{
"category": "使用教學",
"articles": [
{
"id": 1,
"title": "Windows 使用教學",
"updated_at": 1764547200
}
]
}
]
}取得知識庫文章 GET <base_url>/api/v1/knowledge/article
請求參數
id=1回傳資料
{
"success": true,
"data": {
"id": 1,
"category": "使用教學",
"title": "Windows 使用教學",
"body": "<p>下載客戶端後……</p>", // HTML
"updated_at": 1764547200
}
}工單
以下介面都需要登入
取得工單列表 GET <base_url>/api/v1/tickets
請求參數
page=1
page_size=20回傳資料
{
"success": true,
"data": [
{
"id": 1,
"subject": "無法連線",
"level": 1, // 0 低,1 中,2 高
"is_closed": false,
"is_replied": true, // 客服已回覆
"created_at": 1764547200,
"updated_at": 1764550800
}
],
"pagination": {
"page": 1,
"page_size": 20,
"total": 1
}
}取得工單詳情 GET <base_url>/api/v1/ticket
請求參數
id=1回傳資料
{
"success": true,
"data": {
"id": 1,
"subject": "無法連線",
"level": 1,
"is_closed": false,
"is_replied": true,
"created_at": 1764547200,
"updated_at": 1764550800,
"messages": [ // 按時間正序
{
"id": 1,
"is_me": true, // true 為使用者傳送,false 為客服傳送
"message": "所有節點都連不上",
"created_at": 1764547200
},
{
"id": 2,
"is_me": false,
"message": "請更新訂閱後重試",
"created_at": 1764550800
}
]
}
}建立工單 POST <base_url>/api/v1/ticket/create
提交資料
{
"subject": "無法連線",
"level": 1, // 0 低,1 中,2 高
"message": "所有節點都連不上"
}回傳資料
{
"success": true,
"data": {
"id": 1 // 工單 id
}
}回覆工單 POST <base_url>/api/v1/ticket/reply
提交資料
{
"id": 1,
"message": "已經更新,還是不行"
}回傳資料
{
"success": true
}關閉工單 POST <base_url>/api/v1/ticket/close
提交資料
{
"id": 1
}回傳資料
{
"success": true
}