Esempio n. 1
0
        /// <summary>
        /// 微信MessageHandler事件处理,此代码的简化MessageHandler方法已由/CustomerMessageHandler/CustomerMessageHandler_Event.cs完成,
        /// 此方法不再更新
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public ResponseMessageBase GetResponseMessage(RequestMessageEventBase requestMessage)
        {
            ResponseMessageBase responseMessage = null;

            switch (requestMessage.Event)
            {
            case Event.ENTER:
            {
                var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = "您刚才发送了ENTER事件请求。";
                responseMessage = strongResponseMessage;
                break;
            }

            case Event.LOCATION:
                throw new Exception("暂不可用");

            //break;
            case Event.subscribe:    //订阅
            {
                var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();

                //获取Senparc.Weixin.MP.dll版本信息
#if NET45
                var dllPath = HttpContext.Current.Server.MapPath("~/bin/Senparc.Weixin.MP.dll");
#else
                //var dllPath = ServerUtility.ContentRootMapPath("~/bin/Release/netcoreapp2.2/Senparc.Weixin.MP.dll");//本地测试路径
                var dllPath = ServerUtility.ContentRootMapPath("~/Senparc.Weixin.MP.dll");        //发布路径
#endif

                var fileVersionInfo = FileVersionInfo.GetVersionInfo(dllPath);

                var version = fileVersionInfo.FileVersion;
                strongResponseMessage.Content = string.Format(
                    "欢迎关注【Senparc.Weixin.MP 微信公众平台SDK】,当前运行版本:v{0}。\r\n您还可以发送【位置】【图片】【语音】信息,查看不同格式的回复。\r\nSDK官方地址:https://sdk.weixin.senparc.com",
                    version);
                responseMessage = strongResponseMessage;
                break;
            }

            case Event.unsubscribe:    //退订
            {
                //实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
                //unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。
                var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = "有空再来";
                responseMessage = strongResponseMessage;
                break;
            }

            case Event.CLICK:    //菜单点击事件,根据自己需要修改
                //这里的CLICK在此DEMO中不会被执行到,因为已经重写了OnEvent_ClickRequest
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(responseMessage);
        }
Esempio n. 2
0
        public ResponseMessageBase GetResponseMessage(RequestMessageEventBase requestMessage)
        {
            ResponseMessageBase responseMessage = null;

            switch (requestMessage.Event)
            {
            case Event.ENTER:
            {
                var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = "您刚才发送了ENTER事件请求。";
                responseMessage = strongResponseMessage;
                break;
            }

            case Event.LOCATION:
                throw new Exception("暂不可用");

            //break;
            case Event.subscribe:    //订阅
            {
                var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageNews>();

                //获取Senparc.Weixin.MP.dll版本信息
                var fileVersionInfo = FileVersionInfo.GetVersionInfo(HttpContext.Current.Server.MapPath("~/bin/Senparc.Weixin.MP.dll"));
                var version         = fileVersionInfo.FileVersion;
                strongResponseMessage.Articles.Add(new Article()
                    {
                        Title = "**,您有一个0元设计未领", PicUrl = "http://material-ui.net/content/zixun.jpg", Url = "http://material-ui.net/booking.html", Description = "您有一个0元设计未领"
                    });
                responseMessage = strongResponseMessage;
                break;
            }

            case Event.unsubscribe:    //退订
            {
                //实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
                //unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。
                var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = "有空再来";
                responseMessage = strongResponseMessage;
                break;
            }

            case Event.CLICK:    //菜单点击事件,根据自己需要修改
                //这里的CLICK在此DEMO中不会被执行到,因为已经重写了OnEvent_ClickRequest
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(responseMessage);
        }
Esempio n. 3
0
        public ResponseMessageBase GetResponseMessage(RequestMessageEventBase requestMessage)
        {
            ResponseMessageBase responseMessage = null;

            switch (requestMessage.Event)
            {
            case Event.ENTER:
            {
                var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = "您刚才发送了ENTER事件请求。";
                responseMessage = strongResponseMessage;
                break;
            }

            case Event.LOCATION:
                throw new Exception("暂不可用");

            //break;
            case Event.subscribe:    //订阅
            {
                var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();

                //获取Senparc.Weixin.MP.dll版本信息
                var fileVersionInfo = FileVersionInfo.GetVersionInfo(HttpContext.Current.Server.MapPath("~/bin/Senparc.Weixin.MP.dll"));
                var version         = fileVersionInfo.FileVersion;
                strongResponseMessage.Content = string.Format(
                    "欢迎关注【XX公司微信平台】,当前运行版本:v{0}。\r\n您还可以发送【位置】【图片】【语音】信息,查看不同格式的回复。\r\nSDK官方地址:http://www.yubom.net",
                    version);
                responseMessage = strongResponseMessage;
                break;
            }

            case Event.unsubscribe:    //退订
            {
                //实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
                //unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。
                var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = "亲,有空再来!";
                responseMessage = strongResponseMessage;
                break;
            }

            case Event.CLICK:    //菜单点击事件,根据自己需要修改
                //这里的CLICK在此DEMO中不会被执行到,因为已经重写了OnEvent_ClickRequest
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(responseMessage);
        }
Esempio n. 4
0
        public ResponseMessageBase GetResponseMessage(RequestMessageEventBase requestMessage)
        {
            ResponseMessageBase responseMessage = null;

            switch (requestMessage.Event)
            {
            case Event.ENTER:
            {
                var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = "您刚才发送了ENTER事件请求。";
                responseMessage = strongResponseMessage;
                break;
            }

            case Event.LOCATION:
                throw new Exception("暂不可用");

            //break;
            case Event.subscribe:    //订阅
            {
                var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();

                //获取Senparc.Weixin.MP.dll版本信息
                var fileVersionInfo = FileVersionInfo.GetVersionInfo(HttpContext.Current.Server.MapPath("~/bin/Senparc.Weixin.MP.dll"));
                var version         = fileVersionInfo.FileVersion;
                strongResponseMessage.Content = string.Format(
                    "欢迎关注计划管理平台,当前运行版本:v{0}。\r\n 输入如:【1】,【任务】,任务查询 注:(需在计划系统中有对应帐号并等待通过审核)\r\n输入如:【2】,【绑定】, 进行计划任务帐号绑定\r\n输入如:【3】,【电话】,【通讯录】, 进行通讯录查询\r\n",
                    version);
                responseMessage = strongResponseMessage;
                break;
            }

            case Event.unsubscribe:    //退订
            {
                //实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
                //unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。
                var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = "有空再来";
                responseMessage = strongResponseMessage;
                break;
            }

            case Event.CLICK:    //菜单点击事件,根据自己需要修改
                //这里的CLICK在此DEMO中不会被执行到,因为已经重写了OnEvent_ClickRequest
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(responseMessage);
        }
Esempio n. 5
0
        public ResponseMessageBase GetResponseMessage(RequestMessageEventBase requestMessage)
        {
            ResponseMessageBase responseMessage = null;
            switch (requestMessage.Event)
            {
                case Event.ENTER:
                    {
                        var strongResponseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();
                        strongResponseMessage.Content = "您刚才发送了ENTER事件请求。";
                        responseMessage = strongResponseMessage;
                        break;
                    }
                case Event.LOCATION:
                    throw new Exception("暂不可用");
                    //break;
                case Event.subscribe://订阅
                    {
                        var strongResponseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();

                        //获取OneGulp.WeChat.MP.dll版本信息
                        var fileVersionInfo = FileVersionInfo.GetVersionInfo(HttpContext.Current.Server.MapPath("~/bin/OneGulp.WeChat.MP.dll"));
                        var version = fileVersionInfo.FileVersion;
                        strongResponseMessage.Content = string.Format(
                            "欢迎关注,当前运行版本:v{0}。\r\n您还可以发送【位置】【图片】【语音】信息,查看不同格式的回复。",
                            version);
                        responseMessage = strongResponseMessage;
                        break;
                    }
                case Event.unsubscribe://退订
                    {
                        //实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
                        //unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。
                        var strongResponseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();
                        strongResponseMessage.Content = "亲,有空再来!";
                        responseMessage = strongResponseMessage;
                        break;
                    }
                case Event.CLICK://菜单点击事件,根据自己需要修改
                    //这里的CLICK在此DEMO中不会被执行到,因为已经重写了OnEvent_ClickRequest
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            return responseMessage;         
        }
Esempio n. 6
0
        public ResponseMessageBase GetResponseMessage(RequestMessageEventBase requestMessage)
        {
            string SiteUrl = System.Configuration.ConfigurationManager.AppSettings["SiteUrl"].ToString();
            ResponseMessageBase responseMessage = null;

            switch (requestMessage.Event)
            {
            case Event.ENTER:
            {
                var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = "您刚才发送了ENTER事件请求。";
                responseMessage = strongResponseMessage;
                break;
            }

            case Event.LOCATION:
                throw new Exception("暂不可用");

            //break;
            case Event.subscribe:    //订阅
            {
                #region 订阅
                var OpenID = requestMessage.FromUserName;
                var q      = QueryBuilder.Create <Data.WXUsers>().Equals(x => x.OpenID, OpenID);
                var model  = Data.WXUsersDB.GETWXUsers(q);
                if (model == null)
                {
                    //=不存在该用户
                    //var umodel = Common.GetUserInfo(OpenID);
                    var _model = new Data.WXUsers();
                    _model.CreateTime = DateTime.Now;
                    _model.OpenID     = OpenID;
                    _model.Sex        = 3;
                    var resultid = Data.WXUsersDB.AddWXUsers(_model);
                    if (resultid > 0)
                    {
                        //订阅成功,退出图文信息。
                        var art = Data.MyContentDB.GETMyContent("reg_myprofile");
                        var res = requestMessage.CreateResponseMessage <ResponseMessageNews>();
                        res.Articles.Add(new Article {
                                Title = art.Title, Description = art.SubContent, PicUrl = SiteUrl + art.Thumb, Url = art.LinkUrl + "?WxID=" + resultid
                            });
                        res.ToUserName = OpenID;
                        return(res);
                    }
                    else
                    {
                        //订阅不成功
                        var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();
                        strongResponseMessage.Content = "发生异常,订阅不成功。";
                        return(strongResponseMessage);
                    }
                }
                else
                {
                    //已经存在该用户
                    var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();
                    strongResponseMessage.Content = "您已经关注了,不需要重新关注。";
                    return(strongResponseMessage);
                }
                #endregion
                break;
            }

            case Event.unsubscribe:    //退订
            {
                //实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
                //unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。
                var strongResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = "有空再来";
                responseMessage = strongResponseMessage;
                break;
            }

            case Event.CLICK:    //菜单点击事件,根据自己需要修改
                throw new Exception("Demo中还没有加入CLICK的测试!");

            //break;
            default:
                throw new ArgumentOutOfRangeException();
            }

            return(responseMessage);
        }
Esempio n. 7
0
        public ResponseMessageBase GetResponseMessage(RequestMessageEventBase requestMessage)
        {
            UserProfile up = new UserProfile();
            var Buttons = up.Buttons;
            ResponseMessageBase responseMessage = null;
            switch (requestMessage.Event)
            {
                case Event.ENTER:
                    {
                        var strongResponseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();
                        strongResponseMessage.Content = "您刚才发送了ENTER事件请求。";
                        responseMessage = strongResponseMessage;
                        break;
                    }
                case Event.LOCATION:
                    throw new Exception("暂不可用");
                //break;
                case Event.subscribe://订阅
                    {
                        var strongResponseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();

                        //获取Senparc.Weixin.MP.dll版本信息
                        var fileVersionInfo = FileVersionInfo.GetVersionInfo(HttpContext.Current.Server.MapPath("~/bin/EasyWeixin.dll"));
                        var version = fileVersionInfo.FileVersion;
                        strongResponseMessage.Content = string.Format(
                            "欢迎关注【Senparc.Weixin.MP 微信公众平台SDK】,当前运行版本:v{0}。\r\n您还可以发送【位置】【图片】【语音】信息,查看不同格式的回复。\r\nSDK官方地址:http://weixin.senparc.com",
                            version);
                        responseMessage = strongResponseMessage;
                        break;
                    }
                case Event.unsubscribe://退订
                    {
                        //实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
                        //unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。
                        var strongResponseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();
                        strongResponseMessage.Content = "有空再来";
                        responseMessage = strongResponseMessage;
                        break;
                    }
                case Event.CLICK://菜单点击事件,根据自己需要修改
                    {
                        var strongResponseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();
                        foreach (var Button in Buttons)
                        {
                            if (Button.SubButtons.Count == 0)
                            {
                                if (Button.key == requestMessage.EventKey)
                                {
                                }
                            }
                            else
                            {
                                foreach (var Subitem in Button.SubButtons)
                                {
                                    if (Subitem.key == requestMessage.EventKey)
                                    {
                                    }
                                }
                            }
                        }

                        //throw new Exception("Demo中还没有加入CLICK的测试!");
                        break;
                    }
                case Event.VIEW://菜单点击事件,根据自己需要修改
                    {
                        var strongResponseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();
                        //requestMessage.EventKey

                        break;
                    }
                //break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            return responseMessage;
        }