/// <summary> /// 小程序AD验证 /// </summary> /// <param name="dto"></param> /// <returns></returns> public async Task <ReturnValueModel> GetSaleUserInfo(VerifyInputDto dto) { ReturnValueModel rvm = new ReturnValueModel(); if (string.IsNullOrEmpty(dto?.ADAccount)) { rvm.Success = false; rvm.Msg = "fail"; rvm.Result = "请输入账号。"; return(rvm); } if (string.IsNullOrEmpty(dto?.Password)) { rvm.Success = false; rvm.Msg = "fail"; rvm.Result = "请输入密码。"; return(rvm); } if (string.IsNullOrEmpty(dto?.openId)) { rvm.Success = false; rvm.Msg = "fail"; rvm.Result = "请输入密码。"; return(rvm); } var encryptedData = dto.encryptedData; var iv = dto.iv; //小程序用户基本信息 var wxUserInfo = dto.userInfo ?? new DecodedUserInfoModel(); //匹配AD白名单 var isWhiteName = await CheckWhiteName(dto.ADAccount); if (!isWhiteName) { rvm.Msg = "fail"; rvm.Success = false; rvm.Result = "您输入的账号无权限访问。"; LoggerHelper.WriteLogInfo("[CheckWhiteName]:错误------不在白名单"); return(rvm); } //验证AD域 var verify = await GetVerifyApi(dto.ADAccount, dto?.Password); if (verify.Success == false) { return(verify); } var saleADAccountUser = _rep.FirstOrDefault <WxSaleUserModel>(s => s.IsDeleted != 1 && s.ADAccount == dto.ADAccount.ToUpper()); if (saleADAccountUser != null) { saleADAccountUser.ADAccount = null; saleADAccountUser.Remark = dto.ADAccount.ToUpper(); _rep.Update(saleADAccountUser); } var saleUser = _rep.FirstOrDefault <WxSaleUserModel>(s => s.IsDeleted != 1 && s.OpenId == dto.openId); if (saleUser == null) { saleUser = new WxSaleUserModel { Id = Guid.NewGuid().ToString(), OpenId = dto.openId, UnionId = wxUserInfo.unionId, WxCity = wxUserInfo.city, WxName = wxUserInfo.nickName, WxCountry = wxUserInfo.country, WxGender = wxUserInfo.gender.ToString(), WxPicture = wxUserInfo.avatarUrl, WxProvince = wxUserInfo.province, CreateTime = DateTime.Now, ADAccount = dto.ADAccount.ToUpper(), }; _rep.Insert(saleUser); _rep.SaveChanges(); } else { saleUser.OpenId = dto.openId; saleUser.UnionId = wxUserInfo.unionId; saleUser.WxCity = wxUserInfo.city; saleUser.WxName = wxUserInfo.nickName; saleUser.WxCountry = wxUserInfo.country; saleUser.WxGender = wxUserInfo.gender.ToString(); saleUser.WxPicture = wxUserInfo.avatarUrl; saleUser.WxProvince = wxUserInfo.province; saleUser.UpdateTime = DateTime.Now; saleUser.ADAccount = dto.ADAccount.ToUpper(); saleUser.Remark = null; _rep.Update(saleUser); _rep.SaveChanges(); } _wxRegisterService.CacheWxSaleUser(saleUser);//必须添加到内存 string _host = ConfigurationManager.AppSettings["HostUrl"]; var authPath = $@"{_host}/api/auth/token/WxSale"; var postStr = $@"username={saleUser.Id}&grant_type=password"; SysToken sysToken = HttpUtils.PostResponse <SysToken>(authPath, postStr, "application/x-www-form-urlencoded"); rvm.Success = true; rvm.Msg = "success"; rvm.Result = new { sysTokenUrl = authPath, sysToken,//管理平台 token username = saleUser.Id, grant_type = "password", verify = true, }; return(rvm); }
public async Task <IHttpActionResult> GetSaleUserInfo([FromBody] VerifyInputDto dto) { var ret = await _aDVerifyService.GetSaleUserInfo(dto); return(Ok(ret)); }