Esempio n. 1
0
        public static string SyncOpenId(Guid sid)
        {
            WxOpenIds openIds = ElegantWM.WeiXin.Common.GetFanList(sid.ToString(), "");
            string fails = "ErrorList:";
            foreach (string oid in openIds.data.openid)
            {
                if (WMFactory.WXFans.GetCount(f => f.AccountId == sid && f.OpenId == oid) <= 0)
                {
                    WxFans wf = ElegantWM.WeiXin.Common.GetFanInfo(sid.ToString(), oid);
                    WX_Fans fan = new WX_Fans();
                    fan.OpenId = oid;
                    fan.AccountId = sid;
                    fan.NickName = wf.nickname;
                    fan.Sex = wf.sex;
                    fan.City = wf.city;
                    fan.Province = wf.province;
                    fan.Avatar = wf.headimgurl;
                    fan.CreateUser = "******";
                    if (!WMFactory.WXFans.Insert(fan))
                    {
                        fails += oid + ",";
                    }
                }
            }

            if (openIds.total <= openIds.count)
            {
                //说明没有更多了
            }

            return fails;
        }
Esempio n. 2
0
 /// <summary>
 /// 取消关注
 /// </summary>
 /// <param name="wxevent">事件</param>
 /// <param name="account">账号</param>
 private static void RemoveFans(WxEvent wxevent, Guid sid)
 {
     string openId = wxevent.FromUserName;
     IEnumerable<WX_Fans> fans = WMFactory.WXFans.FindByConditions(null, f => f.OpenId == openId && f.AccountId == sid, null);
     WX_Fans fan = new WX_Fans();
     if (fans != null && fans.Count() > 0)
     {
         fan = fans.FirstOrDefault();
         fan.ModifyUser = "******";
         fan.IsUsed = 1;
         WMFactory.WXFans.Update(fan);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 添加粉丝
 /// </summary>
 /// <param name="wxevent">事件</param>
 /// <param name="account">账号</param>
 private static void AddFans(WxEvent wxevent, WX_Account account)
 {
     string openId = wxevent.FromUserName;
     Guid sid = account.Id;
     IEnumerable<WX_Fans> fans = WMFactory.WXFans.FindByConditions(null, f => f.OpenId == openId && f.AccountId == sid, null);
     WX_Fans fan = new WX_Fans();
     if (fans != null && fans.Count() > 0)
     {
         fan = fans.FirstOrDefault();
         fan.ModifyUser = "******";
     }
     fan.OpenId = wxevent.FromUserName;
     fan.AccountId = account.Id;
     fan.CreateUser = "******";
     fan.IsUsed = 0;
     //将关注者插入到数据库
     if (account.IsAuthed == 1)
     {
         WxFans wxfan = Common.GetFanInfo(account.Id.ToString(), openId);
         if (wxfan != null)
         {
             fan.NickName = wxfan.nickname;
             fan.Avatar = wxfan.headimgurl;
             fan.City = wxfan.city;
             fan.Country = wxfan.country;
             fan.Province = wxfan.province;
             fan.Sex = wxfan.sex;
         }
     }
     if (fans != null && fans.Count() > 0)
         WMFactory.WXFans.Update(fan);
     else
         WMFactory.WXFans.Insert(fan);
 }