示例#1
0
        /// <summary>
        /// 创建服务
        /// </summary>
        /// <param name="messageContext">上下文对象</param>
        /// <param name="createServicFunction">外部方法</param>
        public static ResponseService_MemorySupport CreateOrGetService(CustomMessageContext messageContext, Func <string, NodeInstanceService> createServicFunction)
        {
            //参数检查
            if (createServicFunction == null)
            {
                throw new ArgumentNullException("createServicFunction");
            }

            //创建实例
            ResponseService_MemorySupport result = ResponseService.CreateOrGetService <ResponseService_MemorySupport>(messageContext) as ResponseService_MemorySupport;

            result.CreateServicFunction = createServicFunction;
            return(result);
        }
示例#2
0
        private IResponseMessageBase ResponseChainRequest_LevelForNode(RC.DataTypes inputType, IRequestMessageBase baseRequestMessage)
        {
            //获取关注的参数
            string openId    = baseRequestMessage.FromUserName;
            object rawObject = null;

            switch (inputType)
            {
            case RC.DataTypes.Text:
                rawObject = ((RequestMessageText)baseRequestMessage).Content;
                break;

            case RC.DataTypes.Image:
            {
                var inputData = baseRequestMessage as RequestMessageImage;
                if (inputData != null)
                {
                    rawObject = new RC.ImageCan(inputData.PicUrl, inputData.MediaId);
                }
            }
            break;

            case RC.DataTypes.Voice:
            {
                var inputData = baseRequestMessage as RequestMessageVoice;
                if (inputData != null)
                {
                    rawObject = new RC.VoiceCan(inputData.Format, inputData.Recognition, inputData.MediaId);
                }
            }
            break;

            case RC.DataTypes.Video:
            {
                var inputData = baseRequestMessage as RequestMessageVideo;
                if (inputData != null)
                {
                    rawObject = new RC.VideoCan(inputData.ThumbMediaId, inputData.MediaId);
                }
            }
            break;

                #region 后面才去支持
                //case DataTypes.Location:
                //    break;

                //case DataTypes.Link:
                //    break;
                #endregion

            default:
                return(null);
            }

            //用应答链去处理
            RC.ResponseService  service = RC.ResponseService_ConfigurationSupport.CreateOrGetService(this.CurrentMessageContext);    //[使用配置文件方式]
            RC.IResponseMessage ret     = null;
            try
            {
                ret = service.HanderData(openId, inputType, rawObject);
            }
            catch (Exception ex)
            {
                Logger.Log4Net.Error("应答模块捕获异常。", ex);
            }

            //返回结果
            return(ResponseChainRequest_LevelForNode_ResultHandler(ret));
        }
        public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage)
        {
            //扩展处理
            {
                string retNodeId;
                if (MessageHandlerExtend.ClickEvent2ResponseChain.CheckThenGetNodeId(requestMessage.EventKey, out retNodeId))
                {
                    RC.ResponseService service = RC.ResponseService_ConfigurationSupport.CreateOrGetService(this.CurrentMessageContext);     //[使用配置文件方式]
                    //跳转到指定节点
                    RC.IResponseMessage ret = service.JumpToTargetnode(requestMessage.FromUserName, retNodeId);
                    //返回结果
                    return(ResponseChainRequest_LevelForNode_ResultHandler(ret));
                }
            }


            IResponseMessageBase reponseMessage = null;

            //菜单点击,需要跟创建菜单时的Key匹配
            switch (requestMessage.EventKey)
            {
                #region SDK使用范例 备份

                /*
                 *
                 * case "OneClick":
                 *  {
                 *      //这个过程实际已经在OnTextOrEventRequest中完成,这里不会执行到。
                 *      var strongResponseMessage = CreateResponseMessage<ResponseMessageText>();
                 *      reponseMessage = strongResponseMessage;
                 *      strongResponseMessage.Content = "您点击了底部按钮。\r\n为了测试微信软件换行bug的应对措施,这里做了一个——\r\n换行";
                 *  }
                 *  break;
                 * case "SubClickRoot_Text":
                 *  {
                 *      var strongResponseMessage = CreateResponseMessage<ResponseMessageText>();
                 *      reponseMessage = strongResponseMessage;
                 *      strongResponseMessage.Content = "您点击了子菜单按钮。";
                 *  }
                 *  break;
                 * case "SubClickRoot_News":
                 *  {
                 *      var strongResponseMessage = CreateResponseMessage<ResponseMessageNews>();
                 *      reponseMessage = strongResponseMessage;
                 *      strongResponseMessage.Articles.Add(new Article()
                 *      {
                 *          Title = "您点击了子菜单图文按钮",
                 *          Description = "您点击了子菜单图文按钮,这是一条图文信息。",
                 *          PicUrl = "http://weixin.senparc.com/Images/qrcode.jpg",
                 *          Url = "http://weixin.senparc.com"
                 *      });
                 *  }
                 *  break;
                 * case "SubClickRoot_Music":
                 *  {
                 *      var strongResponseMessage = CreateResponseMessage<ResponseMessageMusic>();
                 *      reponseMessage = strongResponseMessage;
                 *      strongResponseMessage.Music.MusicUrl = "http://weixin.senparc.com/Content/music1.mp3";
                 *  }
                 *  break;
                 * case "SubClickRoot_Image":
                 *  {
                 *      var strongResponseMessage = CreateResponseMessage<ResponseMessageImage>();
                 *      reponseMessage = strongResponseMessage;
                 *      strongResponseMessage.Image.MediaId = "Mj0WUTZeeG9yuBKhGP7iR5n1xUJO9IpTjGNC4buMuswfEOmk6QSIRb_i98do5nwo";
                 *  }
                 *  break;
                 * case "SubClickRoot_Agent"://代理消息
                 *  {
                 *      //获取返回的XML
                 *      DateTime dt1 = DateTime.Now;
                 *      reponseMessage = MessageAgent.RequestResponseMessage(this, agentUrl, agentToken, RequestDocument.ToString());
                 *      //上面的方法也可以使用扩展方法:this.RequestResponseMessage(this,agentUrl, agentToken, RequestDocument.ToString());
                 *
                 *      DateTime dt2 = DateTime.Now;
                 *
                 *      if (reponseMessage is ResponseMessageNews)
                 *      {
                 *          (reponseMessage as ResponseMessageNews)
                 *              .Articles[0]
                 *              .Description += string.Format("\r\n\r\n代理过程总耗时:{0}毫秒", (dt2 - dt1).Milliseconds);
                 *      }
                 *  }
                 *  break;
                 * case "Member"://托管代理会员信息
                 *  {
                 *      //原始方法为:MessageAgent.RequestXml(this,agentUrl, agentToken, RequestDocument.ToString());//获取返回的XML
                 *      reponseMessage = this.RequestResponseMessage(agentUrl, agentToken, RequestDocument.ToString());
                 *  }
                 *  break;
                 * case "OAuth"://OAuth授权测试
                 *  {
                 *      var strongResponseMessage = CreateResponseMessage<ResponseMessageNews>();
                 *      strongResponseMessage.Articles.Add(new Article()
                 *      {
                 *          Title = "OAuth2.0测试",
                 *          Description = "点击【查看全文】进入授权页面。\r\n注意:此页面仅供测试(是专门的一个临时测试账号的授权,并非Senparc.Weixin.MP SDK官方账号,所以如果授权后出现错误页面数正常情况),测试号随时可能过期。请将此DEMO部署到您自己的服务器上,并使用自己的appid和secret。",
                 *          Url = "http://weixin.senparc.com/oauth2",
                 *          PicUrl = "http://weixin.senparc.com/Images/qrcode.jpg"
                 *      });
                 *      reponseMessage = strongResponseMessage;
                 *  }
                 *  break;
                 * case "Description":
                 *  {
                 *      var strongResponseMessage = CreateResponseMessage<ResponseMessageText>();
                 *      strongResponseMessage.Content = GetWelcomeInfo();
                 *      reponseMessage = strongResponseMessage;
                 *  }
                 *  break;
                 * default:
                 *  {
                 *      var strongResponseMessage = CreateResponseMessage<ResponseMessageText>();
                 *      strongResponseMessage.Content = "您点击了按钮,EventKey:" + requestMessage.EventKey;
                 *      reponseMessage = strongResponseMessage;
                 *  }
                 *  break;
                 *
                 */
                #endregion
            }

            return(reponseMessage);
        }