/// <summary>
        /// 点击事件
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage)
        {
            IResponseMessageBase reponseMessage = null;

            //菜单点击,需要跟创建菜单时的Key匹配
            switch (requestMessage.EventKey)
            {
            case "toupiao":
                return(this.GetVoteUrlResponse(requestMessage.FromUserName));

                break;

            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 = "您点击了子菜单图文按钮,这是一条图文信息。这个区域是Description内容\r\n可以使用\\r\\n进行换行。",
                        PicUrl      = "http://sdk.weixin.senparc.com/Images/qrcode.jpg",
                        Url         = "http://sdk.weixin.senparc.com"
                    });

                //随机添加一条图文,或只输出一条图文信息
                if (DateTime.Now.Second % 2 == 0)
                {
                    strongResponseMessage.Articles.Add(new Article()
                        {
                            Title       = "这是随机产生的第二条图文信息,用于测试多条图文的样式",
                            Description = "这是随机产生的第二条图文信息,用于测试多条图文的样式",
                            PicUrl      = "http://sdk.weixin.senparc.com/Images/qrcode.jpg",
                            Url         = "http://sdk.weixin.senparc.com"
                        });
                }
            }
            break;

            case "SubClickRoot_Music":
            {
                //上传缩略图
                var accessToken  = Containers.AccessTokenContainer.TryGetAccessToken(appId, appSecret);
                var uploadResult = AdvancedAPIs.MediaApi.UploadTemporaryMedia(accessToken, UploadMediaFileType.thumb,
                                                                              Server.GetMapPath("~/Images/Logo.jpg"));
                //设置音乐信息
                var strongResponseMessage = CreateResponseMessage <ResponseMessageMusic>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Music.Title        = "天籁之音";
                strongResponseMessage.Music.Description  = "真的是天籁之音";
                strongResponseMessage.Music.MusicUrl     = "http://sdk.weixin.senparc.com/Content/music1.mp3";
                strongResponseMessage.Music.HQMusicUrl   = "http://sdk.weixin.senparc.com/Content/music1.mp3";
                strongResponseMessage.Music.ThumbMediaId = uploadResult.thumb_media_id;
            }
            break;

            case "SubClickRoot_Image":
            {
                //上传图片
                var accessToken  = Containers.AccessTokenContainer.TryGetAccessToken(appId, appSecret);
                var uploadResult = AdvancedAPIs.MediaApi.UploadTemporaryMedia(accessToken, UploadMediaFileType.image,
                                                                              Server.GetMapPath("~/Images/Logo.jpg"));
                //设置图片信息
                var strongResponseMessage = CreateResponseMessage <ResponseMessageImage>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Image.MediaId = uploadResult.media_id;
            }
            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 = "选择下面两种不同的方式进行测试,区别在于授权成功后,最后停留的页面。",
                        //Url = "http://sdk.weixin.senparc.com/oauth2",
                        //PicUrl = "http://sdk.weixin.senparc.com/Images/qrcode.jpg"
                    });

                strongResponseMessage.Articles.Add(new Article()
                    {
                        Title       = "OAuth2.0测试(不带returnUrl),测试环境可使用",
                        Description = "OAuth2.0测试(不带returnUrl)",
                        Url         = "http://sdk.weixin.senparc.com/oauth2",
                        PicUrl      = "http://sdk.weixin.senparc.com/Images/qrcode.jpg"
                    });

                var returnUrl = "/OAuth2/TestReturnUrl";
                strongResponseMessage.Articles.Add(new Article()
                    {
                        Title       = "OAuth2.0测试(带returnUrl),生产环境强烈推荐使用",
                        Description = "OAuth2.0测试(带returnUrl)",
                        Url         = "http://sdk.weixin.senparc.com/oauth2?returnUrl=" + returnUrl.UrlEncode(),
                        PicUrl      = "http://sdk.weixin.senparc.com/Images/qrcode.jpg"
                    });

                reponseMessage = strongResponseMessage;
            }
            break;

            case "Description":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = GetWelcomeInfo();
                reponseMessage = strongResponseMessage;
            }
            break;

            case "SubClickRoot_PicPhotoOrAlbum":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "您点击了【微信拍照】按钮。系统将会弹出拍照或者相册发图。";
            }
            break;

            case "SubClickRoot_ScancodePush":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "您点击了【微信扫码】按钮。";
            }
            break;

            case "ConditionalMenu_Male":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "您点击了个性化菜单按钮,您的微信性别设置为:男。";
            }
            break;

            case "ConditionalMenu_Femle":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "您点击了个性化菜单按钮,您的微信性别设置为:女。";
            }
            break;

            default:
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = "正在建设中,敬请期待";
                reponseMessage = strongResponseMessage;
            }
            break;
            }

            return(reponseMessage);
        }
        public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage)
        {
            IResponseMessageBase reponseMessage = null;

            //菜单点击,需要跟创建菜单时的Key匹配
            switch (requestMessage.EventKey)
            {
            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 accessToken = CommonAPIs.AccessTokenContainer.TryGetToken(appId, appSecret);
                //var uploadResult = AdvancedAPIs.Media.MediaApi.Upload(accessToken, UploadMediaFileType.thumb,
                //                                             Server.GetMapPath("~/Images/Logo.jpg"));
                ////设置音乐信息
                //var strongResponseMessage = CreateResponseMessage<ResponseMessageMusic>();
                //reponseMessage = strongResponseMessage;
                //strongResponseMessage.Music.Title = "天籁之音";
                //strongResponseMessage.Music.Description = "真的是天籁之音";
                //strongResponseMessage.Music.MusicUrl = "http://weixin.senparc.com/Content/music1.mp3";
                //strongResponseMessage.Music.ThumbMediaId = uploadResult.thumb_media_id;
            }
            break;

            case "SubClickRoot_Customer":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                using (WXDBEntities db = new WXDBEntities())
                {
                    var tmp = db.WXKewWords.Where(s => s.Type == 0).FirstOrDefault();
                    if (tmp != null)
                    {
                        strongResponseMessage.Content = tmp.Description;
                    }
                    else
                    {
                        strongResponseMessage.Content = "你好,欢迎关注恒大御景湾 !";
                        //\r\n输入序号快速了解我们\r\n[1]查看项目投资方\r\n[2]查看户型\r\n[3]查看交通,\r\n加入誉天下会,尊享更多优惠!\r\n<a href=\"http://zhengrong.tencenthouse.com/member/registerMember.aspx\">马上加入》》》</a>
                    }
                }
            }
            break;

            case "SubClick_sh":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "开盘时间待定,敬请关注官方微信。";
            }
            break;

            case "SubClick_xs":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "销售热线:021-60259333";
            }
            break;

            case "SubClick_jt":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "来访动线:\r\n1、地铁11号线,马陆站2号出口(出口前进20米,到阿克苏南路后右转);\r\n2、市区方向:\r\n(1)您可以就近上中环高架,转S5沪嘉高速至【马陆】出口下,左转至【宝安公路】,然后到【永盛南路】左转,根据我们的道旗指引就到了。\r\n(2)沪翔高速:S6沪翔高速至【永盛路出口】下,至永盛南路向北行驶再右转,根据我们的道旗指引就到了。\r\n3、使用手机【高德导航】,搜索“恒大御景湾”根据指示即可到达";
            }
            break;

            case "SubClick_xm":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "项目地址:嘉定区马陆镇【阿克苏南路】与【合作南路】交汇处东50米。";
            }
            break;

            case "SubClickRoot_Image":
            {
                //上传图片
                //var accessToken = CommonAPIs.AccessTokenContainer.TryGetToken(appId, appSecret);
                //var uploadResult = AdvancedAPIs.Media.MediaApi.Upload(accessToken, UploadMediaFileType.image,
                //                                             Server.GetMapPath("~/Images/Logo.jpg"));
                ////设置图片信息
                //var strongResponseMessage = CreateResponseMessage<ResponseMessageImage>();
                //reponseMessage = strongResponseMessage;
                //strongResponseMessage.Image.MediaId = uploadResult.media_id;
                //return null;
            }
            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)
                {
                    return(null);
                }
            }
            break;

            case "Member":    //托管代理会员信息
            {
                //原始方法为:MessageAgent.RequestXml(this,agentUrl, agentToken, RequestDocument.ToString());//获取返回的XML
                //return null;
            }
            break;

            case "OAuth":    //OAuth授权测试
            {
                //return null;
            }
            break;

            case "Description":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = GetWelcomeInfo();
                reponseMessage = strongResponseMessage;
            }
            break;

            default:
            {
                // return null;
            }
            break;
            }

            return(reponseMessage);
        }
Esempio n. 3
0
        public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage)
        {
            IResponseMessageBase reponseMessage = null;

            //菜单点击,需要跟创建菜单时的Key匹配
            switch (requestMessage.EventKey)
            {
            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://www.w3ccloud.com/Images/qrcode.jpg",
                        Url         = "http://www.w3ccloud.com"
                    });
            }
            break;

            case "SubClickRoot_Music":
            {
                //上传缩略图
                var accessToken  = AccessTokenContainer.TryGetAccessToken(appId, appSecret);
                var uploadResult = MediaApi.UploadTemporaryMedia(accessToken, UploadMediaFileType.thumb,
                                                                 Server.GetMapPath("~/Images/Logo.jpg"));
                //设置音乐信息
                var strongResponseMessage = CreateResponseMessage <ResponseMessageMusic>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Music.Title        = "天籁之音";
                strongResponseMessage.Music.Description  = "真的是天籁之音";
                strongResponseMessage.Music.MusicUrl     = "http://www.w3ccloud.com/Content/music1.mp3";
                strongResponseMessage.Music.HQMusicUrl   = "http://www.w3ccloud.com/Content/music1.mp3";
                strongResponseMessage.Music.ThumbMediaId = uploadResult.thumb_media_id;
            }
            break;

            case "SubClickRoot_Image":
            {
                //上传图片
                var accessToken  = AccessTokenContainer.TryGetAccessToken(appId, appSecret);
                var uploadResult = MediaApi.UploadTemporaryMedia(accessToken, UploadMediaFileType.image,
                                                                 Server.GetMapPath("~/Images/Logo.jpg"));
                //设置图片信息
                var strongResponseMessage = CreateResponseMessage <ResponseMessageImage>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Image.MediaId = uploadResult.media_id;
            }
            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://www.w3ccloud.com/oauth2",
                        PicUrl      = "http://www.w3ccloud.com/Images/qrcode.jpg"
                    });
                reponseMessage = strongResponseMessage;
            }
            break;

            case "Description":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = GetWelcomeInfo();
                reponseMessage = strongResponseMessage;
            }
            break;

            case "SubClickRoot_PicPhotoOrAlbum":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "您点击了【微信拍照】按钮。系统将会弹出拍照或者相册发图。";
            }
            break;

            case "SubClickRoot_ScancodePush":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "您点击了【微信扫码】按钮。";
            }
            break;

            default:
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = "您点击了按钮,EventKey:" + requestMessage.EventKey;
                reponseMessage = strongResponseMessage;
            }
            break;
            }

            return(reponseMessage);
        }
Esempio n. 4
0
        /// <summary>
        /// 点击事件
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage)
        {
            IResponseMessageBase reponseMessage = null;

            //菜单点击,需要跟创建菜单时的Key匹配

            switch (requestMessage.EventKey)
            {
            case "OneClick":
            {
                //这个过程实际已经在OnTextOrEventRequest中命中“OneClick”关键字,并完成回复,这里不会执行到。
                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 = "您点击了子菜单图文按钮,这是一条图文信息。这个区域是Description内容\r\n可以使用\\r\\n进行换行。",
                        PicUrl      = "https://sdk.weixin.senparc.com/Images/qrcode.jpg",
                        Url         = "https://sdk.weixin.senparc.com"
                    });

                //随机添加一条图文,或只输出一条图文信息
                if (SystemTime.Now.Second % 2 == 0)
                {
                    strongResponseMessage.Articles.Add(new Article()
                        {
                            Title       = "这是随机产生的第二条图文信息,用于测试多条图文的样式",
                            Description = "这是随机产生的第二条图文信息,用于测试多条图文的样式",
                            PicUrl      = "https://sdk.weixin.senparc.com/Images/qrcode.jpg",
                            Url         = "https://sdk.weixin.senparc.com"
                        });
                }
            }
            break;

            case "SubClickRoot_Music":
            {
                //上传缩略图

#if NET45
                var filePath = "~/Images/Logo.thumb.jpg";
#else
                var filePath = "~/wwwroot/Images/Logo.thumb.jpg";
#endif

                var uploadResult = AdvancedAPIs.MediaApi.UploadTemporaryMedia(appId, UploadMediaFileType.thumb,
                                                                              ServerUtility.ContentRootMapPath(filePath));
                //PS:缩略图官方没有特别提示文件大小限制,实际测试哪怕114K也会返回文件过大的错误,因此尽量控制在小一点(当前图片39K)

                //设置音乐信息
                var strongResponseMessage = CreateResponseMessage <ResponseMessageMusic>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Music.Title        = "天籁之音";
                strongResponseMessage.Music.Description  = "真的是天籁之音";
                strongResponseMessage.Music.MusicUrl     = "https://sdk.weixin.senparc.com/Content/music1.mp3";
                strongResponseMessage.Music.HQMusicUrl   = "https://sdk.weixin.senparc.com/Content/music1.mp3";
                strongResponseMessage.Music.ThumbMediaId = uploadResult.thumb_media_id;
            }
            break;

            case "SubClickRoot_Image":
            {
                //上传图片
#if NET45
                var filePath = "~/Images/Logo.jpg";
#else
                var filePath = "~/wwwroot/Images/Logo.jpg";
#endif

                var uploadResult = AdvancedAPIs.MediaApi.UploadTemporaryMedia(appId, UploadMediaFileType.image,
                                                                              ServerUtility.ContentRootMapPath(filePath));
                //设置图片信息
                var strongResponseMessage = CreateResponseMessage <ResponseMessageImage>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Image.MediaId = uploadResult.media_id;
            }
            break;

            case "SendMenu":
            {
                var menuContentList = new List <SendMenuContent>()
                {
                    new SendMenuContent("101", "满意"),
                    new SendMenuContent("102", "一般"),
                    new SendMenuContent("103", "不满意")
                };
                //使用异步接口
                CustomApi.SendMenu(appId, OpenId, "请对 Senparc.Weixin SDK 给出您的评价", menuContentList, "感谢您的参与!");

                reponseMessage = new ResponseMessageNoResponse();        //不返回任何消息
            }
            break;

            case "SubClickRoot_Agent":    //代理消息
            {
                //获取返回的XML
                var dt1 = SystemTime.Now;
                reponseMessage = MessageAgent.RequestResponseMessage(this, agentUrl, agentToken, RequestDocument.ToString());
                //上面的方法也可以使用扩展方法:this.RequestResponseMessage(this,agentUrl, agentToken, RequestDocument.ToString());

                var dt2 = SystemTime.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 = "选择下面两种不同的方式进行测试,区别在于授权成功后,最后停留的页面。",
                        //Url = "https://sdk.weixin.senparc.com/oauth2",
                        //PicUrl = "https://sdk.weixin.senparc.com/Images/qrcode.jpg"
                    });

                strongResponseMessage.Articles.Add(new Article()
                    {
                        Title       = "OAuth2.0测试(不带returnUrl),测试环境可使用",
                        Description = "OAuth2.0测试(不带returnUrl)",
                        Url         = "https://sdk.weixin.senparc.com/oauth2",
                        PicUrl      = "https://sdk.weixin.senparc.com/Images/qrcode.jpg"
                    });

                var returnUrl = "/OAuth2/TestReturnUrl";
                strongResponseMessage.Articles.Add(new Article()
                    {
                        Title       = "OAuth2.0测试(带returnUrl),生产环境强烈推荐使用",
                        Description = "OAuth2.0测试(带returnUrl)",
                        Url         = "https://sdk.weixin.senparc.com/oauth2?returnUrl=" + returnUrl.UrlEncode(),
                        PicUrl      = "https://sdk.weixin.senparc.com/Images/qrcode.jpg"
                    });

                reponseMessage = strongResponseMessage;
            }
            break;

            case "Description":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = GetWelcomeInfo();
                reponseMessage = strongResponseMessage;
            }
            break;

            case "SubClickRoot_PicPhotoOrAlbum":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "您点击了【微信拍照】按钮。系统将会弹出拍照或者相册发图。";
            }
            break;

            case "SubClickRoot_ScancodePush":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "您点击了【微信扫码】按钮。";
            }
            break;

            case "ConditionalMenu_Male":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "您点击了个性化菜单按钮,您的微信性别设置为:男。";
            }
            break;

            case "ConditionalMenu_Femle":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "您点击了个性化菜单按钮,您的微信性别设置为:女。";
            }
            break;

            case "GetNewMediaId":    //获取新的MediaId
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                try
                {
                    var result = AdvancedAPIs.MediaApi.UploadForeverMedia(appId, ServerUtility.ContentRootMapPath("~/Images/logo.jpg"));
                    strongResponseMessage.Content = result.media_id;
                }
                catch (Exception e)
                {
                    strongResponseMessage.Content = "发生错误:" + e.Message;
                    WeixinTrace.SendCustomLog("调用UploadForeverMedia()接口发生异常", e.Message);
                }
            }
            break;

            default:
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                strongResponseMessage.Content = "您点击了按钮,EventKey:" + requestMessage.EventKey;
                reponseMessage = strongResponseMessage;
            }
            break;
            }

            return(reponseMessage);
        }
Esempio n. 5
0
        /// <summary>
        /// 执行NeuChar判断过程,获取响应消息
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <param name="messageHandler"></param>
        /// <param name="accessTokenOrApi"></param>
        /// <returns></returns>
        public async Task <IResponseMessageBase> ExecuteAsync <TC, TRequest, TResponse>(IRequestMessageBase requestMessage, IMessageHandlerWithContext <TC, TRequest, TResponse> messageHandler,
                                                                                        string accessTokenOrApi)
            where TC : class, IMessageContext <TRequest, TResponse>, new()
            where TRequest : class, IRequestMessageBase
            where TResponse : class, IResponseMessageBase
        {
            //SenparcTrace.SendCustomLog("neuchar trace","1");
            //if (accessTokenOrApi == null)
            //{
            //    throw new ArgumentNullException(nameof(accessTokenOrApi));
            //}

            if (messageHandler == null)
            {
                throw new ArgumentNullException(nameof(messageHandler));
            }

            var messageHandlerEnlightener = messageHandler.MessageEntityEnlightener;
            var appDataNode = messageHandler.CurrentAppDataNode;

            IResponseMessageBase responseMessage = null;

            //SenparcTrace.SendCustomLog("neuchar trace", "3");

            //进行APP特殊处理

            //判断状态
            var context = await messageHandler.GetCurrentMessageContext();

            AppDataItem currentAppDataItem = null;

            switch (context.AppStoreState)
            {
            case AppStoreState.None:    //未进入任何应用
            case AppStoreState.Exit:
                currentAppDataItem = null;
                break;

            case AppStoreState.Enter:
                //判断是否已过期
                if (context.CurrentAppDataItem != null)
                {
                    if (context.LastActiveTime.HasValue && context.LastActiveTime.Value.AddMinutes(context.CurrentAppDataItem.MessageKeepTime) < SystemTime.Now)
                    {
                        //没有上一条活动,或者对话已过期,则设置为退出状态
                        context.AppStoreState      = AppStoreState.None;
                        context.CurrentAppDataItem = null;                                            //退出清空
                        await messageHandler.GlobalMessageContext.UpdateMessageContextAsync(context); //储存到缓存
                    }
                    else
                    {
                        //继续保持应用状态
                        currentAppDataItem = context.CurrentAppDataItem;

                        if (requestMessage is IRequestMessageText || requestMessage is IRequestMessageEventKey requestClick)
                        {
                            var content = (requestMessage is IRequestMessageText requestText) ? requestText.Content : (requestMessage as IRequestMessageEventKey).EventKey;
                            if (!context.CurrentAppDataItem.MessageExitWord.IsNullOrEmpty() && context.CurrentAppDataItem.MessageExitWord.Equals(content, StringComparison.OrdinalIgnoreCase))
                            {
                                //执行退出命令
                                context.AppStoreState      = AppStoreState.None;
                                context.CurrentAppDataItem = null;                                            //退出清空
                                                                                                              //currentAppDataItem = context.CurrentAppDataItem;//当前消息仍然转发(最后一条退出消息)
                                await messageHandler.GlobalMessageContext.UpdateMessageContextAsync(context); //储存到缓存
                            }
                        }
                    }
                }
                else
                {
                    //已经进入App状态,但是没有标记退出,此处强制退出
                    context.AppStoreState = AppStoreState.None;
                    await messageHandler.GlobalMessageContext.UpdateMessageContextAsync(context);    //储存到缓存
                }
                break;

            default:
                break;
            }

            //TODO:暂时限定类型

            if (currentAppDataItem == null)
            {
                if (requestMessage is IRequestMessageText || requestMessage is IRequestMessageEventKey requestClick)
                {
                    var content = (requestMessage is IRequestMessageText requestText) ? requestText.Content : (requestMessage as IRequestMessageEventKey).EventKey;

                    currentAppDataItem = appDataNode.Config.AppDataItems
                                         .FirstOrDefault(z => z.ExpireDateTime > SystemTime.Now && !z.MessageEnterWord.IsNullOrEmpty() && z.MessageEnterWord.Equals(content, StringComparison.OrdinalIgnoreCase));

                    if (currentAppDataItem != null && currentAppDataItem.MessageKeepTime > 0)
                    {
                        //初次进入应用
                        context.AppStoreState      = AppStoreState.Enter;
                        context.CurrentAppDataItem = currentAppDataItem;
                        await messageHandler.GlobalMessageContext.UpdateMessageContextAsync(context);//储存到缓存
                    }
                }
            }

            if (currentAppDataItem != null) //已经锁定某个App
            {
                //NeuralSystem.Instance.NeuCharDomainName = "https://www.neuchar.com";

                //转发AppData消息
                var neuCharUrl = $"{NeuralSystem.Instance.NeuCharDomainName}/App/Weixin?appId={currentAppDataItem.Id}&neuralAppId={appDataNode.NeuralAppId}";
                try
                {
                    IServiceProvider serviceProvider = null;
#if !NET45
                    try
                    {
                        serviceProvider = Senparc.CO2NET.SenparcDI.GetServiceProvider();
                    }
                    catch (Exception ex)
                    {
                        Senparc.CO2NET.Trace.SenparcTrace.SendCustomLog("MessageHandlerNode 中 serviceProvider 未设置成功", ex.Message);
                    }
#endif
                    responseMessage = MessageAgent.RequestResponseMessage(messageHandler, serviceProvider, neuCharUrl, "Senparc", requestMessage.ConvertEntityToXmlString());
                }
                catch (Exception ex)
                {
                    Senparc.CO2NET.Trace.SenparcTrace.SendCustomLog("NeuChar 远程调用 APP 失败", ex.Message);
                }
            }


            //APP特殊处理结束


            if (responseMessage != null)
            {
                if (messageHandler.MessageEntityEnlightener.PlatformType == PlatformType.WeChat_MiniProgram && responseMessage is IResponseMessageText)
                {
                    //小程序
                    messageHandler.ApiEnlightener.SendText(accessTokenOrApi, messageHandler.WeixinOpenId, (responseMessage as IResponseMessageText).Content);
                    return(new SuccessResponseMessage());
                }
                else
                {
                    return(responseMessage);
                }
            }

            //处理普通消息回复
            switch (requestMessage.MsgType)
            {
            case RequestMsgType.Text:
            {
                try
                {
                    //SenparcTrace.SendCustomLog("neuchar trace", "3.1");

                    var textRequestMessage = requestMessage as IRequestMessageText;

                    //遍历所有的消息设置
                    foreach (var messagePair in Config.MessagePair.Where(z => z.Request.Type == RequestMsgType.Text))
                    {
                        //遍历每一个消息设置中的关键词
                        var pairSuccess = messagePair.Request.Keywords.Exists(keyword => keyword.Equals(textRequestMessage.Content, StringComparison.OrdinalIgnoreCase));
                        if (pairSuccess)
                        {
                            responseMessage = await GetResponseMessage(requestMessage, messagePair.Responses, messageHandler, accessTokenOrApi);
                        }

                        if (responseMessage != null)
                        {
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    SenparcTrace.SendCustomLog("neuchar text error", ex.Message + "\r\n|||\r\n" + (ex.InnerException != null ? ex.InnerException.ToString() : ""));
                }
            }
            break;

            case RequestMsgType.Image:
            {
                var imageRequestMessage = requestMessage as IRequestMessageImage;
                //遍历所有的消息设置

                foreach (var messagePair in Config.MessagePair.Where(z => z.Request.Type == RequestMsgType.Image))
                {
                    responseMessage = await GetResponseMessage(requestMessage, messagePair.Responses, messageHandler, accessTokenOrApi);

                    if (responseMessage != null)
                    {
                        break;
                    }
                }
            }
            break;

            case RequestMsgType.Event:
            {
                //菜单或其他系统事件
                if (requestMessage is IRequestMessageEvent eventRequestMessage)
                {
                    var eventType = eventRequestMessage.EventName.ToUpper();

                    //构造返回结果
                    List <Response> responses = new List <Response>();


                    switch (eventType)
                    {
                    case "CLICK" when requestMessage is IRequestMessageEventKey clickRequestMessage:
                    {
                        //TODO:暂时只支持CLICK,因此在这里遍历
                        foreach (var messagePair in Config.MessagePair.Where(z => z.Request.Type == RequestMsgType.Event))
                        {
                            var pairSuccess = messagePair.Request.Keywords.Exists(keyword => keyword.Equals(clickRequestMessage.EventKey, StringComparison.OrdinalIgnoreCase));
                            if (pairSuccess)
                            {
                                try
                                {
                                    responseMessage = await GetResponseMessage(requestMessage, messagePair.Responses, messageHandler, accessTokenOrApi);
                                }
                                catch (Exception ex)
                                {
                                    SenparcTrace.SendCustomLog("CLICK 跟踪 1.1", ex.Message + "\r\n" + ex.StackTrace);
                                }
                            }

                            if (responseMessage != null)
                            {
                                break;
                            }
                        }
                    }
                    break;

                    default:
                        break;
                    }
                }
                else
                {
                    //下级模块中没有正确处理 requestMessage 类型
                }
            }
            break;

            default:
                //不作处理

                //throw new UnknownRequestMsgTypeException("NeuChar未支持的的MsgType请求类型:"+ requestMessage.MsgType, null);
                break;
            }
            //SenparcTrace.SendCustomLog("neuchar trace", "4");

            return(responseMessage);
        }
        public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage)
        {
            IResponseMessageBase reponseMessage = null;

            //菜单点击,需要跟创建菜单时的Key匹配
            switch (requestMessage.EventKey)
            {
            case "OneClick":
            {
                //这个过程实际已经在OnTextOrEventRequest中完成,这里不会执行到。
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "您点击了底部按钮。\r\n为了测试微信软件换行bug的应对措施,这里做了一个——\r\n换行";
            }
            break;

            case "telphone":
            {
                //这个过程实际已经在OnTextOrEventRequest中完成,这里不会执行到。
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "02168409571";
            }
            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       = "您点击了子菜单图文按钮222",
                        Description = "您点击了子菜单图文按钮,这是一条图文信息33。",
                        PicUrl      = "http://weixin.senparc.com/Images/qrcode.jpg",
                        Url         = "http://weixin.senparc.com"
                    });
            }
            break;

            //case "SubClickRoot_Music":
            //    {
            //        //上传缩略图
            //        var accessToken = CommonAPIs.AccessTokenContainer.TryGetToken(appId, appSecret);
            //        var uploadResult = AdvancedAPIs.Media.MediaApi.UploadTemporaryMedia(accessToken, UploadMediaFileType.thumb,
            //                                                     Server.GetMapPath("~/Images/Logo.jpg"));
            //        //设置音乐信息
            //        var strongResponseMessage = CreateResponseMessage<ResponseMessageMusic>();
            //        reponseMessage = strongResponseMessage;
            //        strongResponseMessage.Music.Title = "天籁之音";
            //        strongResponseMessage.Music.Description = "真的是天籁之音";
            //        strongResponseMessage.Music.MusicUrl = "http://weixin.senparc.com/Content/music1.mp3";
            //        strongResponseMessage.Music.HQMusicUrl = "http://weixin.senparc.com/Content/music1.mp3";
            //        strongResponseMessage.Music.ThumbMediaId = uploadResult.thumb_media_id;
            //    }
            //    break;
            //case "SubClickRoot_Image":
            //    {
            //        //上传图片
            //        var accessToken = CommonAPIs.AccessTokenContainer.TryGetToken(appId, appSecret);
            //        var uploadResult = AdvancedAPIs.Media.MediaApi.UploadTemporaryMedia(accessToken, UploadMediaFileType.image,
            //                                                     Server.GetMapPath("~/Images/Logo.jpg"));
            //        //设置图片信息
            //        var strongResponseMessage = CreateResponseMessage<ResponseMessageImage>();
            //        reponseMessage = strongResponseMessage;
            //        strongResponseMessage.Image.MediaId = uploadResult.media_id;
            //    }
            //    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 "Description":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageNews>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Articles.Add(new Article()
                    {
                        Title       = "您点击了子菜单图文按钮111",
                        Description = "您点击了子菜单图文按钮,这是一条图文信息。",
                        PicUrl      = "http://weixin.senparc.com/Images/qrcode.jpg",
                        Url         = "http://weixin.senparc.com"
                    });
            }
            break;

            case "SubClickRoot_PicPhotoOrAlbum":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "您点击了【微信拍照】按钮。系统将会弹出拍照或者相册发图。";
            }
            break;

            case "SubClickRoot_ScancodePush":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "您点击了【微信扫码】按钮。";
            }
            break;

            default:
            {
                reponseMessage = this.Robet(requestMessage.EventKey);
            }
            break;
            }

            return(reponseMessage);
        }
Esempio n. 7
0
        public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage)
        {
            IResponseMessageBase reponseMessage = null;

            //菜单点击,需要跟创建菜单时的Key匹配
            switch (requestMessage.EventKey)
            {
            case "OneClick":
            {
                //这个过程实际已经在OnTextOrEventRequest中完成,这里不会执行到。
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "hello world!!!!您点击了底部按钮。\r\n为了测试微信软件换行bug的应对措施,这里做了一个——\r\n换行";
            }
            break;

            case "SubClickRoot_Text":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "hello祖爷 你好啊!!!!您点击了子菜单按钮。";
            }
            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"
                    });
                strongResponseMessage.Articles.Add(new Article()
                    {
                        Title       = "2祖爷 你好啊!!!!您点击了子菜单图文按钮",
                        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;
            }

            return(reponseMessage);
        }
        public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage)
        {
            IResponseMessageBase reponseMessage = null;

            //菜单点击,需要跟创建菜单时的Key匹配
            switch (requestMessage.EventKey)
            {
            case "OneClick":
            {
                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_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注意:此页面仅供测试,测试号随时可能过期。请将此DEMO部署到您自己的服务器上,并使用自己的appid和secret。",
                        Url         = "http://weixin.senparc.com/oauth2",
                    });
                reponseMessage = strongResponseMessage;
            }
            break;
            }

            return(reponseMessage);
        }
Esempio n. 9
0
        public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage)
        {
            IResponseMessageBase reponseMessage = null;

            //菜单点击,需要跟创建菜单时的Key匹配
            switch (requestMessage.EventKey)
            {
            case "Near":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "您点击了底部按钮。\r\n为了测试微信软件换行bug的应对措施,这里做了一个——\r\n换行";
            }
            break;

            case "ContactUs":
            {
                MpUser fromUser = MpUserService.GetByOpenID(requestMessage.FromUserName);
                if (fromUser != null)
                {
                    Client.StartKfMeeting(fromUser.Id);
                }
                return(null);
            }
            break;

            case "NearBy":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageText>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Content = "首先切换到对话模式,看到输入框旁边那个“+”了没,选择“位置”后点击“发送”,即可查询周边网点信息。";
            }
            break;

            case "SubClickRoot_Music":
            {
                var strongResponseMessage = CreateResponseMessage <ResponseMessageMusic>();
                reponseMessage = strongResponseMessage;
                strongResponseMessage.Music.MusicUrl = "http://weixin.senparc.com/Content/music1.mp3";
            }
            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注意:此页面仅供测试,测试号随时可能过期。请将此DEMO部署到您自己的服务器上,并使用自己的appid和secret。",
                        Url         = "http://weixin.senparc.com/oauth2",
                    });
                reponseMessage = strongResponseMessage;
            }
            break;
            }

            return(reponseMessage);
        }