123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace LYFZ.Weixin.SDK
- {
-
-
-
- public class Template
- {
-
-
-
- public string TemplateId { get; set; }
-
-
-
- public string Title { get; set; }
-
-
-
- public string PrimaryIndustry { get; set; }
-
-
-
- public string DeputyIndustry { get; set; }
-
-
-
- public string Content { get; set; }
-
-
-
- public string Example { get; set; }
-
-
-
-
-
-
-
-
-
- public Template(string templateId, string title, string primaryIndustry, string deputyIndustry,
- string content, string example)
- {
- TemplateId = templateId;
- Title = title;
- PrimaryIndustry = primaryIndustry;
- DeputyIndustry = deputyIndustry;
- Content = content;
- Example = example;
- }
-
-
-
- public Template()
- { }
-
-
-
-
- public override string ToString()
- {
- return string.Format("模板id:{0}\r\n标题:{1}\r\n一级行业:{2}\r\n二级行业:{3}\r\n" +
- "内容:{4}\r\n示例:{5}",
- TemplateId, Title, PrimaryIndustry, DeputyIndustry,
- Content, Example);
- }
-
-
-
-
- public void Parse(Newtonsoft.Json.Linq.JObject jo)
- {
- TemplateId = (string)jo["template_id"];
- Title = (string)jo["title"];
- PrimaryIndustry = (string)jo["primary_industry"];
- DeputyIndustry = (string)jo["deputy_industry"];
- Content = (string)jo["content"];
- Example = (string)jo["example"];
- }
-
-
-
-
-
- public static ErrorMessage Parse(string json, out Template[] templates)
- {
- templates = null;
- ErrorMessage errorMessage = new ErrorMessage(ErrorMessage.ExceptionCode, "");
- if (string.IsNullOrWhiteSpace(json))
- {
- errorMessage.errmsg = "请求失败。";
- }
- else if (ErrorMessage.IsErrorMessage(json))
- {
- errorMessage = ErrorMessage.Parse(json);
- }
- else
- {
- JObject jo = JObject.Parse(json);
- JToken jt;
- if (jo.TryGetValue("template_list", out jt) && jt.Type == JTokenType.Array)
- {
- errorMessage = new ErrorMessage(ErrorMessage.SuccessCode, "请求成功。");
- JArray ja = (JArray)jt;
- templates = new Template[ja.Count];
- for (int i = 0; i < ja.Count; i++)
- {
- templates[i] = new Template();
- templates[i].Parse((JObject)ja[i]);
- }
- }
- else
- {
- errorMessage.errmsg = "解析结果失败。";
- }
- }
- return errorMessage;
- }
- }
- }
|