add coin recharge sms notice
| | |
| | | package com.xcong.excoin.modules.coin.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DatePattern; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.xcong.excoin.common.enumerates.CoinTypeEnum; |
| | | import com.xcong.excoin.modules.blackchain.service.BtcService; |
| | |
| | | import com.xcong.excoin.modules.member.entity.MemberEntity; |
| | | import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity; |
| | | import com.xcong.excoin.utils.LogRecordUtils; |
| | | import com.xcong.excoin.utils.mail.SmsSend; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | BigDecimal newBalance = balance.subtract(early); |
| | | memberWalletCoinDao.updateBlockBalance(walletCoinEntity.getId(), newBalance, balance, 0); |
| | | |
| | | insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "ERC20", balance); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "ERC20", balance); |
| | | // 插入财务记录 |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", newBalance, CoinTypeEnum.USDT.name(), 1, 1); |
| | | // TODO 钉钉发送, 短信提醒 |
| | | |
| | | MemberEntity member = memberDao.selectById(memberId); |
| | | if (StrUtil.isNotBlank(member.getPhone())) { |
| | | String amount = newBalance.toPlainString() + "USDT-ERC20"; |
| | | SmsSend.sendRechargeMsg(member.getPhone(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), amount, orderNo); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | BigDecimal newBalance = balance.subtract(early); |
| | | memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), newBalance, balance, 0); |
| | | insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.ETH.name(), null, balance); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.ETH.name(), null, balance); |
| | | |
| | | // 插入财务记录 |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", newBalance, CoinTypeEnum.ETH.name(), 1, 1); |
| | | // TODO 钉钉消息, 短信提醒 |
| | | |
| | | MemberEntity member = memberDao.selectById(memberId); |
| | | if (StrUtil.isNotBlank(member.getPhone())) { |
| | | String amount = newBalance.toPlainString() + "ETH"; |
| | | SmsSend.sendRechargeMsg(member.getPhone(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), amount, orderNo); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | BigDecimal newBalance = balance.subtract(early); |
| | | |
| | | memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), newBalance, balance, 0); |
| | | insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "OMNI", balance); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "OMNI", balance); |
| | | |
| | | // TODO 钉钉消息, 短信提醒 |
| | | MemberEntity member = memberDao.selectById(memberId); |
| | | if (StrUtil.isNotBlank(member.getPhone())) { |
| | | String amount = newBalance.toPlainString() + "USDT-OMNI"; |
| | | SmsSend.sendRechargeMsg(member.getPhone(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), amount, orderNo); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | BigDecimal newBalance = balance.subtract(early); |
| | | memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), newBalance, balance, 0); |
| | | |
| | | insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.BTC.name(), null, balance); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.BTC.name(), null, balance); |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", newBalance, CoinTypeEnum.BTC.name(), 1, 1); |
| | | |
| | | // TODO 钉钉提醒, 短信提醒 |
| | | |
| | | MemberEntity member = memberDao.selectById(memberId); |
| | | if (StrUtil.isNotBlank(member.getPhone())) { |
| | | String amount = newBalance.toPlainString() + "BTC"; |
| | | SmsSend.sendRechargeMsg(member.getPhone(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), amount, orderNo); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | return String.valueOf(timestamp).substring(2) + random; |
| | | } |
| | | |
| | | public void insertCoinCharge(String address, Long memberId, BigDecimal newBalance, String symbol, String tag, BigDecimal lastAmount) { |
| | | public String insertCoinCharge(String address, Long memberId, BigDecimal newBalance, String symbol, String tag, BigDecimal lastAmount) { |
| | | MemberCoinChargeEntity memberCoinChargeEntity = new MemberCoinChargeEntity(); |
| | | memberCoinChargeEntity.setAddress(address); |
| | | memberCoinChargeEntity.setMemberId(memberId); |
| | |
| | | memberCoinChargeEntity.setTag(tag); |
| | | memberCoinChargeEntity.setStatus(1); |
| | | memberCoinChargeEntity.setLastAmount(lastAmount); |
| | | memberCoinChargeEntity.setOrderCode(generateNo()); |
| | | String orderNo = generateNo(); |
| | | memberCoinChargeEntity.setOrderCode(orderNo); |
| | | memberCoinChargeDao.insert(memberCoinChargeEntity); |
| | | return orderNo; |
| | | } |
| | | } |
| | |
| | | package com.xcong.excoin.utils.mail; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import net.sf.json.JSONObject; |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.HttpResponse; |
| | |
| | | import org.apache.http.util.EntityUtils; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | import java.util.TreeMap; |
| | | |
| | |
| | | |
| | | public static final String TYPE_MD5 = "md5"; |
| | | public static final String TYPE_SHA1 = "sha1"; |
| | | |
| | | private static final String APP_ID = "51258"; |
| | | private static final String APP_KEY = "a9b6e0758dc40d3c346887fc0e154642"; |
| | | private static final String SIGN_TYPE = ""; |
| | | /** |
| | | * API 请求接口配置 |
| | | */ |
| | | private static final String URL = "https://api.mysubmail.com/message/xsend"; |
| | | |
| | | |
| | | /** |
| | | * 发送验证码 |
| | | * |
| | | * @param telphone 手机号 |
| | | * @param code 验证码 |
| | | * @param time 超时时间 |
| | | * @return |
| | | */ |
| | | public static boolean sendVerifyCode(String telphone, String code, int time) { |
| | | TreeMap<String, Object> requestData = new TreeMap<String, Object>(); |
| | | JSONObject vars = new JSONObject(); |
| | | |
| | | String appid = "51258"; |
| | | String appkey = "a9b6e0758dc40d3c346887fc0e154642"; |
| | | String project = "2CHnV3"; |
| | | String signtype = ""; |
| | | vars.put("code", code); |
| | | vars.put("time", time); |
| | | |
| | | requestData.put("appid", appid); |
| | | requestData.put("appid", APP_ID); |
| | | requestData.put("project", project); |
| | | requestData.put("to", telphone); |
| | | if (!vars.isEmpty()) { |
| | | requestData.put("vars", vars.toString()); |
| | | } |
| | | return requestSend(requestData); |
| | | } |
| | | |
| | | /** |
| | | * 发送充值成功消息 |
| | | * |
| | | * @param phone 手机号 |
| | | * @param time 充值时间 |
| | | * @param amount 金额 |
| | | * @param orderNo 订单号 |
| | | */ |
| | | public static void sendRechargeMsg(String phone, String time, String amount, String orderNo) { |
| | | TreeMap<String, Object> requestData = new TreeMap<String, Object>(); |
| | | JSONObject vars = new JSONObject(); |
| | | vars.put("time", time); |
| | | vars.put("price", amount); |
| | | vars.put("orderNo", orderNo); |
| | | String project = "Cqky91"; |
| | | requestData.put("appid", APP_ID); |
| | | requestData.put("project", project); |
| | | requestData.put("to", phone); |
| | | if (!vars.isEmpty()) { |
| | | requestData.put("vars", vars.toString()); |
| | | } |
| | | |
| | | requestSend(requestData); |
| | | } |
| | | |
| | | |
| | | private static boolean requestSend(TreeMap<String, Object> requestData) { |
| | | MultipartEntityBuilder builder = MultipartEntityBuilder.create(); |
| | | @SuppressWarnings("deprecation") |
| | | ContentType contentType = ContentType.create(HTTP.PLAIN_TEXT_TYPE, HTTP.UTF_8); |
| | |
| | | builder.addTextBody(key, String.valueOf(value), contentType); |
| | | } |
| | | } |
| | | if (signtype.equals(TYPE_MD5) || signtype.equals(TYPE_SHA1)) { |
| | | if (SIGN_TYPE.equals(TYPE_MD5) || SIGN_TYPE.equals(TYPE_SHA1)) { |
| | | String timestamp = getTimestamp(); |
| | | requestData.put("timestamp", timestamp); |
| | | requestData.put("sign_type", signtype); |
| | | String signStr = appid + appkey + RequestEncoder.formatRequest(requestData) + appid + appkey; |
| | | requestData.put("sign_type", SIGN_TYPE); |
| | | String signStr = APP_ID + APP_KEY + RequestEncoder.formatRequest(requestData) + APP_ID + APP_KEY; |
| | | |
| | | builder.addTextBody("timestamp", timestamp); |
| | | builder.addTextBody("sign_type", signtype); |
| | | builder.addTextBody("signature", RequestEncoder.encode(signtype, signStr), contentType); |
| | | builder.addTextBody("sign_type", SIGN_TYPE); |
| | | builder.addTextBody("signature", RequestEncoder.encode(SIGN_TYPE, signStr), contentType); |
| | | } else { |
| | | builder.addTextBody("signature", appkey, contentType); |
| | | builder.addTextBody("signature", APP_KEY, contentType); |
| | | } |
| | | |
| | | HttpPost httpPost = new HttpPost(URL); |
| | |
| | | |
| | | /** |
| | | * 获取时间戳 |
| | | * |
| | | */ |
| | | private static String getTimestamp() { |
| | | CloseableHttpClient closeableHttpClient = HttpClientBuilder.create().build(); |
| | |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | sendVerifyCode("15773002834", "123456", 2); |
| | | // sendVerifyCode("15773002834", "123456", 2); |
| | | } |
| | | } |
| | |
| | | package com.xcong.excoin; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.xcong.excoin.common.LoginUserUtils; |
| | | import com.xcong.excoin.common.enumerates.CoinTypeEnum; |
| | | import com.xcong.excoin.common.system.service.CommonService; |
| | | import com.xcong.excoin.modules.contract.dao.ContractEntrustOrderDao; |
| | | import com.xcong.excoin.modules.contract.dao.ContractHoldOrderDao; |
| | | import com.xcong.excoin.modules.contract.dao.ContractOrderDao; |
| | | import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity; |
| | | import com.xcong.excoin.modules.member.dao.MemberDao; |
| | | import com.xcong.excoin.modules.member.dao.MemberLevelRateDao; |
| | | import com.xcong.excoin.modules.member.dao.MemberWalletContractDao; |
| | | import com.xcong.excoin.modules.member.entity.MemberEntity; |
| | | import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity; |
| | | import com.xcong.excoin.modules.platform.entity.PlatformTradeSettingEntity; |
| | | import com.xcong.excoin.modules.symbols.service.SymbolsService; |
| | | import com.xcong.excoin.rabbit.producer.OrderProducer; |
| | | import com.xcong.excoin.utils.CacheSettingUtils; |
| | | import com.xcong.excoin.utils.CoinTypeConvert; |
| | | import com.xcong.excoin.utils.RedisUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2020-05-26 |
| | | **/ |
| | | @Slf4j |
| | | @SpringBootTest |
| | | public class SymbolsTest { |
| | | |
| | | @Resource |
| | | private ContractHoldOrderDao contractHoldOrderDao; |
| | | |
| | | @Resource |
| | | private ContractOrderDao contractOrderDao; |
| | | |
| | | @Resource |
| | | private ContractEntrustOrderDao contractEntrustOrderDao; |
| | | |
| | | @Resource |
| | | private CommonService commonService; |
| | | |
| | | @Resource |
| | | private MemberWalletContractDao memberWalletContractDao; |
| | | |
| | | @Resource |
| | | private MemberLevelRateDao memberLevelRateDao; |
| | | |
| | | @Resource |
| | | private CacheSettingUtils cacheSettingUtils; |
| | | |
| | | @Resource |
| | | private RedisUtils redisUtils; |
| | | |
| | | @Resource |
| | | private OrderProducer producer; |
| | | |
| | | @Resource |
| | | private MemberDao memberDao; |
| | | |
| | | @Resource |
| | | private SymbolsService symbolsService; |
| | |
| | | public void symbolsTest() { |
| | | symbolsService.updateSymbolsKine("1min"); |
| | | } |
| | | |
| | | @Test |
| | | public void moneyTest() { |
| | | MemberEntity memberEntity = memberDao.selectById(11L); |
| | | PlatformTradeSettingEntity tradeSetting = cacheSettingUtils.getTradeSetting(); |
| | | |
| | | List<ContractHoldOrderEntity> holdOrderEntities = contractHoldOrderDao.selectHoldOrderListByMemberId(memberEntity.getId()); |
| | | |
| | | BigDecimal beUsedBondAmount = BigDecimal.ZERO; |
| | | // 总盈利 |
| | | BigDecimal totalProfitOrLess = BigDecimal.ZERO; |
| | | if (CollUtil.isNotEmpty(holdOrderEntities)) { |
| | | for (ContractHoldOrderEntity holdOrderEntity : holdOrderEntities) { |
| | | // 获取最新价 |
| | | BigDecimal newPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(holdOrderEntity.getSymbol()))); |
| | | BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(holdOrderEntity.getSymbol()); |
| | | beUsedBondAmount = beUsedBondAmount.add(holdOrderEntity.getBondAmount()); |
| | | |
| | | // 单个订单盈利 |
| | | BigDecimal profitOrLess = BigDecimal.ZERO; |
| | | // 开多 |
| | | if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { |
| | | profitOrLess = newPrice.subtract(holdOrderEntity.getOpeningPrice()).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt())).multiply(lotNumber); |
| | | // 开空 |
| | | } else { |
| | | profitOrLess = holdOrderEntity.getOpeningPrice().subtract(newPrice).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt())).multiply(lotNumber); |
| | | } |
| | | |
| | | if (MemberEntity.IS_PROFIT_Y == memberEntity.getIsProfit()) { |
| | | if (profitOrLess.compareTo(BigDecimal.ZERO) > 0) { |
| | | profitOrLess = profitOrLess.multiply(BigDecimal.ONE.subtract(tradeSetting.getForceParam())); |
| | | } else { |
| | | profitOrLess = profitOrLess.multiply(BigDecimal.ONE.add(tradeSetting.getForceParam())); |
| | | } |
| | | } |
| | | |
| | | totalProfitOrLess = totalProfitOrLess.add(profitOrLess); |
| | | } |
| | | } |
| | | MemberWalletContractEntity walletContractEntity = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberEntity.getId(), CoinTypeEnum.USDT.name()); |
| | | |
| | | log.info("--->{}", walletContractEntity.getTotalBalance()); |
| | | log.info("----->{}", totalProfitOrLess); |
| | | |
| | | } |
| | | } |