示例#1
0
    protected void btnlogin_Click(object sender, EventArgs e)
    {
        string AuthenType = ddlAuthenTypeList.SelectedValue;

        PageUtility.SetCookie("AuthenType", AuthenType, 168);           //168个小时,即一个礼拜
        string AuthenName  = txtUsername.Text;
        string Password    = txtPassword.Text;
        string CustID      = "";
        string RealName    = "";
        string NickName    = "";
        string UserName    = "";
        string OutID       = "";
        string UserAccount = "";
        string ErrMsg      = "";
        string CustType    = "";
        string ProvinceID  = "";
        int    Result      = 1;

        if (!CommonUtility.ValidateValidateCode(HttpUtility.HtmlDecode(Request.Form["code"].ToString().Trim().ToUpper()), this.Context))
        {
            err_code.InnerHtml = "验证码错误,请重新输入";

            return;
        }

        //日志
        log(String.Format("【开始验证】:SPID:{0},ProvinceID:{1},AuthenName:{2},AuthenType:{3}", SPID, ProvinceID, AuthenName, AuthenType));

        Result = BTForBusinessSystemInterfaceRules.UserAuthV2(SPID, AuthenName, AuthenType, Password, Context, ProvinceID, "", "",
                                                              out ErrMsg, out CustID, out UserAccount, out CustType, out OutID, out ProvinceID, out RealName, out UserName, out NickName);
        //验证结果日志
        log(String.Format("【验证结果】:CustID:{0},UserAcount:{1},CustType:{2},OutID:{3},ProvinceID:{4},RealName:{5},UserName:{6},NickName:{7}",
                          CustID, UserAccount, CustType, OutID, ProvinceID, RealName, UserName, NickName));
        CommonBizRules.WriteDataCustAuthenLog(SPID, CustID, ProvinceID, AuthenType, AuthenName, "2", Result, ErrMsg);
        if (Result != 0)
        {
            if (Result == 1001 || Result == -20504 || Result == -21553)
            {
                err_Username.InnerHtml  = ErrMsg;
                hint_Username.InnerHtml = "";
                return;
            }

            if (Result == -21501)
            {
                err_Password.InnerHtml = ErrMsg;
                return;
            }
            Response.Write(ErrMsg);
            return;
        }

        SPInfoManager spInfo = new SPInfoManager();
        Object        SPData = spInfo.GetSPData(this.Context, "SPData");
        string        key    = spInfo.GetPropertyBySPID("35000000", "SecretKey", SPData);

        //生成token并保存
        UserToken UT             = new UserToken();
        string    UserTokenValue = UT.GenerateUserToken(CustID, RealName, UserName, NickName, OutID, CustType, AuthenName, AuthenType, key, out ErrMsg);
        string    CookieName     = System.Configuration.ConfigurationManager.AppSettings["CookieName"];

        PageUtility.SetCookie(UserTokenValue, CookieName, this.Page);

        TokenValidate.IsRedircet = false;

        TokenValidate.Validate();

        this.ssoFunc();
    }
示例#2
0
    protected void login_Click(object sender, EventArgs e)
    {
        Response.AddHeader("P3P", "CP=CAO PSA OUR");
        StringBuilder strLog = new StringBuilder();
        //string AuthenType = HttpUtility.HtmlDecode(Request.Form["AuthenType"].ToString().Trim().ToUpper());         //获取认证类型

        string AuthenName = username.Text;
        string Password   = password.Text;
        string AuthenType = "1";  // 默认是用户名

        Regex regMobile = new Regex(@"^1[3458]\d{9}$");
        Regex regEmail  = new Regex(@"^[0-9a-zA-Z_\-\.]*[0-9a-zA-Z_\-]@[0-9a-zA-Z]+\.+[0-9a-zA-Z_\-.]+$");
        Regex regCard   = new Regex(@"^(\d{9}|\d{16})$");

        if (regMobile.IsMatch(AuthenName))
        {
            AuthenType = "2";
        }
        if (regEmail.IsMatch(AuthenName))
        {
            AuthenType = "4";
        }
        if (regCard.IsMatch(AuthenName))
        {
            AuthenType = "3";
        }


        PageUtility.SetCookie("AuthenType", AuthenType, 168);           //168个小时,即一个礼拜


        string CustID      = "";
        string RealName    = "";
        string NickName    = "";
        string UserName    = "";
        string OutID       = "";
        string UserAccount = "";
        string ErrMsg      = "";
        string CustType    = "";
        string ProvinceID  = "";
        int    Result      = 1;

        try
        {
            strLog.AppendFormat("checkCode={0}", Request.Form["checkCode"]);
            if (!CommonUtility.ValidateValidateCode(HttpUtility.HtmlDecode(Request.Form["checkCode"].ToString().Trim()), this.Context))
            {
                errorHint.InnerHtml = "验证码错误,请重新输入";
                return;
            }

            //日志
            strLog.AppendFormat("【开始验证】:SPID:{0},ProvinceID:{1},AuthenName:{2},AuthenType:{3}", SPID, ProvinceID, AuthenName, AuthenType);

            Result = BTForBusinessSystemInterfaceRules.UserAuthV2(SPID, AuthenName, AuthenType, Password, Context, ProvinceID, "", "",
                                                                  out ErrMsg, out CustID, out UserAccount, out CustType, out OutID, out ProvinceID, out RealName, out UserName, out NickName);
            //验证结果日志
            strLog.AppendFormat("【验证结果】:CustID:{0},UserAcount:{1},CustType:{2},OutID:{3},ProvinceID:{4},RealName:{5},UserName:{6},NickName:{7}",
                                CustID, UserAccount, CustType, OutID, ProvinceID, RealName, UserName, NickName);
            CommonBizRules.WriteDataCustAuthenLog(SPID, CustID, ProvinceID, AuthenType, AuthenName, "2", Result, ErrMsg);
            if (Result != 0)
            {
                if (Result == 1001 || Result == -20504 || Result == -21553)
                {
                    errorHint.InnerHtml = ErrMsg;
                    //hint_Username.InnerHtml = "";
                    return;
                }

                if (Result == -21501)
                {
                    errorHint.InnerHtml = ErrMsg;
                    return;
                }
                Response.Write(ErrMsg);
                return;
            }

            SPInfoManager spInfo = new SPInfoManager();
            Object        SPData = spInfo.GetSPData(this.Context, "SPData");
            string        key    = spInfo.GetPropertyBySPID("35000000", "SecretKey", SPData);

            //生成token并保存
            UserToken UT             = new UserToken();
            string    UserTokenValue = UT.GenerateUserToken(CustID, RealName, UserName, NickName, OutID, CustType, AuthenName, AuthenType, key, out ErrMsg);
            string    CookieName     = System.Configuration.ConfigurationManager.AppSettings["CookieName"];
            PageUtility.SetCookie(CookieName, UserTokenValue);

            TokenValidate.IsRedircet = false;
            TokenValidate.Validate();

            this.ssoFunc();
        }
        catch (System.Exception ex)
        {
            log(ex.ToString());
        }
        finally
        {
            log(strLog.ToString());
        }
    }
示例#3
0
    public void aaa()
    {
        string AuthenName = HttpUtility.HtmlDecode(Request.QueryString["name"].ToString());
        string QuestionID = HttpUtility.HtmlDecode(Request.QueryString["questionID"].ToString());
        string Answer     = HttpUtility.HtmlDecode(Request.QueryString["answer"].ToString());


        ///调用你的方法


        if (!ValidateValidateCode())
        {
            Response.Write("1");
            return;
        }



        string CustID  = "";
        string outerid = "";

        string UserAccount = "";
        string ProvinceID  = "";

        string CustType = "";
        string RealName = "";
        string UserName = "";
        string NickName = "";
        int    Result1  = 0;
        int    Result2  = 0;
        string ErrorDescription;
        string str;


        try
        {
            #region 数据校验


            if (CommonUtility.IsEmpty(AuthenName))
            {
                Result1          = ErrorDefinition.BT_IError_Result_InValidRealName_Code;
                ErrorDescription = ErrorDefinition.BT_IError_Result_InValidRealName_Msg + ",不能为空";
                //return Result;
            }



            #endregion



            Result1 = BTForBusinessSystemInterfaceRules.UserAuthV2("35000000", AuthenName, "1", "",
                                                                   this.Context, ProvinceID, "", "",
                                                                   out ErrorDescription, out CustID, out UserAccount, out CustType, out outerid, out ProvinceID, out RealName, out UserName, out NickName);


            //Result1 = BTForBusinessSystemInterfaceRules.UserAuthV2("35000000", AuthenName, "1", "",
            //    this.Context,ProvinceID,
            //    out ErrorDescription
        }
        catch (Exception e)
        {
            Result1          = ErrorDefinition.IError_Result_System_UnknowError_Code;
            ErrorDescription = ErrorDefinition.IError_Result_System_UnknowError_Msg + e.Message;
        }

        if (Result1 != -21501)
        {
            str = "CustID:\"" + CustID + "\"," + "CustType:\"" + CustType + "\"," + "Result1:\"" + Result1 + "\"," + "Result2:\"" + Result2 + "\"";
            Response.Write(str);
            return;
        }

        try
        {
            if (CommonUtility.IsEmpty(CustID))
            {
                Result2          = ErrorDefinition.BT_IError_Result_InValidCustID_Code;
                ErrorDescription = ErrorDefinition.BT_IError_Result_InValidCustID_Msg + ",不能为空";
            }
            if (CommonUtility.IsEmpty(QuestionID))
            {
                Result2          = ErrorDefinition.IError_Result_UnknowError_Code;
                ErrorDescription = ErrorDefinition.IError_Result_UnknowError_Msg + ",QuestionID不能为空";
            }
            if (CommonUtility.IsEmpty(Answer))
            {
                Result2          = ErrorDefinition.IError_Result_UnknowError_Code;
                ErrorDescription = ErrorDefinition.IError_Result_UnknowError_Msg + ",Answer不能为空";
            }


            Result2 = BTForBusinessSystemInterfaceRules.PwdQuestionAuth(CustID, int.Parse(QuestionID), Answer, out ErrorDescription);
        }
        catch (Exception err)
        {
            Result2          = ErrorDefinition.IError_Result_UnknowError_Code;
            ErrorDescription = err.Message.ToString();;
        }


        str = "CustID:\"" + CustID + "\"," + "CustType:\"" + CustType + "\"," + "Result1:\"" + Result1 + "\"," + "Result2:\"" + Result2 + "\"";

        Response.Write(str);
    }
示例#4
0
    protected void auth_Click(object sender, EventArgs e)
    {
        string AuthenType = HttpUtility.HtmlDecode(Request.Form["AuthenType"].ToString().Trim().ToUpper());         //获取认证类型
        string password   = Request.Form["password"].ToString().Trim();
        string username   = Request.Form["username"].ToString().Trim();

        // 按照模式匹配出,认证模式 (手机,用户名,商旅卡,邮箱)认证
        // 如果认证通过,返回custid
        // 绑定 custid和openid

        PageUtility.SetCookie("AuthenType", AuthenType, 168);           //168个小时,即一个礼拜
        string AuthenName  = username;
        string Password    = password;
        string CustID      = "";
        string RealName    = "";
        string NickName    = "";
        string UserName    = "";
        string OutID       = "";
        string UserAccount = "";
        string CustType    = "";
        string ProvinceID  = "";
        string ErrMsg      = "";
        int    Result;

        //日志
        log(String.Format("【开始验证】:SPID:{0},ProvinceID:{1},AuthenName:{2},AuthenType:{3}", SPID, ProvinceID, AuthenName, AuthenType));

        Result = BTForBusinessSystemInterfaceRules.UserAuthV2(SPID, AuthenName, AuthenType, Password, Context, ProvinceID, "", "",
                                                              out ErrMsg, out CustID, out UserAccount, out CustType, out OutID, out ProvinceID, out RealName, out UserName, out NickName);
        //验证结果日志
        log(String.Format("【验证结果】:CustID:{0},UserAcount:{1},CustType:{2},OutID:{3},ProvinceID:{4},RealName:{5},UserName:{6},NickName:{7}",
                          CustID, UserAccount, CustType, OutID, ProvinceID, RealName, UserName, NickName));
        CommonBizRules.WriteDataCustAuthenLog(SPID, CustID, ProvinceID, AuthenType, AuthenName, "2", Result, ErrMsg);
        if (Result != 0)
        {
            if (Result == 1001 || Result == -20504 || Result == -21553)
            {
                errorHint.InnerHtml = ErrMsg;
                return;
            }

            if (Result == -21501)
            {
                errorHint.InnerHtml = ErrMsg;
                return;
            }
            Response.Write(ErrMsg);
            return;
        }

        // 绑定custid 和code关系   begin
        string        _connectionString = WebConfigurationManager.ConnectionStrings["BestToneCenterConStr"].ConnectionString;
        int           result            = -1;
        SqlConnection con = new SqlConnection(_connectionString);
        SqlCommand    cmd = new SqlCommand("insert into oauthaccount (openid,custid,createtime,status) values (@code,@CustID,getdate(),@oauthtype)", con);

        cmd.Parameters.Add("@code", SqlDbType.NVarChar, 50).Value     = code;
        cmd.Parameters.Add("@CustID", SqlDbType.NVarChar, 16).Value   = CustID;
        cmd.Parameters.Add("@oauthtype", SqlDbType.NVarChar, 1).Value = oauthtype;

        using (con)
        {
            con.Open();
            result = cmd.ExecuteNonQuery();
        }
        //end
        if (result != 0)
        {
            errorHint.InnerHtml = "绑定关系建立失败";
            return;
        }

        SPInfoManager spInfo = new SPInfoManager();
        Object        SPData = spInfo.GetSPData(this.Context, "SPData");
        string        key    = spInfo.GetPropertyBySPID("35000000", "SecretKey", SPData);

        //生成token并保存
        UserToken UT             = new UserToken();
        string    UserTokenValue = UT.GenerateUserToken(CustID, RealName, UserName, NickName, OutID, CustType, AuthenName, AuthenType, key, out ErrMsg);
        string    CookieName     = System.Configuration.ConfigurationManager.AppSettings["CookieName"];

        //PageUtility.SetCookie(UserTokenValue, CookieName, this.Page);
        PageUtility.SetCookie(CookieName, UserTokenValue);
        TokenValidate.IsRedircet = false;
        TokenValidate.Validate();
        this.ssoFunc();
    }
示例#5
0
    protected void QueryAssertionByTicket()
    {
        MBOSSClass    mboss = new MBOSSClass();
        StringBuilder strLog = new StringBuilder();
        string        xml = "";
        int           Result = -19999;
        string        ErrMsg = String.Empty;
        string        UAProvinceID = "35";
        string        SPID = UAProvinceID + "999991";
        string        CustID = "", RealName = "", NickName = "", UserName = "", OutID = "", UserAccount = "", CustType = "", ProvinceID = "", AuthenName = "", AuthenType = "";
        string        AssertionAddress = String.Empty;
        string        SSOAddress       = String.Empty;
        string        SecretKey        = String.Empty;

        try
        {
            //获取到集团断言查询地址,这里要注意个问题,取地址是从数据库中去,测试库上的地址已经改为新的断言地址,在正式库上是否要改?
            Result = mboss.GetMBOSSAddress(this.Context, SPID, out AssertionAddress, out SSOAddress, out ErrMsg);
            if (Result != 0)
            {
                strLog.Append("没有获取到集团断言查询地址;\r\n");
                //SendJF();   没有获取到集团断言查询地址
                return;
            }
            PageUtility.SetCookie(AssertionAddress, "AssertionAddress", this.Page);
            PageUtility.SetCookie(SSOAddress, "SSOAddress", this.Page);
            //35000 20130808 5146985330
            string TransactionID = "35000" + DateTime.Now.ToString("yyyyMMdd") + Convert.ToString(LongRandom(1000000000, 9999999999, new Random()));                   //获取流水号
            //密钥
            Result = mboss.GetMBOSSSecretKey(this.Context, SPID, out SecretKey, out ErrMsg);
            if (Result != 0)
            {
                strLog.Append("没有获取到密钥;\r\n");
                //没有获取到密钥;
                return;
            }

            //断言
            MBOSSClass.BilByCompilingResult bil = new MBOSSClass.BilByCompilingResult();
            //查询断言并解析
            Result     = mboss.SendUATicket(UAProvinceID, SPID, UATicket, AssertionAddress, this.Context, "SPCAData", TransactionID, out bil, out xml, out ErrMsg);
            AuthenType = bil.AccountType;
            AuthenName = bil.AccountID;
            strLog.AppendFormat("断言查询返回的报文:{0}\r\n", xml);
            if (Result != 0)
            {
                //Response.Redirect("../ErrorInfo.aspx?Result=-19999&ErrorInfo=请从网厅登陆1&FunctionName=请从网厅登陆1", true);
                Response.Redirect("../ErrorInfo.aspx?Result=-19999&ErrorInfo=断言解析错误!", true);
                return;
            }


            //用户入库是否存在,没有则新增,有则update
            string dealType = String.Empty;
            int    type     = 0;
            string areaid   = String.Empty;

            Result = BTForBusinessSystemInterfaceRules.MUserAuthV2(SPID, UAProvinceID, bil.AccountID, bil.AccountType, bil.AccountInfos, Context,
                                                                   out ErrMsg, out CustID, out UserAccount, out CustType, out OutID, out ProvinceID,
                                                                   out RealName, out UserName, out NickName, out dealType, out type, out areaid);

            if (Result != 0)
            {
                Response.Redirect("../ErrorInfo.aspx?Result=" + Result + "&ErrorInfo=" + ErrMsg + "&FunctionName=请从网厅登陆4", true);
                return;
            }

            //如果客户信息不全,则去crm查询一把  这里要注意的是,必须根据集团返回的断言中的UAID 当成省码传给枢纽
            string TestStr = String.Empty;
            Result = CrmSSO.UserAuthCrm1(bil.ProvinceID, bil.AccountInfos[0].areaid, bil.AccountType, bil.AccountID, UAProvinceID, "", "0", UAProvinceID + "999991", this.Context, out RealName, out UserName, out NickName, out OutID, out CustType, out CustID, out ErrMsg, out TestStr);
            if (Result != 0)
            {
                Response.Redirect("../ErrorInfo.aspx?Result=" + Result + "&ErrorInfo=" + ErrMsg + "&FunctionName=请从网厅登陆5", true);
                return;
            }
            strLog.Append(Result + "==" + UAProvinceID + "=UAProvinceID;" + bil.AccountType + " =bil.AccountType;" + bil.AccountID + "=bil.AccountID;" + "" + "" + RealName + "=RealName;" + UserName + "=UserName;" + NickName + "=NickName;" + OutID + "=OutID;" + CustType + "=CustType;" + CustID + "=CustID1;" + ErrMsg + "=ErrMsg\r\n");
            if (dealType == "0")            //通知积分系统
            {
                CIP2BizRules.InsertCustInfoNotify(CustID, "2", System.Configuration.ConfigurationManager.AppSettings["ScoreBesttoneSPID"], "", "0", out ErrMsg);
            }

            //生成ticket
            Result = CIPTicketManager.insertCIPTicket(TransactionID, SPID, CustID, RealName, NickName, UserName, OutID, "", AuthenName, AuthenType, out ErrMsg);
            Response.Redirect(ReturnUrl + "?Ticket=" + TransactionID);
        }
        catch (Exception e)
        {
            strLog.AppendFormat(e.Message);
        }
        finally
        {
            try
            {
                CommonBizRules.WriteDataCustAuthenLog(SPID, CustID, ProvinceID, AuthenType, AuthenName, "2", Result, ErrMsg);
            }
            catch { }
        }
    }
示例#6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        log("step1");
        int Result = ErrorDefinition.IError_Result_UnknowError_Code;

        log("step2");
        if (CommonUtility.IsParameterExist("SSORequestXML", this.Page))  // 带着token过来的是网厅的认证请求
        {
            #region 隐藏
            MBOSSClass mboss = new MBOSSClass();

            SPInfoManager spInfo             = new SPInfoManager();
            string        SPID               = "35999991";
            string        UAProvinceID       = "35";
            string        SourceType         = "";
            string        uaURL              = "";
            string        privateKeyPassword = "";
            string        UserName           = "";
            string        ErrMsg             = "";

            string CAP01002_XML = Request["SSORequestXML"];

            string DigitalSign = MBOSSClass.GetNewXML(CAP01002_XML, "DigitalSign");

            string DigitalSignValue = MBOSSClass.GetValueFromXML(CAP01002_XML, "DigitalSign");
            //从中取出RedirectURL
            string RedirectURL = MBOSSClass.GetValueFromXML(CAP01002_XML, "RedirectURL");
            //验证 CAP01002_XM 合法性
            byte[] PublicKeyFile = new byte[0];

            try
            {
                Object SPData = spInfo.GetSPData(this.Context, "");  //SPDataCacheName 这里要去问tongbo
                PublicKeyFile = spInfo.GetCAInfo(SPID, 0, SPData, out UserName, out privateKeyPassword);
            }
            catch (Exception err)
            {
                //验证签名未通过
                ErrMsg = err.Message;
                Result = -20001;
                Response.Redirect(RedirectURL, true);
                return;
            }

            Result = mboss.VerifySignByPublicKey(DigitalSign, PublicKeyFile, DigitalSignValue, out ErrMsg);
            //<CAPRoot><SessionHeader><ServiceCode>CAP01003</ServiceCode><Version>mbossUacVersion1</Version><ActionCode>0</ActionCode><TransactionID>35000201109254969771818</TransactionID><SrcSysID>35000</SrcSysID><DigitalSign>302C02141DB53BC5D52562D69EFD959B32F6E10D4BF6421E02145983D67CC81B0F376CA688B39F6AD1896EA0E082</DigitalSign><DstSysID>18</DstSysID><ReqTime>20110925000030</ReqTime><Request><ReqType/><ReqCode/><ReqDesc/></Request></SessionHeader><SessionBody><SPSSOAuthReq><RedirectURL>http://Customer.besttone.com.cn/UserPortal/SSO/SelectAssertion.aspx</RedirectURL><AcceptAccountTypeList><AcceptAccountType>0000000</AcceptAccountType></AcceptAccountTypeList></SPSSOAuthReq></SessionBody></CAPRoot>
            log("从网厅来:" + CAP01002_XML);
            if (Result != 0)
            {
                // 签名校验未通过,直接将请求原路打回
                Response.Redirect(RedirectURL, true);
                return;
            }
            string sessionid   = this.Page.Session.SessionID;
            string globaltoken = Request.Cookies[sessionid].Value.ToString();
            uaURL = RedirectURL;
            if (globaltoken != null && !"".Equals(globaltoken))
            {
                this.sendTicket2UA(uaURL);
            }
            else
            {
                this.Response.Redirect(uaURL);
            }

            #endregion
        }
        else
        {
            //不带token的是积分商城过来的认证请求
            string direction  = Request["Direction"];
            string CookieName = System.Configuration.ConfigurationManager.AppSettings["CookieName"];
            string key0       = System.Configuration.ConfigurationManager.AppSettings["ScoreSystemSecret"];

            if (CommonUtility.IsParameterExist("Direction", this.Page))
            {
                #region 反向登录到集团网厅方向
                string ProvinceID = Request["ProvinceID"];
                if ("uam".Equals(direction))
                {
                    //获取本地的token,如果没有token则返回到积分商城登录
                    //string token = Request.Cookies[CookieName].Value;
                    String token = PageUtility.GetCookie(CookieName);
                    if (String.IsNullOrEmpty(token))
                    {
                        Response.Redirect("http://www.ct10000.com");
                    }

                    string ProvinceID0 = "";  // 2013.01.23 添加
                    string CustID0     = "";
                    string RealName0   = "";
                    string UserName0   = "";
                    string NickName0   = "";
                    string OuterID0    = "";
                    string CustType0   = "";
                    string AuthenName0 = "";
                    string AuthenType0 = "";
                    string ErrMsg0     = "";

                    //解析token
                    UserToken UT0 = new UserToken();
                    // 2013.01.23 修改
                    //int Result0 = UT0.ParseUserToken(token, key0, out CustID0, out RealName0, out UserName0, out NickName0, out OuterID0, out CustType0, out AuthenName0, out AuthenType0, out ErrMsg0);
                    int Result0 = UT0.ParseScoreUserToken(token, key0, out ProvinceID0, out CustID0, out RealName0, out UserName0, out NickName0, out OuterID0, out CustType0, out AuthenName0, out AuthenType0, out ErrMsg0);
                    //日志
                    log(String.Format("【token解析结果:】Result:{0},ErrMsg:{1},AuthenName:{2},AuthenType:{3},CustID:{4},OuterID:{5},CustType:{6}", Result0, ErrMsg0, AuthenName0, AuthenType0, CustID0, OuterID0, CustType0));

                    if (Result0 == 0)
                    {
                        //生成ticket,反向单点登录要求ticket前面加上省id
                        //string sDate = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                        //Random r = new Random();
                        //string ticket = ProvinceID + sDate + r.Next(10000, 99999).ToString();
                        string ticket = ProvinceID + CommonBizRules.CreateTicket();
                        //积分商城
                        SPID = "35000010";
                        //将ticket插入数据库
                        Result = CIPTicketManager.insertCIPTicket(ticket, SPID, CustID0, RealName0, NickName0, UserName0, OuterID0, "", AuthenName0, AuthenType0, out ErrMsg0);

                        log(String.Format("【ticket生成结果:{0}】Result:{1},ErrMsg:{2},ticket:{3}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Result, ErrMsg0, ticket));

                        if (Result != 0)
                        {
                            this.Response.Redirect("http://www.ct10000.com");
                        }
                        string uamURL = System.Configuration.ConfigurationManager.AppSettings["UAMUrl"] + "?AccountIndex=" + ticket;

                        log(String.Format("【登录网厅:{0}】uamURL:{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), uamURL));

                        this.Response.Redirect(uamURL);
                    }
                    else
                    {
                        this.Response.Redirect("http://www.ct10000.com");
                    }
                }
                else
                {
                    this.Response.Redirect("http://www.ct10000.com");
                }
                #endregion
            }
            else
            {
                if (!this.IsPostBack)
                {
                    #region 积分商城直接登录

                    string SPTokenRequest = Request["SPTokenRequest"];
                    log(String.Format("【SPTokenRequest参数为:{1}】SPTokenRequest:{0}", SPTokenRequest, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));

                    string key        = System.Configuration.ConfigurationManager.AppSettings["ScoreSystemSecret"];
                    string JFLoginUrl = System.Configuration.ConfigurationManager.AppSettings["JFLoginUrl"];
                    //生成全局token写入cookie,该全局token为了将来网厅请求时候,查询该客户登陆状态用
                    UserToken UT = new UserToken();

                    ProvinceID  = Request["ProvinceID"];
                    AuthenType  = Request["AuthenType"];
                    AuthenName  = Request["AuthenName"];
                    Password    = Request["Password"];
                    ReturnURL   = Request["ReturnURL"]; // 这个ReturnUrl 用来还给积分商城ticket用
                    AccountType = Request["AccountType"];

                    string RealName    = "";
                    string UserName    = "";
                    string NickName    = "";
                    string CustType    = "";
                    string CustID      = "";
                    string ErrMsg      = "";
                    string OutID       = "";
                    string UserAccount = "";
                    string SPID        = "";

                    //解析SPTokenRequest参数
                    int Resultjf = SSOClass.ParseJFLoginRequest(SPTokenRequest, this.Context, out SPID, out ProvinceID, out AuthenType, out AuthenName, out Password, out ReturnURL, out ErrMsg);

                    if (Resultjf != 0)
                    {
                        //日志
                        log(String.Format("【解析SPTokenRequest参数失败:{0}】Result:{1},ErrMsg:{2}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Result, ErrMsg));
                        string err = System.Web.HttpUtility.UrlEncode("积分商城请求的token解密失败!ErrMsg=" + ErrMsg, Encoding.UTF8);
                        Response.Redirect(JFLoginUrl + "?Result=" + Resultjf + "&ErrMsg=" + err, true);
                        return;
                    }
                    //日志
                    log(String.Format("【解析SPTokenRequest参数成功:{0}】SPID:{1},ProvinceID:{2},AuthenType:{3},AuthenName:{4},ReturnURL:{5}",
                                      DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), SPID, ProvinceID, AuthenType, AuthenName, ReturnURL));

                    string o_ProvinceID = "";
                    Result = BTForBusinessSystemInterfaceRules.UserAuthV2(SPID, AuthenName, AuthenType, Password, this.Context, ProvinceID, "", "",
                                                                          out ErrMsg, out CustID, out UserAccount, out CustType, out OutID, out o_ProvinceID, out RealName, out UserName, out NickName);

                    //日志
                    log(String.Format("【Crm认证结果:{0}】Result:{1},ErrMsg:{2},CustID:{3},UserAccount:{4},CustType:{5},OutID:{6},ProvinceID:{7}",
                                      DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Result, ErrMsg, CustID, UserAccount, CustType, OutID, o_ProvinceID));

                    if (Result != 0)
                    {
                        string err         = System.Web.HttpUtility.UrlEncode(ErrMsg, Encoding.UTF8);
                        string jf_loginUrl = "";
                        if (ReturnURL.IndexOf("?") > 0)
                        {
                            jf_loginUrl = ReturnURL + "&Result=" + Result + "&ErrMsg=" + err;
                        }
                        else
                        {
                            jf_loginUrl = ReturnURL + "?Result=" + Result + "&ErrMsg=" + err;
                        }

                        //直接将请求原路打回 --假设请求中有ReturnURL
                        Response.Redirect(jf_loginUrl + "", true);
                        return;
                    }
                    //生成token 修改 2013.01.23
                    string UserTokenValue = UT.GenerateJFUserToken(ProvinceID, CustID, RealName, UserName, NickName, OutID, CustType, AuthenName, AuthenType, key, out ErrMsg);
                    //UT.GenerateUserToken(CustID, RealName, UserName, NickName, OutID, CustType, AuthenName, AuthenType, key, out ErrMsg);
                    log("token-Result:" + Result);
                    string CookieName0 = System.Configuration.ConfigurationManager.AppSettings["CookieName"];  //CookieName = CIPUT
                    PageUtility.SetCookie(UserTokenValue, CookieName0, this.Page);

                    //生成流水号
                    //string TransactionId = "";
                    //string sDate = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    //Random r = new Random(Guid.NewGuid().GetHashCode());
                    //TransactionId = "35999999" + sDate + r.Next(10000, 99999).ToString();
                    String TransactionId = "35999999" + CommonBizRules.CreateTransactionID();

                    //生成ticket
                    //sDate = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    //r = new Random();
                    //string Ticket = sDate + r.Next(10000, 99999).ToString();
                    String Ticket = CommonBizRules.CreateTicket();

                    StringBuilder msg0 = new StringBuilder();
                    msg0.Append("++++++++++++++++++++++++++++++++++++++token===++++++++++++++++++++" + UserTokenValue + "++++++++++++++++++++++++++\r\n");
                    BTUCenterInterfaceLog.CenterForBizTourLog("REVERSE-SSO", msg0);

                    this.sendTicket2JF(Ticket, CustID, RealName, UserAccount, OutID, UserName, AuthenName, AuthenType, NickName);

                    #endregion
                }
            }
        }
    }
示例#7
0
    protected void ssoFunc()
    {
        string QH = System.Configuration.ConfigurationManager.AppSettings["HQList"];
        //上海,广州处理
        string UAOUTID = System.Configuration.ConfigurationManager.AppSettings["UAOUTIDLIst"];

        string UAProvinceID = Request.Cookies["UAProvinceID"].Value.ToString();

        //是否是SSO的省
        if (QH.IndexOf(UAProvinceID) < 0 && UAOUTID.IndexOf(UAProvinceID) < 0)
        {
            Response.Redirect("../ErrorInfo.aspx?Result=-19999&ErrorInfo=未开通单点登录&FunctionName=请从 http://jf.ct10000.com 直接登入集团积分商城", true);
            return;
        }

        MBOSSClass mboss            = new MBOSSClass();
        string     AssertionAddress = Request.Cookies["AssertionAddress"].Value.ToString();         //获取断言查询地址
        string     TransactionID    = Request.Cookies["TransactionID"].Value.ToString();            //获取流水号

        string xml    = "";
        int    result = -19999;
        string ErrMsg = "";

        string SPID = UAProvinceID + "999991";
        string CustID = "", RealName = "", NickName = "", UserName = "", OutID = "", UserAccount = "", CustType = "", ProvinceID = "", AuthenName = "", AuthenType = "";

        try
        {
            SPInfoManager spInfo = new SPInfoManager();
            Object        SPData = spInfo.GetSPData(this.Context, "SPData");
            //密钥
            string key = spInfo.GetPropertyBySPID(SPID, "SecretKey", SPData);
            //断言
            MBOSSClass.BilByCompilingResult bil = new MBOSSClass.BilByCompilingResult();
            //查询断言并解析
            result     = mboss.SendUATicket(UAProvinceID, SPID, UATicket, AssertionAddress, this.Context, "SPCAData", TransactionID, out bil, out xml, out ErrMsg);
            AuthenType = bil.AccountType;
            AuthenName = bil.AccountID;

            if (result != 0)
            {
                Response.Redirect("../ErrorInfo.aspx?Result=-19999&ErrorInfo=请从网厅登陆1&FunctionName=请从网厅登陆1", true);
                return;
            }
            //用户入库是否存在
            int    type           = 0;
            string p              = bil.AccountID;
            string dealType       = "";
            string areaid         = "";
            string jtUAProvinceID = "";

            log("UAProvinceID:集团ua:" + UAProvinceID);

            if ("35".Equals(UAProvinceID))
            {
                if (!"".Equals(bil.ProvinceID))
                {
                    jtUAProvinceID = bil.ProvinceID;
                }
                else
                {
                    jtUAProvinceID = UAProvinceID;
                }

                result = 0;
                type   = 1;
            }
            else
            {
                result = BTForBusinessSystemInterfaceRules.MUserAuthV2(SPID, UAProvinceID, bil.AccountID, bil.AccountType, bil.AccountInfos, Context,
                                                                       out ErrMsg, out CustID, out UserAccount, out CustType, out OutID, out ProvinceID,
                                                                       out RealName, out UserName, out NickName, out dealType, out type, out areaid);
                log(bil.ProvinceID + "-!35-BTForBusinessSystemInterfaceRules.MUserAuthV2:" + result + "-bil.ProvinceID=" + bil.ProvinceID + "-UAProvinceID=" + UAProvinceID + "-areaid=" + areaid + "-custid=" + CustID + "-OutID=" + OutID + "-ErrMsg=" + ErrMsg);
            }

            string CustID1   = CustID;
            string RealName1 = "";
            string UserName1 = "";
            string NickName1 = "";
            string CustType1 = "";
            log("MUserAuthV2:" + result + ";CustID=" + CustID + " @----@" + ErrMsg + "==" + type);
            if (result != 0)
            {
                Response.Redirect("../ErrorInfo.aspx?Result=-19999&ErrorInfo=" + ErrMsg + "&FunctionName=请从网厅登陆2", true);
                return;
            }
            //模式3情况下,获取证件号和类型
            string TestStr = "";
            if (type == 1)
            {
                string OutID1 = "";
                if (QH.IndexOf(UAProvinceID) >= 0)
                {
                    if (bil.AccountType == "9" || bil.AccountType == "10" || bil.AccountType == "11")
                    {
                        if (areaid != "")
                        {
                            bil.AccountID = areaid + "-" + bil.AccountID;
                        }
                    }
                }
                else if (UAOUTID.IndexOf(UAProvinceID) >= 0)
                {
                    bil.AccountID   = OutID;
                    bil.AccountType = "99";

                    RealName = bil.AccountID;
                }
                else
                {
                    if (bil.AccountType == "9" || bil.AccountType == "10" || bil.AccountType == "11")
                    {
                        string phone = "";
                        areaid = BTForBusinessSystemInterfaceRules.PhoneToArea(UAProvinceID, bil.AccountID, out phone);
                        if (areaid != "")
                        {
                            bil.AccountID = areaid + "-" + phone;
                        }
                    }
                }

                int result1 = -1234;
                if ("35".Equals(UAProvinceID))
                {
                    log("CrmSSO.UserAuthCrm1:provinceid=" + bil.ProvinceID + ";areacode:" + bil.AccountInfos[0].areaid + ";accountid:" + bil.AudienceID + "|TestStr=" + TestStr);
                    result1 = CrmSSO.UserAuthCrm1(bil.ProvinceID, bil.AccountInfos[0].areaid, bil.AccountType, bil.AccountID, p, "", "0", UAProvinceID + "999991", this.Context, out RealName1, out UserName1, out NickName1, out OutID1, out CustType1, out CustID1, out ErrMsg, out TestStr);
                }
                else
                {
                    result1 = CrmSSO.UserAuthCrm(UAProvinceID, bil.AccountType, bil.AccountID, p, "", "0", UAProvinceID + "999991", this.Context, out RealName1, out UserName1, out NickName1, out OutID1, out CustType1, out CustID1, out ErrMsg, out TestStr);
                }

                if (result1 == 0)
                {
                    OutID    = OutID1;
                    CustID   = CustID1;
                    CustType = CustType1;
                }
                else
                {
                    Response.Redirect("../ErrorInfo.aspx?Result=" + result1 + "&ErrorInfo=" + ErrMsg + "&FunctionName=请从网厅登陆5", true);
                    return;
                }
                UserName = RealName1;
                NickName = RealName1;
                log(result1 + "==" + UAProvinceID + "=UAProvinceID;" + bil.AccountType + " =bil.AccountType;" + bil.AccountID + "=bil.AccountID;" + "" + "" + RealName + "=RealName;" + UserName + "=UserName;" + NickName +
                    "=NickName;" + OutID + "=OutID;" + CustType + "=CustType;" + CustID + "=CustID1;" + ErrMsg + "=ErrMsg");
            }

            if (dealType == "0")             //通知积分系统
            {
                CIP2BizRules.InsertCustInfoNotify(CustID, "2", System.Configuration.ConfigurationManager.AppSettings["ScoreBesttoneSPID"], "", "0", out ErrMsg);
            }

            //生成cookie
            UserToken UT             = new UserToken();
            string    UserTokenValue = UT.GenerateUserToken(CustID, RealName, UserName, NickName, OutID, CustType, AuthenName, AuthenType, key, out ErrMsg);
            string    CookieName     = System.Configuration.ConfigurationManager.AppSettings["CookieName"];
            PageUtility.SetCookie(UserTokenValue, CookieName, this.Page);

            //生成ticket
            result = CIPTicketManager.insertCIPTicket(TransactionID, SPID, CustID, RealName, NickName, UserName, OutID, "", AuthenName, AuthenType, out ErrMsg);
            log("insertCIPTicket:" + ErrMsg + result);
            if (result != 0)
            {
                Response.Redirect("../ErrorInfo.aspx?Result=-19999&ErrorInfo=请从网厅登陆3&FunctionName=请从网厅登陆3", true);
                return;
            }

            string Url = Request.Cookies["ReturnURL"].Value.ToString(); // System.Configuration.ConfigurationManager.AppSettings["SSOReturnURL"]; ;

            PageUtility.ExpireCookie("ReturnURL", this.Page);
            PageUtility.ExpireCookie("SPID", this.Page);
            PageUtility.ExpireCookie("UAProvinceID", this.Page);
            PageUtility.ExpireCookie("TransactionID", this.Page);

            Response.Redirect(Url + "?Ticket=" + TransactionID);
        }
        catch (System.Exception ex)
        {
            ErrMsg = ex.Message;
        }
        finally
        {
            try
            {
                CommonBizRules.WriteDataCustAuthenLog(SPID, CustID, ProvinceID, AuthenType, AuthenName, "2", result, ErrMsg);
            }
            catch { }
        }
    }