WmptWeixin/NoticeFactory.cs
(完整代码) 1KBusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WMPT.Common;
using System.Reflection;
namespace WMPT.Weixin
{
/// <summary>
/// 根据消息类型,返回对像
/// </summary>
public class NoticeFactory
{
const string AssemblyPath = "WMPT.Weixin";//用于反射
public static BaseHandler CreateInstance(string xml)
{
BaseHandler handler = null;
//解析数据
System.Xml.XmlDocument d = new System.Xml.XmlDocument();
d.LoadXml(xml);
System.Xml.XmlCDataSection n = d.SelectSingleNode("/xml/MsgType").FirstChild as System.Xml.XmlCDataSection;
HJlog.toLog("MsgType=" + n.Value);
Type type = Type.GetType(string.Format(AssemblyPath + ".{0}," + AssemblyPath, n.Value.Trim()), false, true);
BaseNotice noticemodel = (BaseNotice)Activator.CreateInstance(type);
if (noticemodel != null)
{
noticemodel = noticemodel.LoadXml(xml);
switch (noticemodel.MsgType)
{
case "text":
handler = new TextHandler(noticemodel);
break;
case "location":
handler = new LocationHandler(noticemodel);
break;
case "event":
handler = new EventHandler(noticemodel);
break;
default:
break;
}
}
else
{
HJlog.toLog("noticemodel=mull");
}
return handler;
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。
