/// <summary> /// 提交短信,并扣费 /// </summary> /// <param name="sms"></param> /// <returns></returns> public RPC_Result <SMS.DTO.SMSDTO> SendSMS(SMS.DTO.SMSDTO sms) { try { Account account = AccountDB.GetAccount(sms.Message.AccountID);//AccountServer.Instance.GetAccount(sms.Message.AccountID); if (account == null) { LogHelper.LogWarn("Pretreatment", "PretreatmentService.SendSMS", "系统中不存在此用户 -> {Account=" + sms.Message.AccountID + "}"); MessageTools.MessageHelper.Instance.WirteInfo("提交短信失败,PretreatmentService.SendSMS,系统中不存在此用户 -> {Account=" + sms.Message.AccountID + "}"); return(new RPC_Result <SMS.DTO.SMSDTO>(false, sms, "用户不存在")); } if (account.SMSNumber < sms.Message.NumberCount) { return(new RPC_Result <SMS.DTO.SMSDTO>(false, sms, "总共要发 " + sms.Message.FeeTotalCount + " 条短信,账号余额不足!")); } if (string.IsNullOrEmpty(sms.Message.SPNumber)) { sms.Message.SPNumber = defaultSPNumber.Split(',')[0]; } SMS.DB.SMSDAL.AddSMS(sms); account = AccountDB.GetAccount(sms.Message.AccountID); return(new RPC_Result <SMS.DTO.SMSDTO>(true, sms, "短信已提交成功,扣费:" + sms.Message.FeeTotalCount + "条,剩余" + account.SMSNumber + "条")); } catch (Exception ex) { MessageTools.MessageHelper.Instance.WirteError("发送短信时发生了异常", ex); return(new RPC_Result <SMS.DTO.SMSDTO>(false, sms, "发送短信时发生了异常")); } }
/// <summary> /// 账号扣费,返费 /// </summary> /// <param name="accountID">扣费账号</param> /// <param name="quantity">扣费数 可以为负</param> /// <returns></returns> public RPCResult AccountDeductSMSCount(string accountID, int quantity) { try { if (string.IsNullOrEmpty(accountID)) { LogHelper.LogWarn("SMSService", "SMSService.AccountDeductSMSCharge", "账号为空"); return(new RPCResult(false, "扣费账号不能为空!")); } Account account = AccountDB.GetAccount(accountID);// AccountServer.Instance.GetAccount(accountID); if (account == null) { LogHelper.LogWarn("SMSService", "SMSService.AccountDeductSMSCharge", "账号不存在"); return(new RPCResult(false, "账号不存在")); } if (AccountDB.DeductAccountSMSCharge(account.AccountID, (int)quantity)) { return(new RPCResult(true, "")); } LogHelper.LogWarn("SMSService", "SMSService.AccountDeductSMSCharge", "扣费数据库操作失败"); return(new RPCResult(false, "扣费失败")); } catch (Exception ex) { LogHelper.LogError("SMSService", "SMSService.AccountDeductSMSCharge", ex.ToString()); return(new RPCResult(false, "扣费失败")); } }
/// <summary> /// 账号充值 /// </summary> /// <param name="accountID">充值账号</param> /// <param name="quantity">充值数</param> /// <param name="operatorAccount">操作人</param> /// <returns></returns> public RPCResult AccountPrepaid(string accountID, uint quantity, string operatorAccount) { try { if (string.IsNullOrEmpty(accountID)) { LogHelper.LogWarn("SMSService", "SMSService.AccountPrepaid", "充值账号为空"); return(new RPCResult(false, "充值账号不能为空!")); } Account account = AccountDB.GetAccount(accountID);//AccountServer.Instance.GetAccount(accountID); if (account == null) { LogHelper.LogWarn("SMSService", "SMSService.AccountPrepaid", "充值账号不存在"); return(new RPCResult(false, "账号不存在")); } if (account.SMSNumber + (int)quantity < 0 && quantity > 10000000) { return(new RPCResult(false, "充值金额太大")); } if (AccountDB.AccountPrepaid(account.AccountID, (int)quantity)) { PrepaidRecordDB.Add(operatorAccount, accountID, quantity); return(new RPCResult(true, "充值成功")); } LogHelper.LogWarn("SMSService", "SMSService.AccountPrepaid", "充值数据库操作失败"); return(new RPCResult(false, "充值失败")); } catch (Exception ex) { LogHelper.LogError("SMSService", "SMSService.AccountPrepaid", ex.ToString()); return(new RPCResult(false, "充值失败")); } }
/// <summary> /// 提交短信,并扣费 /// </summary> /// <param name="sms"></param> /// <returns></returns> public RPC_Result <SMS.DTO.SMSDTO> SendSMS(SMS.DTO.SMSDTO sms) { try { Account account = AccountDB.GetAccount(sms.Message.AccountID);//AccountServer.Instance.GetAccount(sms.Message.AccountID); if (account == null) { LogHelper.LogWarn("Pretreatment", "PretreatmentService.SendSMS", "系统中不存在此用户 -> {Account=" + sms.Message.AccountID + "}"); MessageTools.MessageHelper.Instance.WirteInfo("提交短信失败,PretreatmentService.SendSMS,系统中不存在此用户 -> {Account=" + sms.Message.AccountID + "}"); return(new RPC_Result <SMS.DTO.SMSDTO>(false, sms, "用户不存在")); } if (account.SMSNumber < sms.Message.NumberCount) { return(new RPC_Result <SMS.DTO.SMSDTO>(false, sms, "总共要发 " + sms.Message.FeeTotalCount + " 条短信,账号余额不足!")); } SMS.DB.SMSDAL.AddSMS(sms); if (sms.Message.AuditType == AuditType.Auto || sms.Message.AuditType == AuditType.Template) { if (sms.Message.SMSTimer != null) { SMSDAL.AddSMSTimer(sms.Message.ID, sms.Message.SMSTimer.Value); } else { SMSSubmit.Instance.SendSMS(sms); } } account = AccountDB.GetAccount(sms.Message.AccountID); return(new RPC_Result <SMS.DTO.SMSDTO>(true, sms, "短信已提交成功,扣费:" + sms.Message.FeeTotalCount + "条,剩余" + account.SMSNumber + "条")); } catch (Exception ex) { MessageTools.MessageHelper.Instance.WirteError("发送短信时发生了异常", ex); return(new RPC_Result <SMS.DTO.SMSDTO>(false, sms, "发送短信时发生了异常")); } }
public void AccountTest() { Account account = new Account() { AccountID = guid.ToString(), SMSNumber = 10 }; var b = AccountDB.CreateAccount(account); Assert.IsTrue(b); b = AccountDB.AccountPrepaid(account.AccountID, 10); Assert.IsTrue(b); int c = AccountDB.GetSMSNumberByAccount(account.AccountID); Assert.AreEqual(20, c); var a = AccountDB.GetAccount(account.AccountID); Assert.IsNotNull(a); Assert.AreEqual(a.AccountID, account.AccountID); Assert.AreEqual(a.SMSNumber, 20); b = AccountDB.DeductAccountSMSCharge(account.AccountID, 10); Assert.IsTrue(b); c = AccountDB.GetSMSNumberByAccount(account.AccountID); Assert.AreEqual(10, c); b = AccountDB.ReAccountSMSCharge(account.AccountID, 10); Assert.IsTrue(b); c = AccountDB.GetSMSNumberByAccount(account.AccountID); Assert.AreEqual(20, c); var accs = AccountDB.GetAccounts(); Assert.IsNotNull(accs); Assert.IsTrue(accs.Count > 0); b = AccountDB.DelAccount(account.AccountID); Assert.IsTrue(b); }
/// <summary> /// 获取账号 /// </summary> /// <param name="accountID"></param> /// <returns></returns> public RPCResult <Account> GetAccount(string accountID) { if (string.IsNullOrEmpty(accountID)) { LogHelper.LogWarn("SMSService", "SMSService.GetAccount", "账号为空"); return(new RPCResult <Account>(false, null, "账号不能为空!")); } try { Account account = AccountDB.GetAccount(accountID); //AccountServer.Instance.GetAccount(accountID); if (account == null) { return(new RPCResult <Account>(false, null, "不存在用户")); } //account.Password = ""; return(new RPCResult <Account>(true, account, "")); } catch (Exception ex) { LogHelper.LogError("SMSService", "SMSService.GetAccount", ex.ToString()); return(new RPCResult <Account>(false, null, "获取账号出现异常!")); } }
/// <summary> /// Verifica os dados do usuário. /// </summary> /// <param name="version"></param> /// <param name="username"></param> /// <param name="passphrase"></param> /// <param name="result"></param> /// <returns></returns> public AccountData Authenticate(ClientVersion version, string username, string passphrase, out AuthenticationResult result) { if (Configuration.Maintenance) { result = AuthenticationResult.Maintenance; return(null); } if (!Configuration.Version.Compare(version)) { result = AuthenticationResult.VersionOutdated; return(null); } if (username.Length < Constants.MinStringLength || passphrase.Length < Constants.MinStringLength) { result = AuthenticationResult.StringLength; return(null); } var hash = new Hash(); var database = new AccountDB(); var dbError = database.Open(); if (dbError.Number != 0) { Global.WriteLog(LogType.System, $"Failed to authenticate user {username}", LogColor.Red); Global.WriteLog(LogType.System, $"Error Number: {dbError.Number}", LogColor.Red); Global.WriteLog(LogType.System, $"Error Message: {dbError.Message}", LogColor.Red); result = AuthenticationResult.Error; return(null); } var account = database.GetAccount(username); if (account.AccountId > 0) { account.Banned = database.IsBanned(account.AccountId); } if (account.AccountId == 0) { result = AuthenticationResult.WrongUserData; return(account); } if (account.Activated == 0) { result = AuthenticationResult.AccountIsNotActivated; return(account); } if (account.Passphrase.CompareTo(hash.Compute(passphrase)) != 0) { result = AuthenticationResult.WrongUserData; return(account); } if (account.Banned) { result = AuthenticationResult.AccountIsBanned; return(account); } database.UpdateLastLoginDate(account.AccountId); database.Close(); result = AuthenticationResult.Success; return(account); }