1
This commit is contained in:
@@ -113,11 +113,45 @@ namespace Assets.MyGame.Scripts.Net
|
||||
/// <summary>
|
||||
/// 获取我的会话列表(含消息历史)
|
||||
/// GET /customerapi/Customer/my-conversations
|
||||
/// 注意:客服 API 使用 code=1 为成功(非标准 0),需独立处理
|
||||
/// 返回:List<MyConversationInfo>
|
||||
/// </summary>
|
||||
public static void GetMyConversations(Action<List<MyConversationInfo>> callback)
|
||||
{
|
||||
APIManager.Response<List<MyConversationInfo>>(APIType.Customer_MyConversations, callback);
|
||||
UIManager.Instance.StartCoroutine(FetchMyConversations(callback));
|
||||
}
|
||||
|
||||
private static System.Collections.IEnumerator FetchMyConversations(Action<List<MyConversationInfo>> 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<List<MyConversationInfo>>();
|
||||
callback?.Invoke(list);
|
||||
}
|
||||
else
|
||||
{
|
||||
callback?.Invoke(new List<MyConversationInfo>());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
callback?.Invoke(new List<MyConversationInfo>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user