示例#1
0
 public void GetUserIdByOpenId(string OpenId)
 {
     try
     {
         Response.Write("<br/>");
         //Response.Write("获取用户标识");
         string vipId   = string.Empty;
         string status  = "0";
         VipBLL server  = new VipBLL(loggingSessionInfo);
         var    vipObjs = server.QueryByEntity(new VipEntity
         {
             WeiXinUserId = OpenId
         }, null);
         if (vipObjs == null || vipObjs.Length == 0 || vipObjs[0] == null)
         {
             //请求获取用户信息
             //Jermyn20130911 从总部导入vip信息
             bool bReturn  = server.GetVipInfoFromApByOpenId(OpenId, null);
             var  vipObjs1 = server.QueryByEntity(new VipEntity
             {
                 WeiXinUserId = OpenId
             }, null);
             if (vipObjs1 == null || vipObjs1.Length == 0 || vipObjs1[0] == null)
             {
             }
             else
             {
                 vipId  = vipObjs1[0].VIPID;
                 status = vipObjs1[0].Status.ToString();
             }
         }
         else
         {
             vipId  = vipObjs[0].VIPID;
             status = vipObjs[0].Status.ToString();
         }
         //用户不存在或者取消关注,请处理
         if (vipId == null || vipId.Equals("") || status.Equals("0"))
         {
             Response.Redirect(strNoFollowUrl);
         }
         Response.Write("vipId:" + vipId);
         Response.Write("<br/>");
         goUrl = "http://" + HttpUtility.UrlDecode(goUrl) + "?customerId=" + customerId + "&userId=" + vipId + "&openId=" + OpenId + "";
         //goUrl = "http://" + HttpUtility.UrlDecode(goUrl) + "";
         //string strGotoUrl = "/OnlineClothing/go.htm?customerId=" + customerId + "&openId=" + OpenId + "&userId=" + vipId + "&backUrl=" + HttpUtility.UrlEncode(goUrl) + "";
         //Response.Write(goUrl);
         Response.Redirect(goUrl);
     }
     catch (Exception ex)
     {
         Loggers.Debug(new DebugLogInfo()
         {
             Message = string.Format("GetUserIdByOpenId用户用户信息出错: {0}", ex.ToString())
         });
         Response.Write("GetUserIdByOpenId用户用户信息出错:" + ex.ToString());
     }
 }
示例#2
0
 public void GetUserIdByOpenId(string OpenId)
 {
     try
     {
         Response.Write("<br/>");
         //Response.Write("获取用户标识");
         string vipId   = string.Empty;
         VipBLL server  = new VipBLL(loggingSessionInfo);
         var    vipObjs = server.QueryByEntity(new VipEntity
         {
             WeiXinUserId = OpenId
         }, null);
         if (vipObjs == null || vipObjs.Length == 0 || vipObjs[0] == null)
         {
             //请求获取用户信息
             //Jermyn20130911 从总部导入vip信息
             bool bReturn  = server.GetVipInfoFromApByOpenId(OpenId, null);
             var  vipObjs1 = server.QueryByEntity(new VipEntity
             {
                 WeiXinUserId = OpenId
             }, null);
             if (vipObjs1 == null || vipObjs1.Length == 0 || vipObjs1[0] == null)
             {
                 vipId = vipObjs1[0].VIPID;
             }
         }
         else
         {
             vipId = vipObjs[0].VIPID;
         }
         Response.Write("vipId:" + vipId);
         Response.Write("<br/>");
         //goUrl = "http://" + HttpUtility.UrlDecode(goUrl) + "?customerId=" + customerId + "&userId=" + vipId + "&openId=" + OpenId + "";
         goUrl = "http://" + HttpUtility.UrlDecode(goUrl) + "";
         string strGotoUrl = "/OnlineClothing/tmpGoUrl.html?customerId=" + customerId + "&openId=" + OpenId + "&userId=" + vipId + "&backUrl=" + HttpUtility.UrlEncode(goUrl) + "";
         //Response.Write(goUrl);
         Response.Redirect(strGotoUrl);
     }
     catch (Exception ex)
     {
         Loggers.Debug(new DebugLogInfo()
         {
             Message = string.Format("GetUserIdByOpenId用户用户信息出错: {0}", ex.ToString())
         });
         Response.Write("向o2omarketing平台请求用户信息出错,请联系管理员尽快处理.");
         Response.End();
     }
 }
示例#3
0
        public void GetUserIdByOpenId(string OpenId)
        {
            try
            {
                Response.Write("<br/>");
                //Response.Write("获取用户标识");
                string vipId   = string.Empty;
                VipBLL server  = new VipBLL(loggingSessionInfo);
                var    vipObjs = server.QueryByEntity(new VipEntity
                {
                    WeiXinUserId = OpenId
                }, null);
                if (vipObjs == null || vipObjs.Length == 0)
                {
                    //请求获取用户信息
                    //Jermyn20130911 从总部导入vip信息
                    bool bReturn  = server.GetVipInfoFromApByOpenId(OpenId, null);
                    var  vipObjs1 = server.QueryByEntity(new VipEntity
                    {
                        WeiXinUserId = OpenId
                    }, null);
                    if (vipObjs1 == null || vipObjs1.Length == 0)
                    {
                        vipId = vipObjs1[0].VIPID;
                    }
                    else
                    {
                        Response.Write("系统找不到你关注公众号的记录,请尝试取消关注公众号,然后重新关注该公众号!</br>给您带来不便,尽请谅解,谢谢!");
                        Response.End();
                    }
                }
                else
                {
                    vipId = vipObjs[0].VIPID;
                }
                Response.Write("vipId:" + vipId);
                Response.Write("<br/>");
                //goUrl = "http://" + HttpUtility.UrlDecode(goUrl) + "?customerId=" + customerId + "&userId=" + vipId + "&openId=" + OpenId + "";
                goUrl = "http://" + HttpUtility.UrlDecode(goUrl) + "";
                if (goUrl.IndexOf("lj/register.html") > 0)
                {
                    goUrl = goUrl.Replace("lj/register.html", "HtmlApps/auth.html?pageName=Register&eventId=BFC41A8BF8564B6DB76AE8A8E43557BA");
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = string.Format("[OAuthWX.aspx]url替换:old={0};new={1};", "lj/register.html?customerId=e703dbedadd943abacf864531decdac1", "HtmlApps/auth.html?pageName=Register&eventId=BFC41A8BF8564B6DB76AE8A8E43557BA")
                    });
                }
                string strGotoUrl = string.Empty;
                if (goUrl.IndexOf("Fuxing") > 0 || goUrl.IndexOf("HtmlApp") > 0)
                {
                    if (goUrl.IndexOf("?") > 0)
                    {
                        strGotoUrl = goUrl + "&customerId=" + customerId + "&openId=" + OpenId + "&userId=" + vipId + "";//&backUrl=" + HttpUtility.UrlEncode(goUrl) + "
                    }
                    else
                    {
                        strGotoUrl = goUrl + "?customerId=" + customerId + "&openId=" + OpenId + "&userId=" + vipId + "";//&backUrl=" + HttpUtility.UrlEncode(goUrl) + "
                    }
                }
                else
                {
                    if (goUrl.IndexOf("20131217") > 0)
                    {
                        strGotoUrl = "/OnlineClothing20131217/go.htm?customerId=" + customerId + "&openId=" + OpenId + "&userId=" + vipId + "&backUrl=" + HttpUtility.UrlEncode(goUrl) + "";
                    }
                    else
                    {
                        strGotoUrl = "/OnlineClothing/go.htm?customerId=" + customerId + "&openId=" + OpenId + "&userId=" + vipId + "&backUrl=" + HttpUtility.UrlEncode(goUrl) + "";
                    }
                }
                //Response.Write(goUrl);
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("GetUserIdByOpenId: strGotoUrl = {0}", strGotoUrl)
                });
                Response.Redirect(strGotoUrl, false);
            }
            catch (Exception ex) {
                Loggers.Exception(new ExceptionLogInfo()
                {
                    ErrorMessage = string.Format("GetUserIdByOpenId用户用户信息出错: {0}", ex.ToString())
                });

                Response.Write("向o2omarketing平台请求用户信息出错,请联系管理员尽快处理.");
                Response.End();
            }
        }
示例#4
0
        public VipEntity GetUserIdByOpenId(LoggingSessionInfo loggingSessionInfo, string OpenId)
        {
            VipEntity vipInfo = new VipEntity();

            try
            {
                string        vipId         = string.Empty;
                string        status        = "0";
                VipBLL        server        = new VipBLL(loggingSessionInfo);
                WXUserInfoBLL wxUserInfoBLL = new WXUserInfoBLL(loggingSessionInfo);
                //var vipObjs = server.QueryByEntityAbsolute(new VipEntity
                //{
                //    WeiXinUserId = OpenId
                //}, null);
                var vipObjs = server.QueryByEntity(new VipEntity   //先从会员表里取
                {
                    WeiXinUserId = OpenId,
                    ClientID     = loggingSessionInfo.ClientID
                }, null);

                if (vipObjs == null || vipObjs.Length == 0 || vipObjs[0] == null)//找不到会员信息
                {
                    //优先从支持多号运营的表中取
                    var wxUserInfo = wxUserInfoBLL.QueryByEntity(new WXUserInfoEntity()
                    {
                        CustomerID = loggingSessionInfo.ClientID, WeiXinUserID = OpenId
                    }, null).FirstOrDefault();
                    if (wxUserInfo != null)
                    {
                        var vipEntity = server.QueryByEntity(new VipEntity()
                        {
                            ClientID = loggingSessionInfo.ClientID, UnionID = wxUserInfo.UnionID
                        }, null).FirstOrDefault();                                                                                                                            //从会员表里取
                        if (vipEntity != null)
                        {
                            vipId   = vipEntity.VIPID;
                            status  = vipEntity.Status.ToString();
                            vipInfo = vipEntity;
                        }
                        else
                        {
                            vipInfo = null;
                        }
                    }
                    else
                    {
                        //请求获取用户信息
                        //Jermyn20130911 从总部导入vip信息
                        bool bReturn  = server.GetVipInfoFromApByOpenId(OpenId, null);
                        var  vipObjs1 = server.QueryByEntityAbsolute(new VipEntity
                        {
                            WeiXinUserId = OpenId
                        }, null);
                        if (vipObjs1 == null || vipObjs1.Length == 0 || vipObjs1[0] == null)
                        {
                            vipInfo = null;
                        }
                        else
                        {
                            vipId   = vipObjs1[0].VIPID;
                            status  = vipObjs1[0].Status.ToString();
                            vipInfo = vipObjs1[0];
                        }
                    }
                }
                else  //查到会员信息了
                {
                    vipId   = vipObjs[0].VIPID;
                    status  = vipObjs[0].Status.ToString();
                    vipInfo = vipObjs[0];
                    //获取UnionID
                    if (string.IsNullOrEmpty(vipInfo.UnionID))
                    {
                        var vipService  = new VipBLL(loggingSessionInfo);
                        var vipEntity   = new VipEntity();
                        var commonBll   = new CommonBLL();
                        var application = new WApplicationInterfaceDAO(loggingSessionInfo);
                        var appEntity   = application.QueryByEntity(new WApplicationInterfaceEntity()
                        {
                            WeiXinID = vipInfo.WeiXin, CustomerId = loggingSessionInfo.ClientID
                        }, null).FirstOrDefault();
                        if (appEntity != null)
                        {
                            //获取调用微信接口的凭证(普通的获取accestoken的地方)
                            var accessToken = commonBll.GetAccessTokenByCache(appEntity.AppID, appEntity.AppSecret, loggingSessionInfo);
                            //通过openID获取用户信息
                            //  (这种情况下,因为已经有会员信息了,并且已经关注了,才能获取到会员信息)
                            var userInfo = commonBll.GetUserInfo(accessToken.access_token, vipInfo.WeiXinUserId);
                            if (!string.IsNullOrEmpty(userInfo.unionid))
                            {
                                var vipEntitys = vipService.QueryByEntity(new VipEntity {
                                    UnionID = userInfo.unionid, ClientID = loggingSessionInfo.ClientID
                                }, null);
                                if (vipEntitys != null && vipEntitys.Length > 0)//已经存在有UnionID的数据
                                {
                                    var wxUserInfo = wxUserInfoBLL.QueryByEntity(new WXUserInfoEntity()
                                    {
                                        CustomerID = loggingSessionInfo.ClientID, VipID = vipEntitys[0].VIPID, WeiXinUserID = OpenId, UnionID = userInfo.unionid
                                    }, null).FirstOrDefault();
                                    if (wxUserInfo == null)
                                    {
                                        var wxuiEntity = new WXUserInfoEntity()
                                        {
                                            WXUserID     = Guid.NewGuid(),
                                            VipID        = vipEntitys[0].VIPID,//vipInfo.VIPID,
                                            WeiXin       = vipInfo.WeiXin,
                                            WeiXinUserID = vipInfo.WeiXinUserId,
                                            UnionID      = userInfo.unionid,
                                            CustomerID   = vipInfo.ClientID,
                                            CreateBy     = "auth",
                                            LastUpdateBy = "auth"
                                        };
                                        wxUserInfoBLL.Create(wxuiEntity);
                                    }

                                    //删除冗余vip记录
                                    vipInfo.LastUpdateBy = "auth-delete";
                                    vipService.Delete(vipInfo);
                                }
                                else
                                {
                                    //更新微信用户信息
                                    vipInfo.VipName    = userInfo.nickname;
                                    vipInfo.City       = userInfo.city;
                                    vipInfo.Gender     = Convert.ToInt32(userInfo.sex);
                                    vipInfo.HeadImgUrl = userInfo.headimgurl;
                                    vipInfo.UnionID    = userInfo.unionid;
                                    server.Update(vipInfo);
                                }
                            }
                        }
                    }
                }
                return(vipInfo);
            }
            catch (Exception ex)
            {
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("GetUserIdByOpenId用户用户信息出错: {0}", ex.ToString())
                });
                //Response.Write("GetUserIdByOpenId用户用户信息出错:" + ex.ToString());
                return(vipInfo);
            }
        }