public ResponseResult <ThirdPartyLoginResult> Bind(ThirdPartyBindingModel model)
        {
            var app = OAuthAppCache.Get(model.Appid);

            if (app == null)
            {
                return(Fail <ThirdPartyLoginResult>("无效的应用id", "0400"));
            }
            //先绑定手机号
            string plainText;

            if (!xUtils.RsaDecrypt(model.AuthCode, out plainText))
            {
                return(Fail <ThirdPartyLoginResult>("授权码解密失败"));
            }
            int pos = plainText.IndexOf('_');

            string[] array = new string[2];
            array[0] = plainText.Substring(0, pos);
            array[1] = plainText.Substring(pos + 1);
            long timestamp;

            if (!long.TryParse(array[0], out timestamp))
            {
                return(Fail <ThirdPartyLoginResult>("授权码明文格式不正确"));
            }
            long currentTime = xUtils.GetCurrentTimeStamp();

            if (currentTime - timestamp > 120)
            {
                return(Fail <ThirdPartyLoginResult>("请求已过期", "0400"));
            }
            ThirdPartyBindingProvider binding = new ThirdPartyBindingProvider(model);

            if (!binding.Register())
            {
                return(Fail <ThirdPartyLoginResult>(binding.PromptInfo.CustomMessage));
            }
            //再调用登录
            int    clientSource = 0;
            string csource      = Request.Headers["clientsource"];

            int.TryParse(csource, out clientSource);
            string clientSystem    = Request.Headers["clientsystem"];
            string device_id       = Request.Headers["device_id"];
            string userHostAddress = Request.Headers["X-FORWARD-FOR"];
            string sessionId       = Request.Headers["sessionId"];
            string clientVersion   = Request.Headers["clientversion"];
            var    thirdLogin      = new ThirdPartyLoginProvider(binding.User);
            var    result          = thirdLogin.Login(clientSource, clientSystem, device_id, clientVersion, userHostAddress, sessionId, app.Id);

            if (!result.Success)
            {
                return(Fail <ThirdPartyLoginResult>("第三方账号绑定成功,但登陆失败,请重新登录!", "0202"));
            }
            //return new ApiResult<ThirdPartyLoginResult> { retCode = "0000", retMsg = "ok", Data = result.Content };
            return(Success(result.Content));
        }
        public ResponseResult <ThirdPartyLoginResult> Login(ThirdpartyLoginRequestDTO model)
        {
            var app = OAuthAppCache.Get(model.Appid);

            if (app == null)
            {
                return(Fail <ThirdPartyLoginResult>("无效的应用id", "0400"));
            }
            string plainText;

            if (!xUtils.RsaDecrypt(model.AuthCode, out plainText))
            {
                return(Fail <ThirdPartyLoginResult>("授权码解密失败"));
            }
            int pos = plainText.IndexOf('_');

            string[] array = new string[2];
            array[0] = plainText.Substring(0, pos);
            array[1] = plainText.Substring(pos + 1);
            long timestamp;

            if (!long.TryParse(array[0], out timestamp))
            {
                return(Fail <ThirdPartyLoginResult>("授权码明文格式不正确", "0400"));
            }
            long currentTime = xUtils.GetCurrentTimeStamp();

            if (currentTime - timestamp > 120)
            {
                return(Fail <ThirdPartyLoginResult>("请求已过期", "0403"));
            }
            string trueOpenID = array[1];
            var    fac        = UserModuleFactory.GetUserModuleInstance();
            IUser  user       = fac?.GetUserByVoucher(trueOpenID, (UserVoucherType)model.PlatformID);
            var    thirdLogin = new ThirdPartyLoginProvider(user);

            string csource = Request.Headers["clientsource"];

            int.TryParse(csource, out int clientSource);
            string clientSystem    = Request.Headers["clientsystem"];
            string device_id       = Request.Headers["device_id"];
            string userHostAddress = Request.Headers["X-FORWARD-FOR"];
            string sessionId       = Request.Headers["sessionId"];
            string clientVersion   = Request.Headers["clientversion"];
            //若登录失败,客户端需调用绑定手机号
            var result = thirdLogin.Login(clientSource, clientSystem, device_id, clientVersion, userHostAddress, sessionId, app.Id);

            if (!result.Success)
            {
                return(Fail <ThirdPartyLoginResult>("首次使用第三方登录,请先绑定账号!", "0202"));
            }
            return(Success(result.Content));
        }
        public ActionResult Bind(ThirdPartyBindingModel model)
        {
            var app = Facade.Caches.OAuthAppCache.Instance.Find(it => string.Equals(Package.MerchantNo, it.APP_CODE, StringComparison.OrdinalIgnoreCase));

            if (app == null)
            {
                return(FailResult("商户不存在", (int)ApiStatusCode.DATA_NOT_FOUND));
            }
            //先绑定手机号
            string plainText;

            if (!xUtils.RsaDecryptPayPwd(model.OpenID, out plainText))
            {
                return(FailResult("OpenID解密失败", (int)ApiStatusCode.DECRYPT_PASSWORD_FAIL));
            }
            int pos = plainText.IndexOf('_');

            string[] array = new string[2];
            array[0] = plainText.Substring(0, pos);
            array[1] = plainText.Substring(pos + 1);
            long timestamp;

            if (!long.TryParse(array[0], out timestamp))
            {
                return(FailResult("OpenID解密失败", (int)ApiStatusCode.DECRYPT_PASSWORD_FAIL));
            }
            long currentTime = xUtils.GetCurrentTimeStamp();

            if (currentTime - timestamp > 120)
            {
                return(FailResult("请求已过期", (int)ApiStatusCode.BAD_REQUEST));
            }
            ThirdPartyBindingProvider bindingProvider = new ThirdPartyBindingProvider(model);

            if (!bindingProvider.Register())
            {
                return(FailResult(bindingProvider.PromptInfo.CustomMessage));
            }
            //再调用登录
            var thirdLogin = new ThirdPartyLoginProvider((ThirdPartyLogin)model.ThirdParty, array[1]);
            var result     = thirdLogin.Login(this.Package, Request.UserHostAddress, Session.SessionID, app.APP_ID);

            return(Json(result));
        }
        public ActionResult Login([EnumDefine(typeof(ThirdPartyLogin))] int ThirdParty,
                                  [Required(ErrorMessage = "{0}不能为空"), Display(Name = "第三方会员ID")] string OpenID)
        {
            var app = Facade.Caches.OAuthAppCache.Instance.Find(it => string.Equals(Package.MerchantNo, it.APP_CODE, StringComparison.OrdinalIgnoreCase));

            if (app == null)
            {
                return(FailResult("商户不存在", (int)ApiStatusCode.DATA_NOT_FOUND));
            }
            string plainText;

            if (!xUtils.RsaDecryptPayPwd(OpenID, out plainText))
            {
                return(FailResult("OpenID解密失败", (int)ApiStatusCode.DECRYPT_PASSWORD_FAIL));
            }
            int pos = plainText.IndexOf('_');

            string[] array = new string[2];
            array[0] = plainText.Substring(0, pos);
            array[1] = plainText.Substring(pos + 1);
            long timestamp;

            if (!long.TryParse(array[0], out timestamp))
            {
                return(FailResult("OpenID解密失败", (int)ApiStatusCode.DECRYPT_PASSWORD_FAIL));
            }
            long currentTime = xUtils.GetCurrentTimeStamp();

            if (currentTime - timestamp > 120)
            {
                return(FailResult("请求已过期", (int)ApiStatusCode.BAD_REQUEST));
            }
            string trueOpenID = array[1];
            var    thirdLogin = new ThirdPartyLoginProvider((ThirdPartyLogin)ThirdParty, trueOpenID);
            var    result     = thirdLogin.Login(this.Package, Request.UserHostAddress, Session.SessionID, app.APP_ID);

            return(Json(result));
        }