/// <summary> /// 获取商家实体[token filter用到] /// </summary> /// <param name="token"></param> /// <returns></returns> public MerchantAccount GetMerchantAccountByToken(string token) { MerchantAccount account = null; string merchantId = string.Empty; WebRedis.GetWebTokenIndRedis(token, out merchantId); var result = Guid.TryParse(merchantId, out Guid guid); if (result) { account = new MerchantAccountDAC().GetById(guid); if (account == null) { throw new CommonException(ReasonCode.UNAUTHORIZED, "未授权"); } if (!account.POSId.HasValue) { throw new CommonException(ReasonCode.ACCOUNT_UNBUNDLED, "帐号已被解绑"); } if (account.Status == AccountStatus.Locked) { throw new CommonException(ReasonCode.ACCOUNT_LOCKED, "账户已锁定"); } } return(account); }
/// <summary> /// 获取登录二维码 /// </summary> /// <returns></returns> public string GetLoginQRcode() { string qrCodeKey = WebConfig.QRCodePrefix + Guid.NewGuid().ToString("N"); //写入redis bool reuslt = WebRedis.SetLoginQRCodeIndRedis(qrCodeKey, "0"); return(qrCodeKey); }
/// <summary> /// POS机扫码登录Web[更新redis的key=qrcode,value=token] /// </summary> /// <param name="musername">apptoken</param> /// <param name="qrcode">二维码字符串</param> /// <returns>返回成功/失败</returns> public bool ScanQRLogin(string musername, string qrcode) { if (string.IsNullOrEmpty(musername) || string.IsNullOrEmpty(qrcode)) { return(false); } //填充qrcode存在的token bool result = WebRedis.SetLoginQRCodeIndRedis(qrcode, musername); return(result); }
/// <summary> /// 获取登录数据[轮询] /// </summary> /// <returns>0=还没有扫码 -1=qrcode已失效 -2=创建token失败 1=成功</returns> public int GetLoginData(string qrcode, out string webToken) { webToken = string.Empty; //获取userName string merchantUserName = WebRedis.GetLoginQRCodeIndRedis(qrcode); if (string.IsNullOrEmpty(merchantUserName)) { return(-1); } if (merchantUserName == "0")//表示还没有扫码 { return(0); } bool result = WebRedis.SetWebTokenIndRedis(merchantUserName, out webToken); if (result) { WebRedis.DeleteLoginQRCodeIndRedis(qrcode); } return(result ? 1 : -2); }