public string TransferInto(Guid openId, string pin, string coinCode, decimal amount) { var coin = new CryptocurrencyDAC().GetByCode(coinCode); if (coin == null) { throw new CommonException(ReasonCode.CRYPTO_NOT_EXISTS, R.ErrorCryptoCode); } var openAccountDac = new OpenAccountDAC(); var openAccount = openAccountDac.GetOpenAccount(openId); if (openAccount == null) { throw new CommonException(ReasonCode.ACCOUNT_NOT_EXISTS, R.AccountNotExist); } switch (openAccount.FiiiType) { case FiiiType.FiiiPay: var accountDac = new UserAccountDAC(); var userAccount = accountDac.GetById(openAccount.AccountId); new SecurityComponent().VerifyPin(userAccount, pin); return(this.FiiiPayTransferInto(userAccount, coin, amount)); case FiiiType.FiiiPOS: MerchantAccount merchantAccount = new MerchantAccountDAC().GetById(openAccount.AccountId); new SecurityComponent().FiiiPOSVerifyPin(merchantAccount, pin); return(this.FiiiPOSTransferInto(merchantAccount, coin, amount)); default: throw new CommonException(ReasonCode.ACCOUNT_NOT_EXISTS, R.AccountNotExist); } }
public bool FiiiPayLogin(string QRCode, UserAccount account) { if (!RedisHelper.KeyExists(0, QRCode)) { throw new CommonException(ReasonCode.INVALID_QRCODE, R.无效二维码); } var profile = new UserProfileAgent().GetUserProfile(account.Id); var country = new CountryDAC().GetById(account.CountryId); var openAccount = new OpenAccountDAC().GetOpenAccount(FiiiType.FiiiPay, account.Id); if (openAccount == null) { openAccount = new OpenAccountComponent().Create((int)SystemPlatform.FiiiEX, FiiiType.FiiiPay, account.Id); } var om = new { OpenId = openAccount.OpenId, AccountName = country.PhoneCode + " " + account.Cellphone, UserType = 0,//0FiiiPay 1FiiiPos CountryId = country.Id, PosCode = "", CountryName = country.Name, CountryName_CN = country.Name_CN, FullName = profile == null ? "" : (profile.FirstName + " " + profile.LastName), Cellphone = GetMaskedCellphone(country.PhoneCode, account.Cellphone) }; RedisHelper.StringSet(0, QRCode, JsonConvert.SerializeObject(om), TimeSpan.FromMinutes(5)); return(true); }
private decimal FiiiExBalance(FiiiType fiiiType, Guid accountId, Cryptocurrency crypto) { var openAccountDac = new OpenAccountDAC(); var data = openAccountDac.GetOpenAccount(fiiiType, accountId); if (data == null) { return(0M); } LogHelper.Info($"GetFiiiExUserCoin: openId={data.OpenId}, coinCode={crypto.Code}"); int result = new TransferCoinSoapClient().GetUserCoin(data.OpenId.ToString(), crypto.Code, out decimal amount); LogHelper.Info($"GetFiiiExUserCoin: result={result}, amount={amount}"); return(amount); }
public OpenAccount Create(int platform, FiiiType fiiiType, Guid accountId) { OpenAccount account = new OpenAccount { CreateTime = DateTime.UtcNow, PlatformId = platform, FiiiType = fiiiType, OpenId = Guid.NewGuid(), SecretKey = RandomAlphaNumericGenerator.Generate(32), AccountId = accountId }; long id = new OpenAccountDAC().Create(account); account.Id = id; return(account); }
public bool FiiiPosLogin(string QRCode, Guid accountId) { if (!RedisHelper.KeyExists(0, QRCode)) { throw new CommonException(ReasonCode.INVALID_QRCODE, R.无效二维码); } MerchantAccount account = new MerchantAccountDAC().GetById(accountId); if (account == null) { throw new CommonException(ReasonCode.ACCOUNT_NOT_EXISTS, R.用户不存在); } var country = new CountryDAC().GetById(account.CountryId); var pos = new POSDAC().GetById(account.POSId.Value); var openAccount = new OpenAccountDAC().GetOpenAccount(FiiiType.FiiiPOS, account.Id); if (openAccount == null) { openAccount = new OpenAccountComponent().Create((int)SystemPlatform.FiiiEX, FiiiType.FiiiPOS, account.Id); } var om = new { OpenId = openAccount.OpenId, AccountName = account.Username, UserType = 1,//0FiiiPay 1FiiiPos CountryId = country.Id, PosCode = pos.Sn, CountryName = country.Name, CountryName_CN = country.Name_CN, FullName = account.MerchantName, Cellphone = GetMaskedCellphone(account.PhoneCode, account.Cellphone) }; RedisHelper.StringSet(0, QRCode, JsonConvert.SerializeObject(om), TimeSpan.FromMinutes(5)); return(true); }
public TransferResult FiiiPOSTransferToEx(Guid accountId, int cryptoId, decimal amount, string pinToken) { var securityVerify = new SecurityVerification(SystemPlatform.FiiiPOS); securityVerify.VerifyToken(accountId, pinToken, SecurityMethod.Pin); var openAccountDac = new OpenAccountDAC(); var openAccount = openAccountDac.GetOpenAccount(FiiiType.FiiiPOS, accountId); if (openAccount == null) { throw new CommonException(ReasonCode.GENERAL_ERROR, R.FiiiExAccountNotExist); } var crypto = new CryptocurrencyDAC().GetById(cryptoId); if (crypto == null) { throw new CommonException(ReasonCode.GENERAL_ERROR, R.CurrencyForbidden); } var walletDac = new MerchantWalletDAC(); var wallet = walletDac.GetByAccountId(accountId, crypto.Id); if (wallet.Balance < amount) { throw new CommonException(ReasonCode.GENERAL_ERROR, Resources.余额不足); } //10091=参数不符合要求 10013=用户信息不存在 10020=币不存在 0=成功 int result = FiiiExCoinIn(openAccount.OpenId, crypto.Code, amount, out string recordId); if (result != 0) { throw new CommonException(ReasonCode.GENERAL_ERROR, Resources.从FiiiEx划转失败); } MerchantExTransferOrder order; using (var scope = new TransactionScope()) { walletDac.Decrease(wallet.Id, amount); order = new MerchantExTransferOrder { Timestamp = DateTime.UtcNow, OrderNo = CreateOrderNo(), OrderType = ExTransferType.ToEx, AccountId = accountId, WalletId = wallet.Id, CryptoId = crypto.Id, CryptoCode = crypto.Code, Amount = amount, Status = 1, Remark = null, ExId = recordId }; order = new MerchantExTransferOrderDAC().Create(order); scope.Complete(); } try { FiiiEXTransferMSMQ.PubMerchantTransferToEx(order.Id, 0); } catch (Exception ex) { LogHelper.Info("FiiiPOSTransferToEx - error", ex); } return(new TransferResult { Id = order.Id, Amount = order.Amount.ToString(crypto.DecimalPlace), OrderNo = order.OrderNo, Timestamp = order.Timestamp.ToUnixTime(), CryptoCode = crypto.Code }); }
public TransferResult FiiiPayTransferFromEx(UserAccount account, int cryptoId, decimal amount, string pin) { new SecurityComponent().VerifyPin(account, pin); var openAccountDac = new OpenAccountDAC(); var openAccount = openAccountDac.GetOpenAccount(FiiiType.FiiiPay, account.Id); if (openAccount == null) { throw new CommonException(ReasonCode.GENERAL_ERROR, R.FiiiExAccountNotExist); } var crypto = new CryptocurrencyDAC().GetById(cryptoId); if (crypto == null) { throw new CommonException(ReasonCode.GENERAL_ERROR, R.CurrencyForbidden); } var balance = this.FiiiExBalance(FiiiType.FiiiPay, account.Id, crypto); if (balance < amount) { throw new CommonException(ReasonCode.GENERAL_ERROR, Resources.余额不足); } //10091=参数不符合要求 10013=用户信息不存在 10024=用户币不存在 10025=用户币种余额不足 0=成功 int result = FiiiExCoinOut(openAccount.OpenId, crypto.Code, amount, out string recordId); if (result == 10025) { throw new CommonException(ReasonCode.GENERAL_ERROR, Resources.余额不足); } if (result != 0) { throw new CommonException(ReasonCode.GENERAL_ERROR, Resources.从FiiiEx划转失败); } var walletDac = new UserWalletDAC(); var wallet = walletDac.GetByAccountId(account.Id, crypto.Id); UserExTransferOrder order; using (var scope = new TransactionScope()) { if (wallet == null) { wallet = new UserWalletComponent().GenerateWallet(account.Id, crypto.Id); } walletDac.Increase(wallet.Id, amount); order = new UserExTransferOrder { Timestamp = DateTime.UtcNow, OrderNo = CreateOrderNo(), OrderType = ExTransferType.FromEx, AccountId = account.Id, WalletId = wallet.Id, CryptoId = crypto.Id, CryptoCode = crypto.Code, Amount = amount, Status = 1, Remark = null, ExId = recordId }; order = new UserExTransferOrderDAC().Create(order); scope.Complete(); } try { FiiiEXTransferMSMQ.PubUserTransferFromEx(order.Id, 0); } catch (Exception ex) { LogHelper.Info("PubUserTransferFromEx - error", ex); } return(new TransferResult { Id = order.Id, Amount = order.Amount.ToString(crypto.DecimalPlace), OrderNo = order.OrderNo, Timestamp = order.Timestamp.ToUnixTime(), CryptoCode = crypto.Code }); }
public bool HasExAccount(FiiiType fiiiType, Guid accountId) { var openAccount = new OpenAccountDAC().GetOpenAccount(fiiiType, accountId); return(openAccount != null); }