日期:2014-05-16  浏览次数:20985 次

mvc 实现微信公众号主动推送消息
去年做的项目,去年还能用,但是今天来用,发现用不了了。
我的功能是  模拟登录,  获取用户fakeid ,然后循环发消息。现在不能用了。求大神解决。
这是获取用户fakeid的代码,请求的时候会报错。基础连接已经关闭: 发送时发生错误

/// <summary>
        /// 获取用户ID
        /// </summary>
        /// <param name="count">需要获取的用户数</param>
        /// <param name="pageidx">当前页(默认为0)</param>
        /// <param name="groupid">分组ID(默认为0,表示未分组的用户)</param>
        /// <returns></returns>
        public static ArrayList SubscribeMP(int? pagesize, int? pageidx, int? groupid)
        {
            try
            {
                /*获取用户信息的url,这里有几个参数给大家讲一下,1.token此参数为上面的token 2.pagesize此参数为每一页显示的记录条数3.pageid为当前的页数,4.groupid为微信公众平台的用户分组的组id*/
                CookieContainer cookie = null;
                string token = null;
                cookie = WeiXinLoginCookie.LoginCookie;//取得cookie
                token = WeiXinLoginCookie.Token;//取得token
                string Url = " https://mp.weixin.qq.com/cgi-bin/contactmanage?t=user/index&pagesize=" + pagesize + "&pageidx=" + pageidx + "&type=0&token=" + token + "&lang=zh_CN";
                HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(Url);
                webRequest2.CookieContainer = cookie;
                webRequest2.ContentType = "text/html; charset=UTF-8";
                webRequest2.Method = "GET";
                webRequest2.ContentType = "application/x-www-form-urlencoded";
                webRequest2.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1";
                //webRequest2.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36";
                HttpWebResponse response2 = (HttpWebResponse)