public Popup(ClientPrompt prompt) { InitializeComponent(); this.cltPrompt = prompt; title.Text = cltPrompt.title; content.Text = cltPrompt.content; closeType = 3; if (cltPrompt.url == null || cltPrompt.url.Trim().Length == 0) { linkLabel1.Visible = false; } }
/* * 解析弹窗消息的返回 */ private static ClientPrompt parsePrompt(string response) { ClientPrompt cltprompt = null; try { JsonTextReader jsonReader = new JsonTextReader(new StringReader(response)); while (jsonReader.Read()) { if (jsonReader.TokenType == JsonToken.PropertyName) { if ((string)(jsonReader.Value) == "recommendScene") { if (jsonReader.Read()) { object result = jsonReader.Value; if (cltprompt == null) { cltprompt = new ClientPrompt(); } cltprompt.recommendScene = Convert.ToString(result); } } else if ((string)(jsonReader.Value) == "recommendId") { if (jsonReader.Read()) { object result = jsonReader.Value; if (cltprompt == null) { cltprompt = new ClientPrompt(); } cltprompt.recommendId = Convert.ToString(result); } } else if ((string)(jsonReader.Value) == "title") { if (jsonReader.Read()) { object result = jsonReader.Value; if (cltprompt == null) { cltprompt = new ClientPrompt(); } cltprompt.title = Convert.ToString(result); } } else if ((string)(jsonReader.Value) == "content") { if (jsonReader.Read()) { object result = jsonReader.Value; if (cltprompt == null) { cltprompt = new ClientPrompt(); } cltprompt.content = Convert.ToString(result); } } else if ((string)(jsonReader.Value) == "url") { if (jsonReader.Read()) { object result = jsonReader.Value; if (cltprompt == null) { cltprompt = new ClientPrompt(); } cltprompt.url = Convert.ToString(result); if (!string.IsNullOrEmpty(cltprompt.url)) { cltprompt.url += "&clientUserNo="+userNo; } } } else if ((string)(jsonReader.Value) == "feedbackUrl") { if (jsonReader.Read()) { object result = jsonReader.Value; if (cltprompt == null) { cltprompt = new ClientPrompt(); } cltprompt.feedbackUrl = Convert.ToString(result); } } else if ((string)(jsonReader.Value) == "nextRequestTime") { if (jsonReader.Read()) { object result = jsonReader.Value; if (cltprompt == null) { cltprompt = new ClientPrompt(); } cltprompt.nextRequestTime = Convert.ToString(result); } } else if ((string)(jsonReader.Value) == "feedbackUrls") { if (jsonReader.Read()) { if (cltprompt == null) { cltprompt = new ClientPrompt(); } if (jsonReader.TokenType == JsonToken.StartArray) { while (jsonReader.Read()) { if (jsonReader.TokenType == JsonToken.EndArray) { //end break; } if (jsonReader.TokenType == JsonToken.String) { { object result = jsonReader.Value; cltprompt.feedbackUrls.Add(Convert.ToString(result)); } } } } } } } } } catch (Exception ex) { } return cltprompt; }
/* * 获取弹窗消息 * bTest:为true的时候,返回自定义测试弹窗消息 */ public static ClientPrompt getPrompt(bool bTest) { if (bTest) { ClientPrompt cltprompt = new ClientPrompt(); cltprompt.title = "你有5条新的关联请求!"; cltprompt.content = "苏州新宇商贸,苏州大马汽修,苏州明明美容等请求与你关联!"; cltprompt.url = "www.baidu.com"; cltprompt.nextRequestTime = "10000"; //cltprompt.feedbackUrls.Add("www.baidu.com"); //cltprompt.feedbackUrls.Add("www.baidu.com"); //cltprompt.feedbackUrls.Add("www.baidu.com"); return cltprompt; } String request = backendAddress + clientrequest; request += "?method=getPrompt"; request += "&sessionId="; request += sessionId; request += "&shopId="; request += shopId; request += "&userNo="; request += userNo; request += "&apiVersion="; request += apiVersion; String response = getBackendData(request, "Get"); return parsePrompt(response); }