Ejemplo n.º 1
0
        /// <summary>
        /// 处理事件
        /// </summary>
        /// <param name="requestStr"></param>
        /// <returns></returns>
        private OutMessage HandleEventMsg(string requestStr)
        {
            var inMessage  = XmlSerializeUtil.Deserialize <InMessageEvent>(requestStr);
            var outMessage = new OutMessageText
            {
                CreateTime   = inMessage.CreateTime,
                FromUserName = inMessage.ToUserName,
                ToUserName   = inMessage.FromUserName,
                Content      = "未知事件类型"
            };

            switch (inMessage.Event.ToLower())
            {
            case "subscribe":
                return(HandleSubscribe(inMessage));

            case "click":
                return(HandleClick(inMessage));

            case "view":
                return(HandleView(inMessage));

            case "scancode_push":
                return(HandleScancodePush(inMessage));

            case "scancode_waitmsg":
                return(HandleScancodeWaitmsg(inMessage));

            default:
                break;
            }


            return(outMessage);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 处理二维码扫描到url跳转事件 返回消息不会起作用!
        /// </summary>
        /// <param name="inMessage"></param>
        /// <returns></returns>
        private OutMessage HandleScancodePush(InMessageEvent inMessage)
        {
            var outMessage = new OutMessageText
            {
                CreateTime   = inMessage.CreateTime,
                FromUserName = inMessage.ToUserName,
                ToUserName   = inMessage.FromUserName,
                Content      = $"HandleScancodePush{inMessage.EventKey}扫描结果:ScanCodeInfo:{inMessage.ScanCodeInfo},ScanType:{inMessage.ScanType},ScanResult:{inMessage.ScanResult}"
            };

            return(outMessage);//可以返回空
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 处理菜单跳转事件 返回消息不会起作用!
        /// </summary>
        /// <param name="inMessage"></param>
        /// <returns></returns>
        private OutMessage HandleView(InMessageEvent inMessage)
        {
            var outMessage = new OutMessageText
            {
                CreateTime   = inMessage.CreateTime,
                FromUserName = inMessage.ToUserName,
                ToUserName   = inMessage.FromUserName,
                Content      = $"{inMessage.EventKey}您跳转的url是{inMessage.EventKey}"
            };

            return(outMessage);//可以返回空
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 处理菜单点击事件
        /// </summary>
        /// <param name="inMessage"></param>
        /// <returns></returns>
        private OutMessage HandleClick(InMessageEvent inMessage)
        {
            var outMessage = new OutMessageText
            {
                CreateTime   = inMessage.CreateTime,
                FromUserName = inMessage.ToUserName,
                ToUserName   = inMessage.FromUserName,
                Content      = $"您点击的按钮是{inMessage.EventKey},暂未设置返回信息"
            };

            if (inMessage.EventKey.ToLower() == "music")
            {
                outMessage.Content = "http://music.taihe.com/";
            }


            return(outMessage);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 处理文本消息
        /// </summary>
        /// <param name="requestStr"></param>
        /// <returns></returns>
        private OutMessage HandleTextMsg(string requestStr)
        {
            var inMessage  = XmlSerializeUtil.Deserialize <InMessageText>(requestStr);
            var outMessage = new OutMessageText
            {
                Content      = "您输入的内容是" + inMessage.Content,
                MsgType      = inMessage.MsgType,
                CreateTime   = inMessage.CreateTime,
                FromUserName = inMessage.ToUserName,
                ToUserName   = inMessage.FromUserName
            };

            if (inMessage.Content.Contains("hello") || inMessage.Content.Contains("你好") || inMessage.Content.Contains("你是谁") || inMessage.Content.Contains("从哪里来"))
            {
                outMessage.Content = "hello,我是何大鹏,欢迎来到召唤师峡谷,您的OPenid是" + inMessage.FromUserName;
            }

            return(outMessage);
        }