Exemplo n.º 1
0
        protected override IWRespBase DoForRequest_Event_Subscribe(WReqEventSubscribe request)
        {
            if (user != null)
            {
                TxtLogServices.WriteTxtLogEx("WeiXinConversation", "DoForRequest_Event_Subscribe");
                user.FollowState       = (int)WxUserState.Attention;
                user.LastSubscribeDate = DateTime.Now;
                user.SubscribeTimes    = user.SubscribeTimes + 1;
                bool result = WeiXinAccountService.EditWXInfo(user);
                TxtLogServices.WriteTxtLogEx("WeiXinConversation", "DoForRequest_Event_Subscribe REsult:{0}", result?"1":"0");
            }
            var gResponse = RequestToKey.GoGKey(config, ReplyType.Subscribe, string.Empty, request);

            return(gResponse);
        }
Exemplo n.º 2
0
 public override void OnExecuting()
 {
     try
     {
         user = WeiXinAccountService.QueryWXByOpenId(OpenId);
         if (user == null || (WxUserState)user.FollowState == WxUserState.UnAttention)
         {
             bool IsNewAdd = user == null;
             user = WxUserInfo.GetWxUserBaseInfo(config, OpenId);
             if (user == null)
             {
                 TxtLogServices.WriteTxtLogEx("WeiXinConversation", "拉取微信用户信息失败,OPENID:{0}", OpenId);
                 return;
             }
             user.OpenID      = OpenId;
             user.UserType    = 0;
             user.FollowState = (int)WxUserState.Attention;
             user.CompanyID   = config.CompanyID;
             bool result = false;
             if (IsNewAdd)
             {
                 TxtLogServices.WriteTxtLogEx("WeiXinConversation", "RegisterAccount");
                 result = WeiXinAccountService.RegisterAccount(user);
                 TxtLogServices.WriteTxtLogEx("WeiXinConversation", string.Format("RegisterAccount Result:{0}", result ? "1" : "0"));
             }
             else
             {
                 TxtLogServices.WriteTxtLogEx("WeiXinConversation", "EditWXInfo");
                 result = WeiXinAccountService.EditWXInfo(user);
                 TxtLogServices.WriteTxtLogEx("WeiXinConversation", string.Format("EditWXInfo Result:{0}", result ? "1" : "0"));
             }
             if (result)
             {
                 user = WeiXinAccountService.QueryWXByOpenId(OpenId);
             }
             string resultDes = result ? "成功" : "失败";
             TxtLogServices.WriteTxtLogEx("WeiXinConversation", "保存微信用户信息{0},OPENID:{1}", resultDes, OpenId);
         }
         else
         {
             //每7天或头像为空时更新一次微信用户信息
             if (user.LastSubscribeDate < DateTime.Now.AddDays(-7) || string.IsNullOrWhiteSpace(user.Headimgurl))
             {
                 WX_Info newUser = WxUserInfo.GetWxUserBaseInfo(config, OpenId);
                 if (newUser == null)
                 {
                     TxtLogServices.WriteTxtLogEx("WeiXinConversation", "更新时拉取微信用户信息失败,OPENID:{0}", OpenId);
                     return;
                 }
                 TxtLogServices.WriteTxtLogEx("WeiXinConversation", "Update");
                 newUser.AccountID = user.AccountID;
                 newUser.OpenID    = OpenId;
                 newUser.UserType  = 0;
                 newUser.CompanyID = config.CompanyID;
                 bool result = WeiXinAccountService.EditWXInfo(newUser);
                 TxtLogServices.WriteTxtLogEx("WeiXinConversation", string.Format("Update Result:{0}", result ? "1" : "0"));
             }
         }
     }
     catch (Exception ex) {
         ExceptionsServices.AddExceptions(ex, string.Format("创建微信账号或者更新微信账号信息失败,OPENID:{0}", OpenId), LogFrom.WeiXin);
         TxtLogServices.WriteTxtLogEx("WeiXinConversation", ex);
     }
 }