Esempio n. 1
0
        /// <summary>
        /// 获取关注者列表
        /// </summary>
        /// <param name="AttentionsList">返回关注的列表</param>
        /// <param name="NextOpenId">超过一万时最后一个关注OPENID</param>
        /// <returns></returns>
        public static WeiXinResult GetAttentions(ref List <string> AttentionsList, string NextOpenId)
        {
            WeiXinResult          AttentionsResult = new WeiXinResult();
            IMpClient             mpClient         = new MpClient();
            AccessTokenGetRequest request          = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                AttentionsResult.IsResult  = false;
                AttentionsResult.ResultMsg = "获取令牌环失败";
                return(AttentionsResult);
            }
            string AccessToken            = response.AccessToken.AccessToken;
            GetAttentionsRequest request2 = new GetAttentionsRequest()
            {
                AccessToken = AccessToken,
                NextOpenId  = NextOpenId
            };

            var response2 = mpClient.Execute(request2);

            if (response2.IsError)
            {
                AttentionsResult.IsResult  = false;
                AttentionsResult.ResultMsg = "获取关注者列表失败,错误信息为:" + response2.ErrInfo.ErrCode + "-" + response2.ErrInfo.ErrMsg;
                return(AttentionsResult);
            }
            else
            {
                var list = response2.Attentions;
                if (list.total > 0)
                {
                    if (list.data.openid.Count > 0)
                    {
                        AttentionsList.AddRange(list.data.openid);
                        if (list.total > 10000 && !String.IsNullOrEmpty(list.next_openid))//超过一万
                        {
                            return(GetAttentions(ref AttentionsList, list.next_openid));
                        }
                        else
                        {
                            // Adpost.Finawin.Utility.ConfigClass.SetConfigKeyValue("next_openid", list.next_openid);
                            AttentionsResult.IsResult  = true;
                            AttentionsResult.ResultMsg = "获取关注者列表成功";
                            return(AttentionsResult);
                        }
                    }
                    else
                    {
                        AttentionsResult.IsResult  = false;
                        AttentionsResult.ResultMsg = "无关注者数据";
                        return(AttentionsResult);
                    }
                }
                else
                {
                    AttentionsResult.IsResult  = false;
                    AttentionsResult.ResultMsg = "无关注者数据";
                    return(AttentionsResult);
                }
            }
        }
Esempio n. 2
0
File: WinXin.cs Progetto: uwitec/O2O
        /// <summary>
        /// 获取关注者列表
        /// </summary>
        /// <param name="AttentionsList">返回关注的列表</param>
        /// <param name="NextOpenId">超过一万时最后一个关注OPENID</param>
        /// <returns></returns>
        public static WeiXinResult GetAttentions(ref List<string> AttentionsList, string NextOpenId)
        {
            WeiXinResult AttentionsResult = new WeiXinResult();
            IMpClient mpClient = new MpClient();
            AccessTokenGetRequest request = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo() { AppID = appId, AppSecret = appSecret }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);
            if (response.IsError)
            {
                AttentionsResult.IsResult = false;
                AttentionsResult.ResultMsg = "获取令牌环失败";
                return AttentionsResult;

            }
            string AccessToken = response.AccessToken.AccessToken;
            GetAttentionsRequest request2 = new GetAttentionsRequest()
            {
                AccessToken = AccessToken,
                NextOpenId = NextOpenId
            };

            var response2 = mpClient.Execute(request2);
            if (response2.IsError)
            {
                AttentionsResult.IsResult = false;
                AttentionsResult.ResultMsg = "获取关注者列表失败,错误信息为:" + response2.ErrInfo.ErrCode + "-" + response2.ErrInfo.ErrMsg;
                return AttentionsResult;
            }
            else
            {
                var list = response2.Attentions;
                if (list.total > 0)
                {
                    if (list.data.openid.Count > 0)
                    {
                        AttentionsList.AddRange(list.data.openid);
                        if (list.total > 10000 && !String.IsNullOrEmpty(list.next_openid))//超过一万
                        {
                            return GetAttentions(ref AttentionsList, list.next_openid);
                        }
                        else
                        {
                            // Adpost.Finawin.Utility.ConfigClass.SetConfigKeyValue("next_openid", list.next_openid);
                            AttentionsResult.IsResult = true;
                            AttentionsResult.ResultMsg = "获取关注者列表成功";
                            return AttentionsResult;
                        }
                    }
                    else
                    {
                        AttentionsResult.IsResult = false;
                        AttentionsResult.ResultMsg = "无关注者数据";
                        return AttentionsResult;
                    }
                }
                else
                {
                    AttentionsResult.IsResult = false;
                    AttentionsResult.ResultMsg = "无关注者数据";
                    return AttentionsResult;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 创建菜单
        /// </summary>
        public static WeiXinResult CreateMenu()
        {
            WeiXinResult rv = new WeiXinResult {
                IsResult = false, ResultMsg = "系统错误!"
            };
            IMpClient             mpClient = new MpClient();
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                rv.ResultMsg = "获取令牌环失败";
                return(rv);
            }
            else
            {
                Menu          menu   = new Menu();
                List <Button> button = new List <Weixin.Mp.Sdk.Domain.Button>();
                #region 菜单一 产品中心
                Button subBtn1 = new Button()
                {
                    key        = "guoneiyou",
                    name       = "国内游",
                    sub_button = null,
                    type       = "view",
                    url        = "http://www.4008005216.com/AppPage/weixin/ProductView.aspx?xianlu=0"
                };
                Button subBtn2 = new Button()
                {
                    key        = "guojiyou",
                    name       = "国际游",
                    sub_button = null,
                    type       = "view",
                    url        = "http://www.4008005216.com/AppPage/weixin/ProductView.aspx?xianlu=1"
                };
                Button subBtn3 = new Button()
                {
                    key        = "chanpintuijian",
                    name       = "产品推荐",
                    sub_button = null,
                    type       = "view",
                    url        = "http://www.4008005216.com/AppPage/weixin/ProductList.aspx?tuijian=1"
                };
                Button subBtn4 = new Button()
                {
                    key        = "chanpinmachaxun",
                    name       = "产品码查询",
                    sub_button = null,
                    type       = "click",
                    url        = "http://www.4008005216.com/AppPage/weixin/Register.aspx"
                };

                Button subBtn5 = new Button()
                {
                    key        = "guoneijipiao",
                    name       = "国内机票",
                    sub_button = null,
                    type       = "view",
                    url        = "http://www.4008005216.com/AppPage/weixin/jp_Search.aspx"
                };
                List <Button> subBtnAll = new List <Button>();
                subBtnAll.Add(subBtn1);
                subBtnAll.Add(subBtn2);
                subBtnAll.Add(subBtn3);
                subBtnAll.Add(subBtn4);
                subBtnAll.Add(subBtn5);
                Button btn = new Button()
                {
                    key        = "menu1",
                    name       = "旅游超市",
                    url        = "httpbig",
                    type       = "click",
                    sub_button = subBtnAll
                };
                button.Add(btn);

                #endregion
                #region 菜单二 会员中心
                Button Menu2SubBtn1 = new Button()
                {
                    key        = "dingdanguanli",
                    name       = "订单管理",
                    sub_button = null,
                    type       = "view",
                    url        = "http://www.4008005216.com/AppPage/weixin/OrderList.aspx"
                };
                Button Menu2SubBtn2 = new Button()
                {
                    key        = "zhanghuguanli",
                    name       = "账户管理",
                    sub_button = null,
                    type       = "view",
                    url        = "http://www.4008005216.com/AppPage/weixin/updateUser.aspx"
                };
                Button Menu2SubBtn3 = new Button()
                {
                    key        = "yuyue",
                    name       = "预约办理",
                    sub_button = null,
                    type       = "view",
                    url        = "http://www.4008005216.com/AppPage/weixin/YuYue.aspx"
                };

                string _weidianurl = "https://open.weixin.qq.com/connect/oauth2/authorize?";
                _weidianurl += "appid=" + appId;
                _weidianurl += "&redirect_uri=http://www.4008005216.com/WeiXin/oauth2_authorize.aspx";
                _weidianurl += "&response_type=code";
                _weidianurl += "&scope=snsapi_base";
                _weidianurl += "&state=weidian_snsapi_base";
                _weidianurl += "#wechat_redirect";

                Button Menu2SubBtn4 = new Button()
                {
                    key        = "wodeweidian",
                    name       = "我的微店",
                    sub_button = null,
                    type       = "view",
                    url        = _weidianurl
                };
                Button Menu2SubBtn5 = new Button()
                {
                    key        = "fenxiang",
                    name       = "最新分享",
                    sub_button = null,
                    type       = "view",
                    url        = "http://www.4008005216.com/HuiYuanWeiXin/TuWenFenXiang.aspx"
                };
                List <Button> subBtnAll2 = new List <Button>();
                subBtnAll2.Add(Menu2SubBtn1);
                subBtnAll2.Add(Menu2SubBtn2);
                subBtnAll2.Add(Menu2SubBtn3);
                subBtnAll2.Add(Menu2SubBtn4);
                subBtnAll2.Add(Menu2SubBtn5);

                btn = new Button()
                {
                    key        = "huiyuanzhongxin",
                    name       = "会员中心",
                    url        = "httpbig",
                    type       = "click",
                    sub_button = subBtnAll2
                };
                button.Add(btn);

                #endregion
                #region 菜单三 惠旅游
                Button Menu3SubBtn1 = new Button()
                {
                    key        = "aboutus",
                    name       = "关于我们",
                    sub_button = null,
                    type       = "view",
                    url        = "http://www.4008005216.com/AppPage/weixin/AboutUs.aspx"
                };
                Button Menu3SubBtn2 = new Button()
                {
                    key        = "appdown",
                    name       = "APP下载",
                    sub_button = null,
                    type       = "view",
                    url        = "http://www.4008005216.com/DownApp.aspx"
                };
                Button Menu3SubBtn3 = new Button()
                {
                    key        = "recommend",
                    name       = "客服反馈",
                    sub_button = null,
                    type       = "click",
                    url        = "http://www.4008005216.com/AppPage/weixin/Recommend.aspx"
                };

                Button Menu3SubBtn4 = new Button()
                {
                    key        = "weimingpian",
                    name       = "我的频道",
                    sub_button = null,
                    type       = "view",
                    url        = "http://www.4008005216.com/huiyuanweixin/mingpian.aspx"
                };

                Button Menu3SubBtn5 = new Button()
                {
                    key        = "lvyouguwen",
                    name       = "旅游顾问",
                    sub_button = null,
                    type       = "view",
                    url        = "http://www.4008005216.com/huiyuanweixin/lvyouguwen.aspx"
                };

                List <Button> subBtnAll3 = new List <Button>();
                subBtnAll3.Add(Menu3SubBtn1);
                subBtnAll3.Add(Menu3SubBtn2);
                subBtnAll3.Add(Menu3SubBtn3);

                subBtnAll3.Add(Menu3SubBtn4);
                subBtnAll3.Add(Menu3SubBtn5);

                btn = new Button()
                {
                    key        = "menu3",
                    name       = "旅游频道",
                    url        = "httpbig",
                    type       = "click",
                    sub_button = subBtnAll3
                };
                button.Add(btn);
                #endregion
                menu.button = button;
                MenuGroup mg = new MenuGroup()
                {
                    menu = menu
                };
                string            postData      = mg.ToJsonString();
                CreateMenuRequest createRequest = new CreateMenuRequest()
                {
                    AccessToken = response.AccessToken.AccessToken,
                    SendData    = postData
                };
                CreateMenuResponse createResponse = mpClient.Execute(createRequest);
                if (createResponse.IsError)
                {
                    rv.ResultMsg = "创建菜单失败,错误信息为:" + createResponse.ErrInfo.ErrCode + "-" + createResponse.ErrInfo.ErrMsg;
                    return(rv);
                }
                else
                {
                    rv.IsResult  = true;
                    rv.ResultMsg = "创建成功";
                    return(rv);
                }
            }
        }
Esempio n. 4
0
File: WinXin.cs Progetto: uwitec/O2O
        /// <summary>
        /// 创建菜单
        /// </summary>
        public static WeiXinResult CreateMenu()
        {
            WeiXinResult rv = new WeiXinResult { IsResult = false, ResultMsg = "系统错误!" };
            IMpClient mpClient = new MpClient();
            AccessTokenGetRequest request = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo() { AppID = appId, AppSecret = appSecret }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);
            if (response.IsError)
            {
                rv.ResultMsg = "获取令牌环失败";
                return rv;
            }
            else
            {
                Menu menu = new Menu();
                List<Button> button = new List<Weixin.Mp.Sdk.Domain.Button>();
                #region 菜单一 产品中心
                Button subBtn1 = new Button()
                {
                    key = "guoneiyou",
                    name = "国内游",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/ProductView.aspx?xianlu=0"
                };
                Button subBtn2 = new Button()
                {
                    key = "guojiyou",
                    name = "国际游",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/ProductView.aspx?xianlu=1"

                };
                Button subBtn3 = new Button()
                {
                    key = "chanpintuijian",
                    name = "产品推荐",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/ProductList.aspx?tuijian=1"
                };
                Button subBtn4 = new Button()
                {
                    key = "chanpinmachaxun",
                    name = "产品码查询",
                    sub_button = null,
                    type = "click",
                    url = "http://www.4008005216.com/AppPage/weixin/Register.aspx"
                };

                Button subBtn5 = new Button()
                {
                    key = "guoneijipiao",
                    name = "国内机票",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/jp_Search.aspx"
                };
                List<Button> subBtnAll = new List<Button>();
                subBtnAll.Add(subBtn1);
                subBtnAll.Add(subBtn2);
                subBtnAll.Add(subBtn3);
                subBtnAll.Add(subBtn4);
                subBtnAll.Add(subBtn5);
                Button btn = new Button()
                {
                    key = "menu1",
                    name = "旅游超市",
                    url = "httpbig",
                    type = "click",
                    sub_button = subBtnAll
                };
                button.Add(btn);

                #endregion
                #region 菜单二 会员中心
                Button Menu2SubBtn1 = new Button()
                {
                    key = "dingdanguanli",
                    name = "订单管理",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/OrderList.aspx"
                };
                Button Menu2SubBtn2 = new Button()
                {
                    key = "zhanghuguanli",
                    name = "账户管理",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/updateUser.aspx"
                };
                Button Menu2SubBtn3 = new Button()
                {
                    key = "yuyue",
                    name = "预约办理",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/YuYue.aspx"
                };

                string _weidianurl = "https://open.weixin.qq.com/connect/oauth2/authorize?";
                _weidianurl += "appid=" + appId;
                _weidianurl += "&redirect_uri=http://www.4008005216.com/WeiXin/oauth2_authorize.aspx";
                _weidianurl += "&response_type=code";
                _weidianurl += "&scope=snsapi_base";
                _weidianurl += "&state=weidian_snsapi_base";
                _weidianurl += "#wechat_redirect";

                Button Menu2SubBtn4 = new Button()
                {
                    key = "wodeweidian",
                    name = "我的微店",
                    sub_button = null,
                    type = "view",
                    url = _weidianurl
                };
                Button Menu2SubBtn5 = new Button()
                {
                    key = "fenxiang",
                    name = "最新分享",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/HuiYuanWeiXin/TuWenFenXiang.aspx"
                };
                List<Button> subBtnAll2 = new List<Button>();
                subBtnAll2.Add(Menu2SubBtn1);
                subBtnAll2.Add(Menu2SubBtn2);
                subBtnAll2.Add(Menu2SubBtn3);
                subBtnAll2.Add(Menu2SubBtn4);
                subBtnAll2.Add(Menu2SubBtn5);

                btn = new Button()
                {
                    key = "huiyuanzhongxin",
                    name = "会员中心",
                    url = "httpbig",
                    type = "click",
                    sub_button = subBtnAll2
                };
                button.Add(btn);

                #endregion
                #region 菜单三 惠旅游
                Button Menu3SubBtn1 = new Button()
                {
                    key = "aboutus",
                    name = "关于我们",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/AboutUs.aspx"
                };
                Button Menu3SubBtn2 = new Button()
                {
                    key = "appdown",
                    name = "APP下载",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/DownApp.aspx"
                };
                Button Menu3SubBtn3 = new Button()
                {
                    key = "recommend",
                    name = "客服反馈",
                    sub_button = null,
                    type = "click",
                    url = "http://www.4008005216.com/AppPage/weixin/Recommend.aspx"
                };

                Button Menu3SubBtn4 = new Button()
                {
                    key = "weimingpian",
                    name = "我的频道",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/huiyuanweixin/mingpian.aspx"
                };

                Button Menu3SubBtn5 = new Button()
                {
                    key = "lvyouguwen",
                    name = "旅游顾问",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/huiyuanweixin/lvyouguwen.aspx"
                };

                List<Button> subBtnAll3 = new List<Button>();
                subBtnAll3.Add(Menu3SubBtn1);
                subBtnAll3.Add(Menu3SubBtn2);
                subBtnAll3.Add(Menu3SubBtn3);

                subBtnAll3.Add(Menu3SubBtn4);
                subBtnAll3.Add(Menu3SubBtn5);

                btn = new Button()
                {
                    key = "menu3",
                    name = "旅游频道",
                    url = "httpbig",
                    type = "click",
                    sub_button = subBtnAll3
                };
                button.Add(btn);
                #endregion
                menu.button = button;
                MenuGroup mg = new MenuGroup()
                {
                    menu = menu
                };
                string postData = mg.ToJsonString();
                CreateMenuRequest createRequest = new CreateMenuRequest()
                {
                    AccessToken = response.AccessToken.AccessToken,
                    SendData = postData
                };
                CreateMenuResponse createResponse = mpClient.Execute(createRequest);
                if (createResponse.IsError)
                {
                    rv.ResultMsg = "创建菜单失败,错误信息为:" + createResponse.ErrInfo.ErrCode + "-" + createResponse.ErrInfo.ErrMsg;
                    return rv;
                }
                else
                {
                    rv.IsResult = true;
                    rv.ResultMsg = "创建成功";
                    return rv;
                }
            }
        }