/// <summary> /// 根据OpenId获取用户 /// </summary> /// <param name="appId"></param> /// <param name="openId"></param> /// <returns></returns> public AppUserAccountInfo GetByOpenId(string appId, string openId) { ArgumentHelper.AssertNotNullOrEmpty(appId, "appId is null"); ArgumentHelper.AssertNotNullOrEmpty(openId, "openId is null"); return(AppUserAccountDao.GetByOpenId(appId, openId)); }
public List <AppUserAccountInfo> GetListByUserId(int tenantId, string[] userIds, string appId) { ArgumentHelper.AssertIsTrue(tenantId > 0, "tenantId is 0"); ArgumentHelper.AssertIsTrue(userIds != null && userIds.Length > 0, "userIds is null or empty"); ArgumentHelper.AssertNotNullOrEmpty(appId, "appId is null"); var result = new List <AppUserAccountInfo>(); if (userIds.Length > 100) { var userIdGroup = new List <string>(); var group = new List <string>(); for (var i = 1; i <= userIds.Length; i++) { group.Add(userIds[i]); if (i % 100 == 0) { userIdGroup.Add(string.Join("|", group)); group = new List <string>(); } } foreach (var ug in userIdGroup) { result.AddRange(AppUserAccountDao.GetListByUserId(tenantId, ug, appId)); } } else { result.AddRange(AppUserAccountDao.GetListByUserId(tenantId, string.Join(",", userIds), appId)); } return(result); }
/// <summary> /// 增加开放平台帐号信息 /// </summary> /// <param name="tenantId"></param> /// <param name="info"></param> /// <param name="isSaveMultiTenant"></param> public string Add(int tenantId, AppAccountInfo info, bool isSaveMultiTenant = true) { ArgumentHelper.AssertIsTrue(tenantId > 0, "TenantId is 0"); ArgumentHelper.AssertIsTrue(info != null, "AppAccountInfo is null"); ArgumentHelper.AssertIsTrue(info.TenantId > 0, "AppAccountInfo.TenantId is 0"); ArgumentHelper.AssertNotNullOrEmpty(info.Name, "AppAccountInfo.AppAccountName is null or empty"); ArgumentHelper.AssertNotNullOrEmpty(info.AppId, "AppAccountInfo.AppId is null or empty"); ArgumentHelper.AssertNotNullOrEmpty(info.AppSecret, "AppAccountInfo.AppSecret is null or empty"); AppAccountDao.Insert(info); if (isSaveMultiTenant && info.TenantId > 1) { try { AppAccountDao.SaveMultiTenant(info); } catch (Exception ex) { AppConnectLogHelper.Error("保存多租赁信息出错,AppAccountId=" + info.AppAccountId, ex); } } return(info.AppAccountId); }
/// <summary> /// 激活绑定 /// </summary> /// <param name="code"></param> public bool Activate(string code) { ArgumentHelper.AssertNotNullOrEmpty(code, "code is null"); var args = CryptographyHelper.AESDecrypt(code).Split('_'); var tenantId = Convert.ToInt32(args[0]); var bindBatchId = Convert.ToInt32(args[1]); var bindBatch = ProviderGateway.BindBatchProvider.Get(tenantId, bindBatchId); if (bindBatch == null || bindBatch.State != BindBatchState.UnUse) { return(false); } var appUserAccount = GetById(tenantId, bindBatch.AppUserAccountId); if (appUserAccount == null || appUserAccount.State != AppUserAccountState.Inactive || appUserAccount.BeisenAccount != bindBatch.BeisenAccount) { return(false); } UpdateState(tenantId, bindBatch.AppUserAccountId, AppUserAccountState.Activated); ProviderGateway.BindBatchProvider.UpdateState(tenantId, bindBatchId, BindBatchState.Used); return(true); }
public async Task SetMetadata(ImageMetadata metadata, CancellationToken cancellationToken) { ArgumentHelper.AssertNotNull(nameof(metadata), metadata); ArgumentHelper.AssertNotNullOrEmpty(nameof(metadata.Id), metadata.Id); ArgumentHelper.AssertNotNullOrEmpty(nameof(metadata.PartitionKey), metadata.PartitionKey); ArgumentHelper.AssertNotNullOrEmpty(nameof(metadata.MimeType), metadata.MimeType); ArgumentHelper.AssertNotNullOrEmpty(nameof(metadata.MD5Hash), metadata.MD5Hash); if (metadata.SizeBytes <= 0) { throw new ArgumentOutOfRangeException(nameof(metadata.SizeBytes)); } if (metadata.Width <= 0) { throw new ArgumentOutOfRangeException(nameof(metadata.Width)); } if (metadata.Height <= 0) { throw new ArgumentOutOfRangeException(nameof(metadata.Height)); } var container = await GetContainer(); await container.UpsertItemAsync(metadata, new PartitionKey(metadata.PartitionKey), cancellationToken : cancellationToken) .ConfigureAwait(false); }
/// <summary> /// 解绑账户 /// </summary> /// <param name="appId"></param> /// <param name="openId"></param> public void UnBind(string appId, string openId) { ArgumentHelper.AssertNotNullOrEmpty(appId, "appId is null"); ArgumentHelper.AssertNotNullOrEmpty(openId, "openId is null"); AppUserAccountDao.UnBind(appId, openId); }
/// <summary> /// 注册用户 /// </summary> /// <param name="tenantId"></param> /// <param name="mobile"></param> /// <param name="code"></param> /// <param name="codeType"></param> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="inviteUserId"></param> /// <param name="message"></param> /// <param name="registerType"></param> /// <returns></returns> public bool Register(int tenantId, string mobile, int code, int codeType, string userName, string password, int inviteUserId, out string message, int registerType = 1) { ArgumentHelper.AssertPositive(tenantId, "tenantId is 0"); ArgumentHelper.AssertPositive(inviteUserId, "inviteUserId is 0"); ArgumentHelper.AssertNotNullOrEmpty(mobile, "mobile is null"); ArgumentHelper.AssertNotNullOrEmpty(userName, "userName is null"); ArgumentHelper.AssertNotNullOrEmpty(password, "password is null"); message = string.Empty; var registerUserInfo = new RegisterUserInfo { TenantId = tenantId, //Email = GetVirtualEmail(mobile), Name = userName, Password = password, InviteUser = inviteUserId, Mobile = mobile, RegisterType = registerType }; if (Validate(registerUserInfo, code, codeType, out message)) { var userId = ProviderGateway.StaffProvider.CreateStaff(registerUserInfo); message = userId > 0 ? "注册成功" : "注册失败"; return(userId > 0); } return(false); }
public async Task <bool> RemoveMetadata(string imageId, string partitionKey, CancellationToken cancellationToken) { ArgumentHelper.AssertNotNullOrEmpty(nameof(imageId), imageId); ArgumentHelper.AssertNotNullOrEmpty(nameof(partitionKey), partitionKey); var container = await GetContainer(); ItemResponse <ImageMetadata> response; try { response = await container.DeleteItemAsync <ImageMetadata>(imageId, new PartitionKey(partitionKey), cancellationToken : cancellationToken) .ConfigureAwait(false); } catch (CosmosException ex) { if (ex.StatusCode == HttpStatusCode.NotFound) { return(false); } throw; } return(response.StatusCode == HttpStatusCode.NoContent); }
/// <summary> /// 增加二维码登录 /// </summary> /// <param name="info"></param> /// <returns></returns> public void Add(QrCodeLoginInfo info) { ArgumentHelper.AssertIsTrue(info != null, "QrCodeLoginInfo is null"); ArgumentHelper.AssertNotNullOrEmpty(info.Code, "QrCodeLoginInfo.Code is null or empty"); ArgumentHelper.AssertIsTrue(info.TitaAppId > 0, "info.TitaAppId is less than 0"); QrCodeLoginDao.Insert(info); }
/// <summary> /// 根据TenantId和状态获取用户 /// </summary> /// <param name="tenantId"></param> /// <param name="appId"></param> /// <param name="states"></param> /// <returns></returns> public List <AppUserAccountInfo> GetByTenantId(int tenantId, string appId, string states) { ArgumentHelper.AssertIsTrue(tenantId > 0, "tenantId is 0"); ArgumentHelper.AssertNotNullOrEmpty(appId, "appId is null"); ArgumentHelper.AssertNotNullOrEmpty(states, "states is null"); return(AppUserAccountDao.GetByTenantId(tenantId, appId, states)); }
/// <summary> /// 根据UserId获取用户 /// </summary> /// <param name="tenantId"></param> /// <param name="userId"></param> /// <param name="appId"></param> /// <returns></returns> public AppUserAccountInfo GetByUserId(int tenantId, int userId, string appId) { ArgumentHelper.AssertIsTrue(tenantId > 0, "tenantId is 0"); ArgumentHelper.AssertIsTrue(userId > 0, "userId is 0"); ArgumentHelper.AssertNotNullOrEmpty(appId, "appId is null"); return(AppUserAccountDao.GetByUserId(tenantId, userId, appId)); }
public Uri GetImageUri(string imageName, ImageSizeType imageSizeType) { ArgumentHelper.AssertNotNullOrEmpty(nameof(imageName), imageName); var blockBlob = GetBlockBlob(imageName, imageSizeType); return(blockBlob.Uri); }
/// <summary> /// 更新邮件、短信发送批次 /// </summary> /// <param name="tenantId"></param> /// <param name="id"></param> /// <param name="batchId"></param> public void UpdateBatchId(int tenantId, int id, string batchId) { ArgumentHelper.AssertIsTrue(tenantId > 0, "tenantId is 0"); ArgumentHelper.AssertIsTrue(id > 0, "id is 0"); ArgumentHelper.AssertNotNullOrEmpty(batchId, "batchId is null"); BindBatchDao.UpdateBatchId(tenantId, id, batchId); }
public async Task <bool> TryDeleteImage(string imageName, ImageSizeType imageSizeType, CancellationToken cancellationToken) { ArgumentHelper.AssertNotNullOrEmpty(nameof(imageName), imageName); var blockBlob = GetBlockBlob(imageName, imageSizeType); return(await blockBlob.DeleteIfExistsAsync(cancellationToken).ConfigureAwait(false)); }
public int Add(TemplateMappingInfo info) { ArgumentHelper.AssertNotNull(info, "TemplateMappingInfo is null"); ArgumentHelper.AssertNotNullOrEmpty(info.AppId, "TemplateMappingInfo.appId is null"); ArgumentHelper.AssertNotNullOrEmpty(info.TemplateIdShort, "TemplateMappingInfo.TemplateIdShort is null"); ArgumentHelper.AssertNotNullOrEmpty(info.TemplateId, "TemplateMappingInfo.TemplateId is null"); return(TemplateMappingDao.Insert(info)); }
/// <summary> /// 获取二维码图片 /// </summary> /// <param name="tenantId"></param> /// <param name="appAccountId"></param> /// <param name="type"></param> /// <param name="code"></param> /// <param name="size"></param> /// <returns></returns> public byte[] GenerateQrCodePicture(int tenantId, string appAccountId, int type, string code, int size) { ArgumentHelper.AssertNotNullOrEmpty(code, "code is null or empty"); AppConnectLogHelper.DebugFormat("调用GenerateQrCodePicture方法:tenantId:{0},code:{1}", tenantId, code); var scanUrl = UrlHelper.AddParameter(AppConnectHostConfig.Cache[0] + HostConst.QrCodeScanLogin, "code", code); AppConnectLogHelper.DebugFormat("scanUrl:{0}", scanUrl); return(QrCodeHelper.Generate(scanUrl, size)); }
public List <AppUserAccountInfo> ConvertToUserId(string appAccountId, List <string> openIds) { ArgumentHelper.AssertNotNullOrEmpty(appAccountId, "appId is null"); ArgumentHelper.AssertIsTrue(openIds != null && openIds.Count > 0, "openId is null"); var appAccount = ProviderGateway.AppAccountProvider.Get(appAccountId); return(AppUserAccountDao.ConvertToUserId(appAccount.TenantId, appAccount.AppId, string.Join(",", openIds))); }
/// <summary> /// 获取Ticket /// </summary> /// <param name="appAccountId"></param> /// <param name="ticketType"></param> /// <param name="getNewToken"></param> /// <returns></returns> public string GetTicket(string appAccountId, string ticketType, bool getNewToken = false) { ArgumentHelper.AssertNotNullOrEmpty(appAccountId, "appAccountId is null or empty"); ArgumentHelper.AssertNotNullOrEmpty(ticketType, "ticketType is null or empty"); var account = AppAccountProvider.Instance.Get(appAccountId); return(GetTicket(account, ticketType, getNewToken)); }
/// <summary> /// 增加返回信息 /// </summary> /// <param name="content"></param> public void Add(CallbackContentInfo content) { ArgumentHelper.AssertIsTrue(content != null, "content is null"); ArgumentHelper.AssertIsTrue(content.TenantId >= 0, "AppAccountInfo.TenantId is less than 0"); ArgumentHelper.AssertNotNullOrEmpty(content.BatchId, "content.BatchId is null or empty"); ArgumentHelper.AssertNotNullOrEmpty(content.AppAccountPublic, "content.AppAccountPublic is null or empty"); ArgumentHelper.AssertNotNullOrEmpty(content.Content, "content.Content is null or empty"); CallbackContentDao.Insert(content); }
/// <summary> /// 增加绑定批次 /// </summary> /// <param name="tenantId"></param> /// <param name="info"></param> /// <returns></returns> public int Add(int tenantId, BindBatchInfo info) { ArgumentHelper.AssertIsTrue(tenantId > 0, "tenantId is 0"); ArgumentHelper.AssertNotNull(info, "info is null"); ArgumentHelper.AssertIsTrue(info.TenantId > 0, "info.TenantId is 0"); ArgumentHelper.AssertIsTrue(info.AppUserAccountId > 0, "info.AppUserAccountId is 0"); ArgumentHelper.AssertNotNullOrEmpty(info.BeisenAccount, "info.BeisenAccount is null"); return(BindBatchDao.Insert(tenantId, info)); }
/// <summary> /// 获取Ticket /// </summary> /// <param name="account"></param> /// <param name="ticketType"></param> /// <param name="getNewToken"></param> /// <returns></returns> public string GetTicket(AppAccountInfo account, string ticketType, bool getNewToken = false) { ArgumentHelper.AssertIsTrue(account != null, "AppAccountInfo is null"); ArgumentHelper.AssertNotNullOrEmpty(ticketType, "ticketType is null or empty"); var token = ProviderGateway.TokenProvider.GetToken(account); var ticketInstance = TicketFactory.GetTicketIntance(account); return(ticketInstance.GetTicket(account, token, ticketType, getNewToken)); }
public int Add(MessageInfo info) { ArgumentHelper.AssertIsTrue(info != null, "MessageInfo is null"); ArgumentHelper.AssertNotNullOrEmpty(info.BatchId, "MessageInfo.BatchId is null or empty"); ArgumentHelper.AssertIsTrue(info.TenantId > 0, "MessageInfo.TenantId is 0"); ArgumentHelper.AssertNotNullOrEmpty(info.AppAccountId, "MessageInfo.AppAccountId is null or empty"); ArgumentHelper.AssertNotNullOrEmpty(info.ContentJson, "MessageInfo.ContentJson is null or empty"); return(MessageDao.Insert(info)); }
/// <summary> /// 获取验证码 /// </summary> /// <param name="batch"></param> /// <returns></returns> public byte[] GetCaptchaImage(string batch) { ArgumentHelper.AssertNotNullOrEmpty(batch, "batch is null"); string captcha; var data = CaptchaImageHelper.CreatBitmap(out captcha); RedisHelper.SetRedis(RedisConstName.Captcha + batch, captcha, 1800); return(data); }
public ActionResult Image(string code, int size = 320, int tenant_id = 0, string appaccount_id = "", int type = 12) { ArgumentHelper.AssertNotNullOrEmpty(code, "code is null or empty"); AppConnectLogHelper.DebugFormat("调用Image方法:code:{0}", code); var file = ProviderGateway.QrCodeLoginProvider.GenerateQrCodePicture(tenant_id, appaccount_id, type, code, size); if (file == null || file.Length <= 0) { AppConnectLogHelper.Error("file stream is null"); } return(File(file, "image/png")); }
/// <summary> /// 更新二维码登录状态 /// </summary> /// <param name="code"></param> /// <param name="state"></param> public void UpdateState(string code, QrCodeLoginState state) { ArgumentHelper.AssertNotNullOrEmpty(code, "Code is null or empty"); var info = GetByCode(code); if (info != null) { info.State = state; QrCodeLoginDao.UpdateState(info); } }
public void Update(int tenantId, MenuInfo info) { ArgumentHelper.AssertIsTrue(info != null, "MenuInfo is null"); ArgumentHelper.AssertNotNullOrEmpty(info.MenuId, "MenuInfo.MenuId is null or empty"); ArgumentHelper.AssertNotNullOrEmpty(info.Name, "MenuInfo.Name is null or empty"); ArgumentHelper.AssertIsTrue(info.TenantId > 0, "MenuInfo.TenantId is 0"); ArgumentHelper.AssertNotNullOrEmpty(info.AppAccountId, "MenuInfo.AppAccountId is null or empty"); ArgumentHelper.AssertIsTrue(info.BeisenAppId > 0, "MenuInfo.BeisenAppId is 0"); ArgumentHelper.AssertNotNullOrEmpty(info.Url, "MenuInfo.Url is null or empty"); MenuDao.Update(info); }
/// <summary> /// 扫码二维码 /// </summary> /// <param name="code"></param> /// <returns></returns> public bool Scan(string code) { ArgumentHelper.AssertNotNullOrEmpty(code, "code is null or empty"); var qrCodeLoginInfo = GetByCode(code); if (qrCodeLoginInfo == null || (qrCodeLoginInfo.State != QrCodeLoginState.UnLogin && qrCodeLoginInfo.State != QrCodeLoginState.Cancel)) { return(false); } UpdateState(code, QrCodeLoginState.Scanned); return(true); }
/// <summary> /// 增加用户账户 /// </summary> /// <param name="tenantId"></param> /// <param name="appUserAccountInfo"></param> public int AddOrUpdate(int tenantId, AppUserAccountInfo appUserAccountInfo) { ArgumentHelper.AssertIsTrue(tenantId > 0, "tenantId is 0"); ArgumentHelper.AssertNotNull(appUserAccountInfo, "appUserAccountInfo is null"); ArgumentHelper.AssertNotNullOrEmpty(appUserAccountInfo.AppId, "appUserAccountInfo.appId is null"); ArgumentHelper.AssertNotNullOrEmpty(appUserAccountInfo.OpenId, "appUserAccountInfo.openId is null"); ArgumentHelper.AssertIsTrue(appUserAccountInfo.TenantId > 0, "appUserAccountInfo.TenantId is 0"); ArgumentHelper.AssertIsTrue(appUserAccountInfo.UserId > 0, "appUserAccountInfo.UserId is 0"); var sqlId = AppUserAccountDao.InsertOrUpdate(tenantId, appUserAccountInfo); AppUserAccountDao.AddOrUpdateCLoud(tenantId, sqlId, appUserAccountInfo); return(sqlId); }
public string GetTemplateId(string appId, string templateIdShort) { ArgumentHelper.AssertNotNullOrEmpty(appId, "appId is null"); ArgumentHelper.AssertNotNullOrEmpty(templateIdShort, "appId is null"); var templateMapping = TemplateMappingDao.Get(appId, templateIdShort); if (templateMapping == null) { return(string.Empty); } return(templateMapping.TemplateId); }
/// <summary> /// 根据Code获取二维码登录 /// </summary> /// <param name="code"></param> /// <returns></returns> public QrCodeLoginInfo GetAndUpdateByCode(string code) { ArgumentHelper.AssertNotNullOrEmpty(code, "Code is null or empty"); var qrcode = GetByCode(code); if (qrcode != null && qrcode.State == QrCodeLoginState.Login) { qrcode = qrcode.Clone(); UpdateState(code, QrCodeLoginState.Invalid); } return(qrcode); }