src/main/java/com/xcong/excoin/configurations/security/WebSecurityConfig.java
@@ -45,6 +45,7 @@ .antMatchers("/v2/**").permitAll() .antMatchers("/api/symbols/**").permitAll() .antMatchers("/common/**").permitAll() .antMatchers("/trc/**").permitAll() .antMatchers("/api/exchange/**").permitAll() .antMatchers("/api/member/getMemberAccountInfo").permitAll() .antMatchers("/api/member/memberForgetPwd").permitAll() src/main/java/com/xcong/excoin/modules/coin/controller/Trc20Controller.java
@@ -1,7 +1,88 @@ package com.xcong.excoin.modules.coin.controller;/** * * @author wzy * @date 2020-11-10 **/ package com.xcong.excoin.modules.coin.controller; import cn.hutool.crypto.SecureUtil; import com.xcong.excoin.common.enumerates.CoinTypeEnum; import com.xcong.excoin.common.response.Result; import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao; import com.xcong.excoin.modules.coin.dao.TrcAddressDao; import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange; import com.xcong.excoin.modules.coin.entity.TrcAddressEntity; import com.xcong.excoin.modules.coin.parameter.dto.TrcRechargeDto; import com.xcong.excoin.modules.member.dao.MemberCoinChargeDao; import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao; import com.xcong.excoin.modules.member.entity.MemberCoinChargeEntity; import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity; import com.xcong.excoin.utils.TRC20ApiUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; /** * @author wzy * @date 2020-11-10 **/ @Slf4j @RestController @RequestMapping(value = "/trc") public class Trc20Controller { @Resource private MemberWalletCoinDao memberWalletCoinDao; @Resource private MemberAccountMoneyChangeDao memberAccountMoneyChangeDao; @Resource private MemberCoinChargeDao memberCoinChargeDao; @Resource private TrcAddressDao trcAddressDao; @PostMapping(value = "/rechargeTrcAmount") @Transactional(rollbackFor = Exception.class) public Result rechargeTrcAmount(@RequestBody TrcRechargeDto trcRechargeDto) { log.info("传入参数 : {}", trcRechargeDto); String sign = SecureUtil.md5(trcRechargeDto.getNum() + trcRechargeDto.getNum().toPlainString() + CoinTypeEnum.USDT.name() + trcRechargeDto.getType() + TRC20ApiUtils.SIGN_STR); if (!sign.equals(trcRechargeDto.getKey())) { return Result.fail("参数错误"); } Long memberId = Long.parseLong(trcRechargeDto.getUid()); MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.USDT.name()); memberWalletCoinDao.updateWalletBalance(wallet.getId(), trcRechargeDto.getNum(), null, null); TrcAddressEntity trcAddress = trcAddressDao.selectSrcAddressByMemberId(memberId); MemberCoinChargeEntity charge = new MemberCoinChargeEntity(); charge.setAddress(trcAddress.getAddress()); charge.setAmount(trcRechargeDto.getNum()); charge.setMemberId(memberId); charge.setSymbol(CoinTypeEnum.USDT.name()); charge.setStatus(1); charge.setTag("TRC20"); charge.setLastAmount(trcRechargeDto.getNum()); String orderNo = generateNo(); charge.setOrderCode(orderNo); memberCoinChargeDao.insert(charge); MemberAccountMoneyChange change = new MemberAccountMoneyChange(); change.setAmount(trcRechargeDto.getNum()); change.setContent("转入"); change.setSymbol(CoinTypeEnum.USDT.name()); change.setStatus(1); change.setType(1); change.setMemberId(memberId); memberAccountMoneyChangeDao.insert(change); return Result.ok("充值成功"); } private String generateNo() { // 生成订单号 Long timestamp = System.currentTimeMillis(); // 随机数 int random = (int) (Math.random() * 10); return String.valueOf(timestamp).substring(2) + random; } } src/main/java/com/xcong/excoin/modules/coin/parameter/dto/TrcRechargeDto.java
@@ -1,7 +1,27 @@ package com.xcong.excoin.modules.coin.parameter.dto;/** * * @author wzy * @date 2020-11-10 **/ package com.xcong.excoin.modules.coin.parameter.dto; import lombok.Data; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.math.BigDecimal; /** * @author wzy * @date 2020-11-10 **/ @Data public class TrcRechargeDto { @NotBlank(message = "uid不能为空") private String uid; @NotNull(message = "充币数量不能为空") private BigDecimal num; @NotNull(message = "类型不能为空") private Integer type; @NotBlank(message = "参数错误") private String key; } src/main/java/com/xcong/excoin/modules/member/entity/MemberCoinWithdrawEntity.java
@@ -42,6 +42,10 @@ */ private int status; public static final int STATUS_DOING = 1; //同意 public static final int IS_STATUS_Y = 2; //拒绝 public static final int IS_STATUS_N = 3; /** * 是否内部转账 Y-是N-不是 */ src/main/java/com/xcong/excoin/quartz/job/TRC20OrderJob.java
@@ -1,11 +1,18 @@ package com.xcong.excoin.quartz.job; import cn.hutool.core.collection.CollUtil; import com.alibaba.fastjson.JSONObject; import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao; import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange; import com.xcong.excoin.modules.member.dao.MemberCoinWithdrawDao; import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao; import com.xcong.excoin.modules.member.entity.MemberCoinWithdrawEntity; import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity; import com.xcong.excoin.utils.TRC20ApiUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.HashMap; @@ -18,19 +25,53 @@ **/ @Slf4j @Component @ConditionalOnProperty(prefix = "app", name = "block-job", havingValue = "true") public class TRC20OrderJob { @Resource private MemberCoinWithdrawDao memberCoinWithdrawDao; @Resource private MemberWalletCoinDao memberWalletCoinDao; @Resource private MemberAccountMoneyChangeDao memberAccountMoneyChangeDao; @Transactional(rollbackFor = Exception.class) public void trc20WithdrawOrder() { log.info("trc20订单查询"); Map<String, Object> param = new HashMap<>(); param.put("label", "TRC20"); param.put("status", 1); List<MemberCoinWithdrawEntity> withdrawEntities = memberCoinWithdrawDao.selectByMap(param); if (CollUtil.isNotEmpty(withdrawEntities)) { for (MemberCoinWithdrawEntity withdrawEntity : withdrawEntities) { MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(withdrawEntity.getMemberId(), withdrawEntity.getSymbol()); String applyOrderInfo = TRC20ApiUtils.getApplyOrderInfo(withdrawEntity.getTag()); Integer transStatus = JSONObject.parseObject(applyOrderInfo).getInteger("transStatus"); Map<String, Object> columnMaps = new HashMap<>(); columnMaps.put("withdraw_id", withdrawEntity.getId()); MemberAccountMoneyChange accountMoneyChanges = memberAccountMoneyChangeDao.selectByMap(columnMaps).get(0); // 状态:2待审核3提币中(审核成功)4提币成功5审核失败 if (transStatus == 4) { memberWalletCoinDao.updateWalletBalance(wallet.getId(), null, null, withdrawEntity.getAmount().negate()); accountMoneyChanges.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER); accountMoneyChanges.setAmount(withdrawEntity.getAmount().negate()); memberAccountMoneyChangeDao.updateById(accountMoneyChanges); withdrawEntity.setStatus(MemberCoinWithdrawEntity.IS_STATUS_Y); memberCoinWithdrawDao.updateById(withdrawEntity); } else if (transStatus == 5) { memberWalletCoinDao.updateWalletBalance(wallet.getId(), withdrawEntity.getAmount(), null, withdrawEntity.getAmount().negate()); accountMoneyChanges.setStatus(MemberAccountMoneyChange.STATUS_FAIL_INTEGER); accountMoneyChanges.setAmount(withdrawEntity.getAmount()); memberAccountMoneyChangeDao.updateById(accountMoneyChanges); withdrawEntity.setStatus(MemberCoinWithdrawEntity.IS_STATUS_N); memberCoinWithdrawDao.updateById(withdrawEntity); } } } } src/main/java/com/xcong/excoin/utils/TRC20ApiUtils.java
@@ -17,7 +17,7 @@ @Slf4j public class TRC20ApiUtils { private static final String TRC20_API = "http://27.50.59.35:5002/"; private static final String SIGN_STR = "w@a!llokmet"; public static final String SIGN_STR = "w@a!llokmet"; /** * 提币申请