예제 #1
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            StreamReader sr      = new StreamReader(HttpContext.Current.Request.InputStream);
            var          postStr = sr.ReadToEnd();

            HttpContext.Current.Request.InputStream.Seek(0, SeekOrigin.Begin);

            if (!string.IsNullOrEmpty(postStr))
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(postStr);

                XmlElement rootElement = doc.DocumentElement;

                WXReqModel model = new WXReqModel();
                model.XML          = postStr;
                model.ToUserName   = rootElement.SelectSingleNode("ToUserName").InnerText;
                model.FromUserName = rootElement.SelectSingleNode("FromUserName").InnerText;
                model.CreateTime   = rootElement.SelectSingleNode("CreateTime").InnerText;
                model.MsgType      = rootElement.SelectSingleNode("MsgType").InnerText;

                switch (model.MsgType)
                {
                case "text":
                    model.Content = rootElement.SelectSingleNode("Content").InnerText;
                    break;

                case "link":
                    model.Title       = rootElement.SelectSingleNode("Title").InnerText;
                    model.Description = rootElement.SelectSingleNode("Description").InnerText;
                    model.Url         = rootElement.SelectSingleNode("Url").InnerText;
                    break;

                case "location":
                    double Location_X, Location_Y; int Scale;
                    if (double.TryParse(rootElement.SelectSingleNode("Location_X").InnerText, out Location_X))
                    {
                        model.Location_X = Location_X;
                    }
                    if (double.TryParse(rootElement.SelectSingleNode("Location_Y").InnerText, out Location_Y))
                    {
                        model.Location_Y = Location_Y;
                    }
                    if (int.TryParse(rootElement.SelectSingleNode("Scale").InnerText, out Scale))
                    {
                        model.Scale = Scale;
                    }

                    model.Label = rootElement.SelectSingleNode("Label").InnerText;
                    break;

                case "image":
                    model.PicUrl  = rootElement.SelectSingleNode("PicUrl").InnerText;
                    model.MediaId = rootElement.SelectSingleNode("MediaId").InnerText;
                    break;

                case "voice":
                    model.PicUrl  = rootElement.SelectSingleNode("Format").InnerText;
                    model.MediaId = rootElement.SelectSingleNode("MediaId").InnerText;
                    try { model.Recongnition = rootElement.SelectSingleNode("Recongnition").InnerText; }
                    catch { }
                    break;

                case "video":
                    model.PicUrl  = rootElement.SelectSingleNode("ThumbMediaId").InnerText;
                    model.MediaId = rootElement.SelectSingleNode("MediaId").InnerText;
                    break;

                case "event":
                    model.EventKey = rootElement.SelectSingleNode("EventKey").InnerText;    //用于自定义菜单
                    model.Event    = rootElement.SelectSingleNode("Event").InnerText;
                    switch (model.Event)
                    {
                    case "LOCATION":
                        double lat, lng, pre;
                        double.TryParse(rootElement.SelectSingleNode("Latitude").InnerText, out lat);
                        double.TryParse(rootElement.SelectSingleNode("Longitude").InnerText, out lng);
                        double.TryParse(rootElement.SelectSingleNode("Precision").InnerText, out pre);
                        model.Latitude  = lat;
                        model.Longitude = lng;
                        model.Precision = pre;
                        break;

                    case "SCAN":
                    case "subscribe":
                        model.Ticket = rootElement.SelectSingleNode("Ticket").InnerText;
                        break;
                    }
                    break;
                }
                try
                {
                    model.MsgId = int.Parse(rootElement.SelectSingleNode("MsgId").InnerText);
                }
                catch { }

                return(model);
            }
            return(null);
        }
예제 #2
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            StreamReader sr = new StreamReader(HttpContext.Current.Request.InputStream);
            var postStr = sr.ReadToEnd();
            HttpContext.Current.Request.InputStream.Seek(0, SeekOrigin.Begin);

            if (!string.IsNullOrEmpty(postStr))
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(postStr);

                XmlElement rootElement = doc.DocumentElement;

                WXReqModel model = new WXReqModel();
                model.XML = postStr;
                model.ToUserName = rootElement.SelectSingleNode("ToUserName").InnerText;
                model.FromUserName = rootElement.SelectSingleNode("FromUserName").InnerText;
                model.CreateTime = rootElement.SelectSingleNode("CreateTime").InnerText;
                model.MsgType = rootElement.SelectSingleNode("MsgType").InnerText;

                switch (model.MsgType)
                {
                    case "text":
                        model.Content = rootElement.SelectSingleNode("Content").InnerText;
                        break;
                    case "link":
                        model.Title = rootElement.SelectSingleNode("Title").InnerText;
                        model.Description = rootElement.SelectSingleNode("Description").InnerText;
                        model.Url = rootElement.SelectSingleNode("Url").InnerText;
                        break;
                    case "location":
                        double Location_X, Location_Y; int Scale;
                        if (double.TryParse(rootElement.SelectSingleNode("Location_X").InnerText, out Location_X))
                            model.Location_X = Location_X;
                        if (double.TryParse(rootElement.SelectSingleNode("Location_Y").InnerText, out Location_Y))
                            model.Location_Y = Location_Y;
                        if (int.TryParse(rootElement.SelectSingleNode("Scale").InnerText, out Scale))
                            model.Scale = Scale;

                        model.Label = rootElement.SelectSingleNode("Label").InnerText;
                        break;
                    case "image":
                        model.PicUrl = rootElement.SelectSingleNode("PicUrl").InnerText;
                        model.MediaId = rootElement.SelectSingleNode("MediaId").InnerText;
                        break;
                    case "voice":
                        model.PicUrl = rootElement.SelectSingleNode("Format").InnerText;
                        model.MediaId = rootElement.SelectSingleNode("MediaId").InnerText;
                        try { model.Recongnition = rootElement.SelectSingleNode("Recongnition").InnerText; }
                        catch { }
                        break;
                    case "video":
                        model.PicUrl = rootElement.SelectSingleNode("ThumbMediaId").InnerText;
                        model.MediaId = rootElement.SelectSingleNode("MediaId").InnerText;
                        break;
                    case "event":
                        model.EventKey = rootElement.SelectSingleNode("EventKey").InnerText;//用于自定义菜单
                        model.Event = rootElement.SelectSingleNode("Event").InnerText;
                        switch (model.Event)
                        {
                            case "LOCATION":
                                double lat, lng, pre;
                                double.TryParse(rootElement.SelectSingleNode("Latitude").InnerText, out lat);
                                double.TryParse(rootElement.SelectSingleNode("Longitude").InnerText, out lng);
                                double.TryParse(rootElement.SelectSingleNode("Precision").InnerText, out pre);
                                model.Latitude = lat;
                                model.Longitude = lng;
                                model.Precision = pre;
                                break;
                            case "SCAN":
                            case "subscribe":
                                model.Ticket = rootElement.SelectSingleNode("Ticket").InnerText;
                                break;
                        }
                        break;
                }
                try
                {
                    model.MsgId = int.Parse(rootElement.SelectSingleNode("MsgId").InnerText);
                }
                catch { }

                return model;
            }
            return null;
        }
예제 #3
0
        public ActionResult Index(WXReqModel model)
        {
            var workContext = _orchardServices.WorkContext;
            var wxSettings = workContext.CurrentSite.As<WinXinSettingsPart>();

            if (model.ToUserName != wxSettings.UserName)
                return Content(string.Format(@"<xml>
<ToUserName><![CDATA[{0}]]></ToUserName>
<FromUserName><![CDATA[{1}]]></FromUserName>
<CreateTime>{2}</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[{3}]]></Content>
</xml>
", model.FromUserName, model.ToUserName, _winXinService.ConvertWXDateTimeInt(DateTime.Now), T("微信平台对接错误,本平台不为此服务号或订阅号提供服务!")));

            string name = null;
            switch (model.MsgType)
            {
                case "text":
                    name = "微信文本消息";
                    break;
                case "image":
                    name = "微信图片消息";
                    break;
                case "voice":
                    name = "微信语音消息";
                    break;
                case "video":
                    name = "微信视频消息";
                    break;
                case "location":
                    name = "微信地理位置消息";
                    break;
                case "link":
                    name = "微信链接消息";
                    break;
                case "event":
                    name = "微信事件消息";
                    if (model.Event == "LOCATION")
                        name = "微信上报地理位置事件";
                    break;
                default:
                    throw new OrchardException(T(string.Format("未知的消息类型:{0}", model.MsgType)));
            }
            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }
            var owner = _membershipService.GetUser(Owner);
            var msg = _contentManager.New("WeiXinMsg");
            msg.As<ICommonPart>().Owner = owner;
            var part = msg.As<WXMsgPart>();

            part.ToUserName = model.ToUserName;
            part.FromUserName = model.FromUserName;
            part.CreateTime = model.CreateTime;
            part.MsgType = model.MsgType;
            part.Content = model.Content;
            part.Location_X = model.Location_X;
            part.Location_Y = model.Location_Y;
            part.Scale = model.Scale;
            part.Label = model.Label;
            part.PicUrl = model.PicUrl;
            part.EventKey = model.EventKey;
            part.Event = model.Event;

            part.MsgId = model.MsgId;
            part.MediaId = model.MediaId;
            part.Format = model.Format;
            part.ThumbMediaId = model.ThumbMediaId;
            part.Title = model.Title;
            part.Description = model.Description;
            part.Url = model.Url;
            part.Ticket = model.Ticket;
            part.Latitude = model.Latitude;
            part.Longitude = model.Longitude;
            part.Precision = model.Precision;
            part.Recongnition = model.Recongnition;
            part.XML = model.XML;

            _contentManager.Create(msg);

            _workflowManager.TriggerEvent(name, msg, () => new Dictionary<string, object> { { "Content", msg } });

            var tupleList = _weiXinResp.List();
            var list = Shape.List(Attributes: new Dictionary<string, object> { 
                { "ToUserName", model.FromUserName } ,{ "FromUserName",model.ToUserName}
            });
            list.AddRange(tupleList.Select(t => _contentManager.BuildDisplay(t.Item1, "Detail")));

            var viewModel = Shape.ViewModel()
                .ContentItems(list);

            return View(viewModel);
        }