Skip to content

客服套件-DDClient(開發文檔)

最後更新:2026-04-10

📖 功能說明請參考 客服套件-DDClient


架構

相關檔案

核心配置(9 個)
檔案說明
.../Config/DDConfigManager.swift初始化入口、域名管理
.../Config/DDCommonConstant.swift常量定義
.../Config/DDPathConfig.swift本地檔案路徑
.../Config/NetworkingConfig.swift網路狀態持久化
.../Config/DDNotificationCommon.swift通知名稱
.../Config/DDMessageLostManager.swift消息補齊
.../Config/DDColorStyle.swift顏色樣式
.../Config/DDFontConfig.swift字體配置
.../Config/IFDefine.swift螢幕常量

基礎路徑:DDClientComponent/Classes/Other/

域名管理(2 個)
檔案說明
.../Domain/ClientDomainManager.swift環境域名管理
.../Domain/DomainModel.swift域名模型

基礎路徑:DDClientComponent/Classes/Other/

聊天 Controller(14 個)
檔案說明
.../DDChatViewController.swift聊天主頁
.../DDChatViewController+Networking.swift歷史記錄/招呼語/補齊
.../DDChatViewController+Message.swift普通消息處理
.../DDChatViewController+SystemMessage.swift系統指令處理
.../DDChatViewController+Event.swiftUI 事件
.../DDChatViewController+Keyboard.swift鍵盤處理
.../DDChatViewController+ToolBarDelegate.swift工具列代理
.../DDChatViewController+TableDelegate.swiftTableView 代理
.../DDChatViewController+Notification.swift通知處理
.../DDChatViewController+NewInteractive.swift新互動邏輯
.../DDChatViewController+PopDelegate.swiftPop 手勢
.../DDChatViewController+Menu.swift選單處理
.../DDChatViewController+Chat.swift聊天相關
.../DDClientComponent-Bridging-Header.hOC/Swift 橋接

基礎路徑:DDClientComponent/Classes/Chat/Controller/

聊天 Model(15 個)
檔案說明
.../DDMessageModel.swift訊息模型 + DDMessageType
.../DDParamModel.swift外部參數 + CustomerType
.../DDChannelsModel.swift會話頻道
.../DDCommandDetailModel.swift系統指令 + DDCommandType
.../DDUserManager.swift使用者管理單例
.../DDUploadModel.swift上傳檔案
.../DDOrderDetailModel.swift訂單詳情
.../DDTemplateModel.swift消息模板
.../DDNoticeModel.swift通知
.../DDServiceAccountInfo.swift帳戶資訊
.../PayDetailModel.swift支付詳情
.../DDChatMenuModel.swift聊天選單
.../DDMessageSizeModel.swift訊息尺寸計算
.../DDNoticePhotoModel.swift通知圖片

基礎路徑:DDClientComponent/Classes/Chat/Model/

網路層(7 個)
檔案說明
.../Http/DDHttpService.swiftHTTP 基礎類(Moya)
.../Http/DDHttpService+ServiceCenter.swift業務 API 方法
.../Http/DDLotteryPlatformRequestInfo.swift請求配置
.../Http/DDLotteryPlatformRequestActionType.swiftEndpoint 枚舉
.../Http/DDNetworkingManager.swift網路管理
.../Http/DDError.swift錯誤模型
.../Http/HttpMessageManager/DDHttpMessageManager.swiftHTTP 消息管理

基礎路徑:DDClientComponent/Classes/Other/Network/

Socket 層(5 個)
檔案說明
.../DDSocketManager.swiftWebSocket 管理單例
.../DDSocketManager+Accept.swift接收訊息解析
.../DDSocketManager+Send.swift發送訊息/鑑權
.../DDSocketManager+Heartbeat.swift心跳 10 秒間隔
.../DDSocketOrginDataModel.swiftSocket 原始數據 + Cmd 枚舉

基礎路徑:DDClientComponent/Classes/Other/Network/Socket/

問題/訂單 Controller(8 個)
檔案說明
.../DDQustionTypeViewController.swift詢前頁(技能組選擇)
.../DDOrderSelectViewController.swift訂單選擇頁
.../DDCryptoOrderSelectViewController.swift加密貨幣訂單選擇
.../DDSubOrderSelectViewController.swift子訂單選擇
.../DDUpdateQustionViewController.swift問題更新頁
.../DDHelpWebViewController.swift幫助 WebView
.../DDBaseQuestionController.swift問題基礎 Controller
.../DDPageRouter.swift內部頁面跳轉路由

基礎路徑:DDClientComponent/Classes/Qusition/Controller/(最後兩項在 Other/Base/Controller)

評價/留言/設備(5 個)
檔案說明
.../DDEvaluateViewController.swift滿意度評價頁
.../DDDeviceInfoViewController.swift設備資訊頁
.../DDLeaveMessageController.swift離線留言主頁
.../DDLeaveMessageController+Data.swift留言資料處理
.../DDLeaveMessageController+Notification.swift留言通知處理

基礎路徑:DDClientComponent/Classes/(DeviceInfo / LeaveMessage)

聊天 View — ChatCell(19 個)
檔案說明
.../DDMeChatViewCell.swift我方文字
.../DDMEImageCell.swift我方圖片
.../DDMeVideoCell.swift我方影片
.../DDMeSureOrderCell.swift我方確認訂單
.../DDOtherChatViewCell.swift對方文字
.../DDOtherImageCell.swift對方圖片
.../DDOtherVideoCell.swift對方影片
.../DDOtherSelectOrderCell.swift對方選擇訂單
.../DDOtherSureOrderCell.swift對方確認訂單
.../DDOtherTextBankViewCell.swift對方銀行卡文本
.../DDOtherTextCurrencyViewCell.swift對方 USDT 文本
.../DDOtherTextOrderViewCell.swift對方訂單文本
.../DDOtherTextPhotoViewCell.swift對方圖片文本
.../DDOtherTextUrlViewCell.swift對方 URL 文本
.../DDCommandTableViewCell.swift系統指令通用
.../DDCommandLeaveMessageCell.swift系統離線留言
.../DDCommandNoticeCell.swift系統通知
.../DDCommandPhotoCell.swift系統圖片
.../DDCommandPhotoCollectionViewCell.swift系統圖片集合

基礎路徑:DDClientComponent/Classes/Chat/View/ChatCell/


API

所有 endpoint 定義於 DDLotteryPlatformRequestActionType 枚舉。除特別標註外,均為 POST + application/json。所有請求參數經 RSA 加密,封裝為 {"encryptParam": "..."}

域名與初始化


取得動態域名

POST /domain/info/queryDomainName

回傳 API_URL, WEBSOCKET_URL, LOG_URL(Base64 編碼)。


用戶/Token/會話


用戶資訊 + Token + 會話判斷(三合一)

POST /api/customer/collectionUserToken

三合一 API

一次完成用戶資訊採集 + Token 取得 + 會話有效性判斷,減少首屏請求。

Request:

參數型別說明
userNameString使用者名稱(遊客模式傳 productId)
userIdInt使用者 ID(遊客模式傳 0)
sysTagInt固定 3(iOS)
visitSourceInt固定 3
vipLevelIntVIP 等級
enterSceneInt進入場景
cusTypeInt1=會員, 2=遊客
deviceCodeString設備唯一碼(Base64 編碼)

Response: invalidFlag: 1=會話中, 2=無會話, 3=排隊中;含 Token 和用戶資訊。


建立會話

POST /api/customer/channel — 選擇技能組後建立會話,Socket 等待分配客服。

Request:

參數型別說明
chatTypeInt聊天類型
orderImgUrlsString訂單圖片 URL
typeInt1=會員, 2=遊客
userIdInt使用者 ID
platformOrderString訂單號
userNameString使用者名稱
triggerIdInt喚醒場景 ID(0=詢前頁, 1=代客充值, 2=充值未到帳, 3=提現, 4=遊戲, 5=代理, 6=充值撤銷, 7=充值無通道)
rechargeCodeInt代客充值碼(場景 1 時使用)
platformOrderTypeInt平台訂單類型(1=充值, 2=提現, 3=遊戲)

Response: 會話 channelId,Socket 接收客服分配。


結束會話

POST /api/customer/end

Request:

參數型別說明
userIdInt使用者 ID
endTypeInt1=會話轉接, 2=超時斷開, 3=關閉頁面, 4=排隊離開, 6=客服主動離開

Response: 無 data。


其他會話 API

Endpoint說明
/api/customer/leave使用者離開頁面
/api/customer/endQueue退出排隊
/api/cusCustomer/querySessionValid會話有效性檢查
/api/customer/cusLeakageChatList消息補齊

消息


發送訊息

POST /api/user/msg

Request:

參數型別說明
userIdInt使用者 ID
channelIdInt會話 ID
customerIdInt客戶 ID
msgIdString訊息唯一 ID
deviceTypeString設備類型
deviceIdString設備 ID
createTimeInt64建立時間
chatTimeInt64聊天時間(同 createTime)
messageTypeInt訊息類型(1=文本, 2=表情, 4=圖片, 5=檔案, 8=影片)
contentString訊息內容
filePathString檔案路徑(圖片/影片時使用)
fileNameString檔案名稱
width / heightInt影片尺寸(影片訊息時使用)

Response: 無 data。


歷史聊天記錄

POST /api/cusCustomer/newChatHistoryList


上傳圖片/檔案

POST /api/common/s3/upload — multipart


技能組/問題


查詢問題類型(技能組)

POST /api/cusCustomer/queryCusSkill


下載按鈕資訊

GET /api/common/queryDownloadPages


評價

Endpoint說明
/api/cusCustomer/addSatisfaction提交評價
/api/cusCustomer/querySatisfaction查詢評價標籤庫
/api/cusCustomer/querySatisfactionContent查詢評價內容

訂單

Endpoint說明
/api/platform/search搜索注單
/api/platform/games/list遊戲產品列表
/api/platform/msg/order/confirm訂單確認
/api/platform/push/order/v2推送訂單到聊天室
/api/recharge/find/order根據 ID 取得訂單
/api/cusCustomer/updateRechargeCode更新充值碼

其他 API

Endpoint說明
/api/common/collection採集客戶/遊客資訊
/api/user/token取得會話 Token
/api/common/information採集設備資訊
/api/cusServer/getDeviceInformation取得設備資訊
/api/common/findAutoReply黑名單回覆語
/api/common/queryDictDetail關鍵字查詢
/api/common/queryCommonConfigs通用配置
/api/customer/queueTips排隊提示語
/api/cusCustomer/queryCusQueue排隊人數
/api/server/entering輸入狀態上報
/api/customer/queryLeaveMessage留言配置
/api/cusCustomer/saveLeaveMessage保存留言
/api/cusCustomer/scenes福利客服場景列表
/api/customer/history/delete遊客刪除歷史
/log/logger/collect閃退日誌上報

WebSocket

Socket 指令

指令說明
C01鑑權請求
C02鑑權失敗
C03鑑權成功
C04設備被擠退
ping / pong心跳
P01單用戶消息
P02群組消息
E01錯誤
消息類型 DDMessageType(12 個)
說明
1文本
2表情
4圖片
5檔案
7系統指令
8影片
11銀行卡文本
12URL 文本
13圖片文本
15USDT
16選擇訂單
17確認訂單
系統指令 DDCommandType(14 個)
說明
-5排隊等待中
1匹配客服
2會話轉接
6邀請評價
7客服下線
8歡迎語
9結束語
10中斷會話
11黑名單
20客服關閉
23 / 29通知消息
28確認訂單
30撤銷消息
32刪除歷史

與 BB 主專案整合

初始化流程

觸發客服流程

  1. openChat()toCheckIsShowLines() → 判斷主線/次線
  2. showLine() 根據設定值判斷:"SDK" → DD SDK / "LiveChat" → LiveChat / URL → 智齒 H5 / 預設 → SDK
  3. goSDKKefu() 組裝參數 → DDConfigManager.openSTChat(param:)
  4. 訂單入口 orderClick() → 諮詢客服/複製單號 → openSDKChat() 帶訂單號
  5. 福利客服 jumpToBoonCustom(sceneType:) → 帶自定義 scenesId

DDClientComponentOptions.json

欄位說明
canUpVideo可否上傳影片
needServiceLeave離開是否呼叫 leave API(BB: true)
clientType0=官網包, 1=呱呱包, 2=SEO包
hasWelfareButton技能組顯示福利客服按鈕
hasDownloadButton技能組顯示下載按鈕(BB: true)
touristCanDeleteRecord遊客可否刪除歷史
cryptocurrency加密貨幣訂單樣式
mutableQuestionType技能組 API 返回值是否為 array
overrideUsername是否覆蓋 server 給的名稱
hasOnlyDepositWithdrawalTypes只有充值/提現按鈕

實作重點

  • 第一次域名請求 host 來源:初始 host 來自 configLocalDomain() 傳入的本地 JSON 設定檔(ClientDomainManager.currentJsonDic),由主 App 在啟動時提供(如 BB 的 ClientDomain.shared.domainDicBB)。設定檔中包含各環境的 domian_url(域名請求地址)、api_base_urlsocket_urllog_url 等初始值,非 hardcode 在 SDK 中
  • 域名防封:啟動時 /domain/info/queryDomainName 取 Base64 編碼域名,失敗時嘗試 OSS 備援 DDOssUrls
  • 域名取得失敗兜底:主域名請求失敗後,呼叫 doubleCheckOssUrls() 依序嘗試 DDOssUrls(從 UserDefaults "oss.domain.kfUrls" 讀取,測試包為空陣列)。每次失敗移除第一個 URL 並重試。若 OSS 全部失敗,complete(false, ...) 回調失敗,此時客服功能無法使用,使用者點擊客服入口不會有回應(無 Toast 或彈窗提示)
  • RSA 加密:所有 POST 參數經 DDIFCommonUtil.RSAWith: (OC) 加密,封裝為 {"encryptParam": "..."}。SDK 中無 debug 模式可關閉加密,如需除錯可在 DDLotteryPlatformRequestInfoparameters 計算屬性中加斷點查看加密前的原始參數,或使用 Proxyman 的 Map Local 功能替換回應
  • 消息補齊DDMessageLostManager 追蹤 sort 值,發現缺漏呼叫 /api/customer/cusLeakageChatList
  • 三合一 API/api/customer/collectionUserToken 減少首屏請求

關鍵數字

  • WebSocket 心跳:10 秒間隔
  • 斷線重連:5 秒後自動重連
  • Header 統一帶 appId, productId, version, deviceType, timestamp, token, language, ip