/* * 解析主窗口消息的返回 */ private static ClientMessage parseMessages(string response) { List<ClientAssortedMessage> results = new List<ClientAssortedMessage>(); ClientAssortedMessage obj = null; long nextrequesttime = 600000; JsonTextReader jsonReader = new JsonTextReader(new StringReader(response)); while (jsonReader.Read()) { if (jsonReader.TokenType == JsonToken.PropertyName) { if ((string)(jsonReader.Value) == "nextRequestTimeInterval") { if (jsonReader.Read()) { object result = jsonReader.Value; nextrequesttime = Convert.ToInt64(result); } } } else if (jsonReader.TokenType == JsonToken.StartArray) { while (jsonReader.Read()) { if (jsonReader.TokenType == JsonToken.EndArray) { //end break; } else if (jsonReader.TokenType == JsonToken.StartObject) { obj = new ClientAssortedMessage(); } else if (jsonReader.TokenType == JsonToken.EndObject) { results.Add(obj); } else if (jsonReader.TokenType == JsonToken.PropertyName) { if ((string)(jsonReader.Value) == "recommendScene") { if (jsonReader.Read()) { object result = jsonReader.Value; obj.recommendScene = Convert.ToString(result); } } else if ((string)(jsonReader.Value) == "title") { if (jsonReader.Read()) { object result = jsonReader.Value; obj.title = Convert.ToString(result); } } else if ((string)(jsonReader.Value) == "relatedTitle") { if (jsonReader.Read()) { object result = jsonReader.Value; obj.relatedTitle = Convert.ToString(result); } } else if ((string)(jsonReader.Value) == "relatedUrl") { if (jsonReader.Read()) { object result = jsonReader.Value; obj.relatedUrl = Convert.ToString(result); if (!string.IsNullOrEmpty(obj.relatedUrl)) { obj.relatedUrl += "&clientUserNo="+userNo; } } } else if ((string)(jsonReader.Value) == "nextRequestTime") { if (jsonReader.Read()) { object result = jsonReader.Value; obj.nextRequestTime = Convert.ToString(result); } } else if ((string)(jsonReader.Value) == "feekbackUrl") { if (jsonReader.Read()) { object result = jsonReader.Value; obj.feekbackUrl = Convert.ToString(result); } } else if ((string)(jsonReader.Value) == "items") { ClientAssortedMessageItem item = null; if (jsonReader.Read()) { if (jsonReader.TokenType == JsonToken.StartArray) { while (jsonReader.Read()) { if (jsonReader.TokenType == JsonToken.EndArray) { //end break; } else if (jsonReader.TokenType == JsonToken.StartObject) { item = new ClientAssortedMessageItem(); } else if (jsonReader.TokenType == JsonToken.EndObject) { obj.items.Add(item); } else if (jsonReader.TokenType == JsonToken.PropertyName) { if ((string)jsonReader.Value == "content") { if (jsonReader.Read()) { object result = jsonReader.Value; item.content = Convert.ToString(result); } } else if ((string)jsonReader.Value == "url") { if (jsonReader.Read()) { object result = jsonReader.Value; item.url = Convert.ToString(result); if (!string.IsNullOrEmpty(item.url)) { item.url += "&clientUserNo=" + userNo; } } } else if ((string)jsonReader.Value == "feedbackUrls") { if (jsonReader.Read()) { if (jsonReader.TokenType == JsonToken.StartArray) { while (jsonReader.Read()) { if (jsonReader.TokenType == JsonToken.EndArray) { //end break; } if (jsonReader.TokenType == JsonToken.String) { { object result = jsonReader.Value; item.feedbackUrls.Add(Convert.ToString(result)); } } } } } } } } } } } } } } } ClientMessage returnresult = new ClientMessage(nextrequesttime, results); return returnresult; }
/* * 获取主窗口消息 * bTest:为true的时候使用测试消息,否则从服务器获取消息 */ public static ClientMessage getMessages(bool bTest) { if (bTest) { List<ClientAssortedMessage> results = new List<ClientAssortedMessage>(); for (int j = 0; j < 4; j++) { ClientAssortedMessage msg = new ClientAssortedMessage(); if (j == 0) { msg.recommendScene = "关联请求"; msg.title = "关联请求"; msg.relatedTitle = "前往消息中心>>"; msg.relatedUrl = "www.baidu.com"; } else if (j == 1) { msg.recommendScene = "配件推送"; msg.title = "配件推送"; msg.relatedTitle = "前往配件报价>>"; msg.relatedUrl = "www.baidu.com"; } else if (j == 2) { msg.recommendScene = "订单消息"; msg.title = "订单消息"; msg.relatedTitle = "前往订单中心>>"; msg.relatedUrl = "www.baidu.com"; } else if (j == 3) { msg.recommendScene = "系统消息"; msg.title = "系统消息"; msg.relatedTitle = "前往系统公告>>"; msg.relatedUrl = "www.baidu.com"; } for (int i = 0; i < 3; i++) { ClientAssortedMessageItem item = new ClientAssortedMessageItem(); item.content = "childmessage" + (i + 1); item.url = "www.sina.com.cn"; item.feedbackUrls.Add("url1"); item.feedbackUrls.Add("url2"); item.feedbackUrls.Add("url3"); msg.items.Add(item); } results.Add(msg); } ClientMessage result = new ClientMessage(30000, results); return result; } String request = backendAddress + clientrequest; request += "?method=getMessages"; request += "&sessionId="; request += sessionId; request += "&shopId="; request += shopId; request += "&userNo="; request += userNo; request += "&apiVersion="; request += apiVersion; String response = getBackendData(request, "Get"); return parseMessages(response); }