Example #1
0
 public static void LogBiz(Type t,BizMQ bo)
 {
     bo.TimeStamp = CommonHelper.GetLoggerDateTime(DateTime.Now);
     bo.LoggerName = CommonHelper.GetLoggerName(t);
     bo.HostName = CommonHelper.GetHostName();
     LogMQOP.SendMessage(bo);
 }
Example #2
0
 public static BizMQ GenBizIndex(Type t,string modelname, string openid, Guid useruuid, string message)
 {
     BizMQ index = new BizMQ(modelname, openid, useruuid, message);
     index.LoggerName = CommonHelper.GetLoggerName(t);
     index.TimeStamp = CommonHelper.GetLoggerDateTime(DateTime.Now);
     index.UserIP = CommonHelper.GetHostName();
     return index;
 }
Example #3
0
 public bool TestException()
 {
     BKLogger.LogErrorAsync(typeof(WeixinAPIController), new Exception("测试错误!" + DateTime.Now.ToString()));
     BizMQ obj = new BizMQ("log", "oYI97wWcPgbNVXrdm7NSNjT5qZYY", Guid.Parse("C51F3107-D823-493F-8103-6206DD41586F"), "天气不错");
     BKLogger.LogBizAsync(typeof(WeixinAPIController), obj);
     return true;
 }
        protected virtual async Task<ActionResult> LoginCallBack(string code, string state, string xueshengUrl,string jiaoshouUrl)
        {
            try
            {
                if (code == null)
                    return Content("code是空!");
                //LogHelper.LogInfoAsync(typeof(WeChatCallBackController), @"1\code=" + code);

                var config = BK.Configuration.BK_ConfigurationManager.GetConfig<WeixinConfig>();
                bool Isbinded = true;

                var openid = await WXAuthHelper.GetOpenIdWXCallBackAsync(config.WeixinAppId, config.WeixinAppSecret, code, async delegate (OAuthAccessTokenResult result)
                {
                    //是否需要绑定账号

                    using (UserRepository userRepository = new UserRepository())
                    {
                        //如果OPenid绑定了,就不需要再向微信请求userinfo的信息了.
                        //如果没有绑定,则需要刷新accesstoken,然后请求userinfo;并将userinfo存入redis。
                        Isbinded = await userRepository.IsUserOpenidExist(result.openid);
                    }

                    if (!Isbinded)
                        //如果没有绑定就要存储token信息
                        await WeChatCallBackControllerHelper.SaveOAuthUserTokenAsync(result);
                    return !Isbinded;//如果绑定了就不需要获取userinfo信息了
                }, async delegate (OAuthUserInfo user)
                {
                    //如果需要绑定用户信息则,此处存储用户信息
                    return await WeChatCallBackControllerHelper.SaveOAuthUserInfoToRedis(user);
                });
                //再次判断是否需要绑定

                //存入cookie供前端代码调用
                Response.Cookies["openid"].Value = openid;
                Response.Cookies["openid"].Expires = DateTime.Now.AddYears(1);


                //如果是tester则不管怎么样都要去注册。
                //可以通过wechat.51science.cn/weixinapi/addtester/?openid=xxx来添加
                //wechat.51science.cn/weixinapi/rmtester/?openid=xxx删除
                bool isToRegister = !Isbinded || await WXAuthHelper.IsTester(openid);
                //BKLogger.LogInfoAsync(typeof(MVCNeedWeixinCallBackBaseController), "isToRegister:"+isToRegister);
                //BKLogger.LogInfoAsync(typeof(MVCNeedWeixinCallBackBaseController), "Isbinded:" + Isbinded);
                if (!isToRegister)
                {
                    //记录用户行为
                    await UserLoginBehaviorOp.AddLoginCountAsync(openid);
                    await UserLoginBehaviorOp.AddUpdateLastLoginTimeAsync(openid);
                    //跳转到个人主页
                    UserInfo userinfo = null;
                    using (UserRepository userRepository = new UserRepository())
                    {
                        userinfo = await userRepository.GetUserInfoByOpenid(openid);
                    }

                    BKLogger.LogInfoAsync(typeof(MVCNeedWeixinCallBackBaseController), "userinfo:"+userinfo.uuid.ToString()+" type:"+userinfo.IsBusiness.Value.ToString());

                    BizMQ bizobj = new BizMQ("微信登陆", openid, userinfo.uuid,userinfo.Name+ " 登陆了!");
                    BKLogger.LogBizAsync(typeof(MVCNeedWeixinCallBackBaseController), bizobj);

                    //存cookie
                    var cookieResult = Response.Cookies["type"].Value = userinfo.IsBusiness.Value.ToString();
                    Response.Cookies["type"].Expires = DateTime.Now.AddYears(1);
                    Response.Cookies["uuid"].Value = userinfo.uuid.ToString();
                    Response.Cookies["uuid"].Expires = DateTime.Now.AddYears(1);

                    //LogHelper.LogInfoAsync(typeof(MVCNeedWeixinCallBackBaseController), cookieResult.ToString());
                    if (userinfo.IsBusiness.Value == 0)
                        return Redirect(jiaoshouUrl);
                    else
                        return Redirect(xueshengUrl);
                }
                else
                {
                    // login页面 
                    return Redirect(LOGIN_PAGE_URL);
                }

            }
            catch (Exception ex)
            {
                BKLogger.LogErrorAsync(typeof(MVCNeedWeixinCallBackBaseController), ex);
                return Content(ex.ToString());
            }
        }
Example #5
0
 public static BizIndex CopyFromBizMQ(BizMQ mq)
 {
     if (mq == null || string.IsNullOrEmpty(mq.Id) || Guid.Parse(mq.Id).Equals(Guid.Empty))
         return null;
     BizIndex ret = new BizIndex();
     foreach (System.Reflection.PropertyInfo pi in ret.GetType().GetProperties())
     {
         object value = mq.GetType().GetProperty(pi.Name).GetValue(mq);
         if(value!=null)
             pi.SetValue(ret, value);
     }
     return ret;
 }