Exemple #1
0
        /// <summary>
        /// 为物流速递用户创建登录Session
        /// </summary>
        private static void CreateSFExpressUserSession()
        {
            // 物流速递传递过来的参数不为空
            if (System.Web.HttpContext.Current.Request["unionid"] != null &&
                System.Web.HttpContext.Current.Request["tokenId"] != null &&
                System.Web.HttpContext.Current.Request["sourcetype"] != null)
            {
                if (System.Web.HttpContext.Current.Session == null ||
                    System.Web.HttpContext.Current.Session[ConstClass.SessionKeyMLoginUser] == null)
                {
                    // 传递参数
                    string UnionId  = System.Web.HttpContext.Current.Request["unionid"].ToString();
                    string SFId     = System.Web.HttpContext.Current.Request["sfid"] != null ? System.Web.HttpContext.Current.Request["sfid"].ToString() : string.Empty;
                    string TokenId  = System.Web.HttpContext.Current.Request["tokenId"].ToString();
                    string Password = TokenId;

                    // 获取SourceType值
                    int SourceType = GetSourceType(System.Web.HttpContext.Current.Request["sourcetype"].ToString());
                    if (SourceType == -1)
                    {
                        return;
                    }

                    // 参数MD5与TokenId比较
                    StringBuilder strBuilder = new StringBuilder();
                    strBuilder.Append(UnionId).Append(SourceType).Append(SFExpressKey);
                    string MD5Encoding = FormsAuthentication.HashPasswordForStoringInConfigFile(strBuilder.ToString(), "MD5");
                    //if (!MD5Encoding.Equals(TokenId))
                    //{
                    //    System.Web.HttpContext.Current.Session[ConstClass.SessionKeyMLoginUser] = null;
                    //    System.Web.HttpContext.Current.Session.Clear();
                    //    return;
                    //}

                    CustomerEntity CustomerEntity = new CustomerEntity();
                    CustomerEntity.Password   = Password;
                    CustomerEntity.SourceType = SourceType;
                    CustomerEntity.SFId       = SFId;
                    CustomerEntity.UnionId    = UnionId;

                    // 获取用户信息是否为空
                    bool IsNullFlag = accountBll.GetUserInfoIsNull(UnionId);

                    int            ReturnUserId         = 1;
                    CustomerEntity ReturnCustomerEntity = null;

                    // 用户信息为空
                    if (IsNullFlag)
                    {
                        // 插入用户信息
                        ReturnCustomerEntity = accountBll.CreateSFExpressUser(CustomerEntity);
                    }
                    else
                    {
                        // 获取用户信息
                        ReturnCustomerEntity = accountBll.GetSFExpressUser(UnionId);
                    }

                    if (ReturnCustomerEntity != null)
                    {
                        ReturnUserId            = ReturnCustomerEntity.ID;
                        CustomerEntity.ID       = ReturnCustomerEntity.ID;
                        CustomerEntity.UserName = ReturnCustomerEntity.UserName;
                        CustomerEntity.Status   = ReturnCustomerEntity.Status;
                    }
                    else
                    {
                        ReturnUserId = 0;
                    }

                    // 给用户登录状态
                    if (ReturnUserId > 0)
                    {
                        //Session记录登录状态
                        LoginHelper.SetLoginUserSession(CustomerEntity.AsLoginUserModel());
                    }
                }
            }
        }