Ejemplo n.º 1
0
        /// <summary>
        /// 取微信粉丝,先取列表,再更新详情
        /// </summary>
        /// <returns></returns>
        public ResponseBase PullFans()
        {
            ResponseBase response = new ResponseBase();

            response.ErrorCode = "A_0";
            try
            {
                string temp = string.Empty;
                temp = HttpAspxPostHtmlInfo(string.Format(GET_ACCESS_TOKEN_URL, System.Configuration.ConfigurationManager.AppSettings["APPID"], System.Configuration.ConfigurationManager.AppSettings["APPSECRET"]), "", "get");
                System.Collections.Hashtable ht = new System.Collections.Hashtable();
                ht = (System.Collections.Hashtable)PluSoft.Utils.JSON.Decode(temp, ht.GetType());
                if (!ht.ContainsKey("access_token"))
                {
                    response.ErrorCode    = "A_" + ht["errcode"].ToString();
                    response.ErrorMessage = ht["errmsg"].ToString();
                    return(response);
                }
                string nextOpenID = "";
                int    curCount   = 0;
                temp = HttpAspxPostHtmlInfo(string.Format(GET_USER_LIST_URL, ht.ContainsKey("access_token"), nextOpenID), "", "get");
                DTO.WCUserList userList = new WCUserList();
                userList = (DTO.WCUserList)PluSoft.Utils.JSON.Decode(temp, userList.GetType());
                DAL.cOtherDAL dal = new DAL.cOtherDAL(con);
                curCount += userList.count;
                //循环取OpenID列表并写入数据库
                while (userList.total > curCount)
                {
                    nextOpenID = userList.next_openid;
                    temp       = HttpAspxPostHtmlInfo(string.Format(GET_USER_LIST_URL, ht.ContainsKey("access_token"), nextOpenID), "", "get");
                    userList   = (DTO.WCUserList)PluSoft.Utils.JSON.Decode(temp, userList.GetType());
                    dal.AddOpenIDList(userList.data.openid);
                    curCount += userList.count;
                }
                //循环从数据库中读取1周未更新的前三十条openID,并更新其信息
                List <string> openIDList = dal.GetOpenIDListNeedUpdate(7);
                StringBuilder sb         = new StringBuilder();
                while (openIDList.Count > 0)
                {
                    sb.Append("{\"user_list\":[");
                    //组装openID列表
                    foreach (string openID in openIDList)
                    {
                        sb.AppendFormat(GET_USER_INFO_REQUEST_DETAIL, openID);
                        sb.Append(",");
                    }
                    sb.Append("]}");
                    temp = HttpAspxPostHtmlInfo(string.Format(GET_USER_INFO_URL, ht.ContainsKey("access_token")), sb.ToString(), "post");
                    List <DTO.LWechatFanQuery> data = new List <LWechatFanQuery>();
                    data = (List <DTO.LWechatFanQuery>)JsonHelper.JsonToObject(temp, data.GetType());
                    dal.UpdateUserInfoList(data);
                    openIDList = dal.GetOpenIDListNeedUpdate(7);
                }
            }
            catch
            {
                response.ErrorCode = "A_444444";
            }
            response.ErrorMessage = rm.GetString(response.ErrorCode);
            return(response);
        }