예제 #1
0
        /// <summary>
        /// 添加新用户到基础表
        /// </summary>
        /// <param name="xml"></param>
        public void RegisterOAuthUser(RequestXML xml)
        {
            try
            {
                if (xml == null)
                {
                    return;
                }
                if (string.IsNullOrEmpty(xml.FromUserName))
                {
                    return;
                }

                //log4net.LogHelper.WriteInfo(this.GetType(), $"扫码事件推送:{JsonConvert.SerializeObject(xml)}");
                UserBaseInfo umodel = UserBaseInfoBLL.SingleModel.GetModelByOpenId(xml.FromUserName, xml.ToUserName);
                if (umodel == null)
                {
                    WeiXinUser wx = WxHelper.GetWxUserInfo(WxHelper.GetToken(), xml.FromUserName);
                    if (wx != null && !string.IsNullOrEmpty(wx.openid))
                    {
                        umodel            = new UserBaseInfo();
                        umodel.headimgurl = wx.headimgurl;
                        umodel.nickname   = wx.nickname;
                        umodel.openid     = wx.openid;
                        umodel.unionid    = wx.unionid;
                        umodel.country    = wx.country;
                        umodel.sex        = wx.sex;
                        umodel.city       = wx.city;
                        umodel.province   = wx.province;
                        umodel.serverid   = xml.ToUserName;
                        UserBaseInfoBLL.SingleModel.Add(umodel);
                    }
                }
                else
                {
                    WeiXinUser wx = WxHelper.GetWxUserInfo(WxHelper.GetToken(), xml.FromUserName);
                    if (wx != null && !string.IsNullOrEmpty(wx.openid) && umodel.headimgurl != wx.headimgurl)
                    {
                        umodel.headimgurl = wx.headimgurl;
                        UserBaseInfoBLL.SingleModel.Update(umodel, "headimgurl");
                    }
                }
            }
            catch (Exception ex)
            {
                log4net.LogHelper.WriteInfo(this.GetType(), $"报错扫码事件推送:{JsonConvert.SerializeObject(ex)}");
                log4net.LogHelper.WriteError(this.GetType(), ex);
            }
        }
예제 #2
0
        /// <summary>
        /// www.vzan.com 扫码登录
        /// </summary>
        /// <param name="requestXML"></param>
        private void IsAccountLogin(RequestXML requestXML)
        {
            //扫码登陆
            if (requestXML == null)
            {
                return;
            }
            string qrscene = requestXML.EventKey;

            if (string.IsNullOrEmpty(qrscene))
            {
                log4net.LogHelper.WriteInfo(this.GetType(), "微信扫码:qrscene为空");
                return;
            }
            qrscene = qrscene.Replace("qrscene_", "");
            Entity.MiniApp.LoginQrCode lcode = RedisUtil.Get <Entity.MiniApp.LoginQrCode>("SessionID:" + qrscene);
            if (lcode == null)
            {
                log4net.LogHelper.WriteInfo(this.GetType(), "微信扫码:lcode is null");
                return;
            }
            lcode.OpenId = requestXML.FromUserName;



            //扫描小未公司公众号
            if (requestXML.ToUserName == "gh_6014346f8435")
            {
                //log4net.LogHelper.WriteInfo(this.GetType(), "微信扫码5:" + Newtonsoft.Json.JsonConvert.SerializeObject(requestXML));
                lcode.WxUser = WxHelper.GetWxUserInfo("gh_6014346f8435", requestXML.FromUserName);
            }
            //扫描小未科技公众号
            else
            {
                //log4net.LogHelper.WriteInfo(this.GetType(), $"微信扫码4:" + Newtonsoft.Json.JsonConvert.SerializeObject(requestXML));
                lcode.WxUser = WxHelper.GetWxUserInfo(WxHelper.GetToken(), requestXML.FromUserName);
            }
            lcode.IsLogin = true;
            RedisUtil.Set <Entity.MiniApp.LoginQrCode>("SessionID:" + qrscene, lcode, TimeSpan.FromMinutes(1));
        }