using Assets.MyGame.Scripts.Net.API; using Assets.MyGame.Scripts.Net.APIRequest.Objs; using Assets.MyGame.Scripts.Net.APIRequest.Params; using Assets.MyGame.Scripts.Net.APIResponses.Customer_SubClass; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; namespace Assets.MyGame.Scripts.Net { public static partial class APIRequestList { #region Customer /// /// 发起会话(POST) /// 参数:userId、userName /// 返回:ConversationInfo(会话信息) /// public static void StartConversation(StartConversationObj req, Action callback) { APIManager.Response(APIType.Customer_Start, req, callback); } /// /// 发送消息(POST) /// 参数:conversationId、senderType、senderId、senderName、senderAvatar、contentType、content /// 返回:CustomerMessageInfo(消息信息) /// public static void SendMessage(SendMessageObj req, Action callback) { APIManager.Response(APIType.Customer_Message, req, callback); } /// /// 获取消息列表(GET) /// 参数:conversationId /// 返回:List(消息列表) /// public static void GetMessages(string conversationId, Action> callback) { APIManager.Response>(APIType.Customer_Messages, new GetMessagesParam { conversationId = conversationId }, callback); } /// /// 获取会话列表(GET) /// 参数:customerId(可选) /// 返回:List(会话列表) /// public static void GetConversations(Action> callback) { APIManager.Response>(APIType.Customer_Conversations, callback); } /// /// 获取会话列表(GET,带客服ID筛选) /// 参数:customerId /// 返回:List(会话列表) /// public static void GetConversations(string customerId, Action> callback) { APIManager.Response>(APIType.Customer_Conversations, new GetConversationsParam { customerId = customerId }, callback); } /// /// 结束会话(POST) /// 参数:conversationId /// 返回:string(结果提示) /// public static void EndConversation(EndConversationObj req, Action callback) { APIManager.Response(APIType.Customer_End, req, callback); } /// /// 获取在线客服列表(GET) /// 返回:List(在线客服列表) /// public static void GetOnlineCustomers(Action> callback) { APIManager.Response>(APIType.Customer_Online, callback); } /// /// 更新客服状态(POST) /// 参数:userId、status(0:离线 1:在线) /// 返回:string(结果提示) /// public static void UpdateCustomerStatus(UpdateCustomerStatusObj req, Action callback) { APIManager.Response(APIType.Customer_Status, req, callback); } /// /// 获取聊天记录(GET) /// 参数:conversationId /// 返回:List(聊天记录列表) /// public static void GetChatLog(string conversationId, Action> callback) { APIManager.Response>(APIType.Customer_ChatLog, new GetMessagesParam { conversationId = conversationId }, callback); } /// /// 获取我的会话列表(含消息历史) /// GET /customerapi/Customer/my-conversations /// 注意:客服 API 使用 code=1 为成功(非标准 0),需独立处理 /// 返回:List /// public static void GetMyConversations(Action> callback) { UIManager.Instance.StartCoroutine(FetchMyConversations(callback)); } private static System.Collections.IEnumerator FetchMyConversations(Action> callback) { string url = APIManager.baseURL + "/customerapi/Customer/my-conversations"; using (var req = UnityEngine.Networking.UnityWebRequest.Get(url)) { req.SetRequestHeader("Content-Type", "application/json"); if (!string.IsNullOrEmpty(APIManager.token)) req.SetRequestHeader("token", APIManager.token); yield return req.SendWebRequest(); if (req.result == UnityEngine.Networking.UnityWebRequest.Result.Success) { var json = req.downloadHandler.text; // 客服 API 返回:{ code: 1, data: [...] },直接取 data var jObj = Newtonsoft.Json.Linq.JObject.Parse(json); if (jObj["data"] != null) { var list = jObj["data"].ToObject>(); callback?.Invoke(list); } else { callback?.Invoke(new List()); } } else { callback?.Invoke(new List()); } } } /// /// 上传客服图片(POST,multipart/form-data) /// 参数:file(文件二进制) /// 返回:string(图片URL) /// public static void UploadCustomerImage(string filePath, Action callback) { APIManager.Response(APIType.ImageUpload_Upload, callback); } #endregion } }