| | |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | import cn.hutool.core.lang.Console; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpStatus; |
| | | import cn.hutool.json.JSONUtil; |
| | | import kernel.cache.RedisLocalCache; |
| | | import kernel.exception.BusinessException; |
| | | import kernel.util.StringUtils; |
| | | import kernel.web.BaseAction; |
| | | import kernel.web.Page; |
| | | import org.jetbrains.annotations.NotNull; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.CrossOrigin; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | |
| | | import io.netty.util.internal.StringUtil; |
| | | import kernel.web.ResultObject; |
| | | import project.blockchain.AdminChannelBlockchainService; |
| | | import project.blockchain.RechargeBlockchainService; |
| | | import project.party.PartyRedisKeys; |
| | | import project.user.UserWalletAddress; |
| | | import project.user.UserWalletAddressService; |
| | | import project.web.admin.AdminChannelBlockchainController; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | |
| | | @RestController |
| | | @CrossOrigin |
| | | |
| | | public class UserWalletAddressController { |
| | | public class UserWalletAddressController extends BaseAction { |
| | | |
| | | @Autowired |
| | | UserWalletAddressService userWalletAddressService; |
| | |
| | | |
| | | @Autowired |
| | | private AdminChannelBlockchainService adminChannelBlockchainService; |
| | | |
| | | @Autowired |
| | | private RechargeBlockchainService rechargeBlockchainService; |
| | | |
| | | /** |
| | | * 本地Redis工具(先取本地缓存再取Redis缓存) |
| | | */ |
| | | @Autowired |
| | | private RedisLocalCache redisLocalCache; |
| | | |
| | | private final String gateway = "https://sig11.udun.io"; |
| | | private final String merchantKey = "7fd79e4ed59e7c31e1fa2e13d64f7e6c"; |
| | | private final String merchantId = "319563"; |
| | | private final String defaultCallBackUrl = "https://coin.usadeepcoin.com/wap/api/user!rechargeCallback.action"; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 未生成钱包地址的用户 |
| | |
| | | int pageSize=300; |
| | | try { |
| | | pageNo=checkAndSetPageNo(pageNoStr); |
| | | String partyId = this.getLoginPartyId(); |
| | | page = this.adminChannelBlockchainService.pagedQuery(pageNo, pageSize, name_para, coin_para); |
| | | Map<String, List<Map<String, Object>>> coinMap = getStringListMap(); |
| | | Map<String, List<Map<String, Object>>> coinMap = getStringListMap(partyId); |
| | | List<Map<String, Object>> result = getCoinData(coinMap, coin_para); |
| | | logger.info("--------------result---------------"+result.toString()); |
| | | page.setElements(result); |
| | | } catch (BusinessException e) { |
| | | logger.error(" error ", e); |
| | | logger.error(" 获取充值地址报错【BusinessException】:", e); |
| | | resultObject.setCode("1"); |
| | | resultObject.setMsg(e.getMessage()); |
| | | return resultObject; |
| | | } catch (Throwable t) { |
| | | logger.error(" error ", t); |
| | | logger.error(" 获取充值地址报错【Throwable】: ", t); |
| | | resultObject.setCode("1"); |
| | | resultObject.setMsg( t.getMessage()); |
| | | return resultObject; |
| | | } |
| | | logger.info("--------------address3---------------"+page.getElements()); |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("pageNo", pageNo); |
| | | map.put("pageSize", pageSize); |
| | |
| | | } |
| | | |
| | | @NotNull |
| | | private static Map<String, List<Map<String, Object>>> getStringListMap() { |
| | | List<Map<String, Object>> ethData = new ArrayList<>(); |
| | | ethData.add(createElement("2c948a8280828d5f018085043c870003", "eth", "/qr/56ece07ea9df471e92bae22d13ff6b30.png", "0xdbE11ac592416EEEa120Bf9526b16a2F6dBCE0A6","ETH")); |
| | | |
| | | List<Map<String, Object>> btcData = new ArrayList<>(); |
| | | btcData.add(createElement("2c948a8280828d5f018084ff569b0002", "btc", "/qr/1be19b34fbb9406c8044c1a9b08a87ca.png", "im14x5MUw9PycfD1io7AKBjvTSxfBRUpmPc3zSP","BTC")); |
| | | |
| | | List<Map<String, Object>> usdtData = new ArrayList<>(); |
| | | usdtData.add(createElement("2c948a8280828d5f01808203eacd0004", "usdt", "/qr/c2b42ee106cf408baf7b1ecc877f2dd4.png", "0xdbE11ac592416EEEa120Bf9526b16a2F6dBCE0A6","ERC20")); |
| | | usdtData.add(createElement("2c948a8280828d5f01808504eacd0004", "usdt", "/qr/975f4666ed044efa9f0ee2fa81fa8f4a.png", "TFUtRvjVpRZArFhXGd5n5ZDEX3PrmudQgb","TRC20")); |
| | | |
| | | List<Map<String, Object>> usdcData = new ArrayList<>(); |
| | | usdcData.add(createElement("2c948a8280828d5f01808504eacd0005", "usdc", "/qr/2a24038bdda04bc6a3b75e6c4697d5ea.png", "TFUtRvjVpRZArFhXGd5n5ZDEX3PrmudQgb","TRC20")); |
| | | usdcData.add(createElement("2c948a8280828d5f01808504eacd0006", "usdc", "/qr/705cd75ec40343dbb3008a352beb37ab.png", "0xdbE11ac592416EEEa120Bf9526b16a2F6dBCE0A6","ERC20")); |
| | | |
| | | private Map<String, List<Map<String, Object>>> getStringListMap(String partyId ) { |
| | | Map<String, List<Map<String, Object>>> coinMap = new HashMap<>(); |
| | | coinMap.put("eth", ethData); |
| | | coinMap.put("btc", btcData); |
| | | coinMap.put("usdt", usdtData); |
| | | coinMap.put("usdc", usdcData); |
| | | |
| | | //获取商户支持币种 |
| | | List<Coin> coinList = listSupportCoin("319563",false); |
| | | //创建地址 |
| | | coinList.forEach(f->{ |
| | | if(f.getName().equals("BTC")){ |
| | | String partyBTC = (String)redisLocalCache.get(partyId + "_BTC"); |
| | | Address address3 = new Address(); |
| | | List<Map<String, Object>> btcData = new ArrayList<>(); |
| | | if(!StringUtils.isNotEmpty(partyBTC)){ |
| | | address3 = createAddress(f.getMainCoinType(),null,null,null); |
| | | btcData.add(createElement("2c948a8280828d5f018084ff569b0002", "btc", "/qr/1be19b34fbb9406c8044c1a9b08a87ca.png", address3.getAddress(),"BTC")); |
| | | redisLocalCache.put(partyId+ "_BTC",address3.getAddress()); |
| | | }else{ |
| | | btcData.add(createElement("2c948a8280828d5f018084ff569b0002", "btc", "/qr/1be19b34fbb9406c8044c1a9b08a87ca.png", partyBTC,"BTC")); |
| | | } |
| | | logger.info("--------------address3---------------"+address3.getAddress()); |
| | | coinMap.put("btc", btcData); |
| | | logger.info("--------------BTC---------------"+coinMap.toString()); |
| | | }else if(f.getName().equals("ETH")){ |
| | | String partyETH = (String)redisLocalCache.get(partyId + "_ETH"); |
| | | List<Map<String, Object>> ethData = new ArrayList<>(); |
| | | if(!StringUtils.isNotEmpty(partyETH)){ |
| | | Address address3 = createAddress(f.getMainCoinType(),null,null,null); |
| | | logger.info("--------------address3---------------"+address3.getAddress()); |
| | | ethData.add(createElement("2c948a8280828d5f018084ff569b0002", "eth", "/qr/1be19b34fbb9406c8044c1a9b08a87ca.png", address3.getAddress(),"ETH")); |
| | | redisLocalCache.put(partyId + "_ETH",address3.getAddress()); |
| | | }else{ |
| | | ethData.add(createElement("2c948a8280828d5f018084ff569b0002", "eth", "/qr/1be19b34fbb9406c8044c1a9b08a87ca.png", partyETH,"ETH")); |
| | | } |
| | | coinMap.put("eth", ethData); |
| | | logger.info("--------------ETH---------------"+coinMap.toString()); |
| | | }else if(f.getName().equals("USDC")){ |
| | | String partyUSDC = (String)redisLocalCache.get(partyId + "_USDC"); |
| | | List<Map<String, Object>> usdcData = new ArrayList<>(); |
| | | if(!StringUtils.isNotEmpty(partyUSDC)){ |
| | | Address address3 = createAddress(f.getMainCoinType(),null,null,null); |
| | | logger.info("--------------address3---------------"+address3.getAddress()); |
| | | usdcData.add(createElement("2c948a8280828d5f01808504eacd0004", "usdc", "/qr/975f4666ed044efa9f0ee2fa81fa8f4a.png", address3.getAddress(),"ERC20")); |
| | | redisLocalCache.put(partyId + "_ETH",address3.getAddress()); |
| | | }else{ |
| | | usdcData.add(createElement("2c948a8280828d5f01808504eacd0004", "usdc", "/qr/975f4666ed044efa9f0ee2fa81fa8f4a.png", partyUSDC,"ERC20")); |
| | | } |
| | | coinMap.put("usdc", usdcData); |
| | | logger.info("--------------USDC---------------"+coinMap.toString()); |
| | | }else if(f.getName().equals("USDT-ERC20")){ |
| | | String partyUSDT = (String)redisLocalCache.get(partyId + "_USDT-ERC20"); |
| | | List<Map<String, Object>> usdtData = new ArrayList<>(); |
| | | if(!StringUtils.isNotEmpty(partyUSDT)){ |
| | | Address address3 = createAddress(f.getMainCoinType(),null,null,null); |
| | | logger.info("--------------address3---------------"+address3.getAddress()); |
| | | usdtData.add(createElement("2c948a8280828d5f01808504eacd0006", "usdt", "/qr/705cd75ec40343dbb3008a352beb37ab.png", address3.getAddress(),"ERC20")); |
| | | redisLocalCache.put(partyId + "_USDT-ERC20",address3.getAddress()); |
| | | }else{ |
| | | usdtData.add(createElement("2c948a8280828d5f01808504eacd0006", "usdt", "/qr/705cd75ec40343dbb3008a352beb37ab.png", partyUSDT,"ERC20")); |
| | | } |
| | | coinMap.put("usdt", usdtData); |
| | | logger.info("--------------USDT-ERC20---------------"+coinMap.toString()); |
| | | } |
| | | }); |
| | | logger.info("----------------总得------------"+coinMap.toString()); |
| | | return coinMap; |
| | | } |
| | | |
| | | public List<Coin> listSupportCoin(String merchantId , boolean showBalance) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("merchantId", merchantId); |
| | | params.put("showBalance", showBalance); |
| | | ResultMsg result = JSONUtil.toBean(UdunUtils.post(gateway, merchantKey, ApiPath.SUPPORT_COIN, JSONUtil.toJsonStr(params)), ResultMsg.class); |
| | | if (result.getCode() != HttpStatus.HTTP_OK) { |
| | | Console.error(JSONUtil.toJsonStr(result)); |
| | | return null; |
| | | } |
| | | return JSONUtil.toList(JSONUtil.parseArray(result.getData()), Coin.class); |
| | | } |
| | | |
| | | public Address createAddress(String mainCoinType, String alias, String walletId, String callUrl) throws UdunException{ |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("merchantId", merchantId); |
| | | params.put("coinType", mainCoinType); |
| | | params.put("callUrl", defaultCallBackUrl); |
| | | params.put("walletId", walletId); |
| | | params.put("alias", alias); |
| | | |
| | | ResultMsg result = JSONUtil.toBean(UdunUtils.post(gateway, merchantKey, ApiPath.CREATE_ADDRESS, StrUtil.format("[{}]", JSONUtil.toJsonStr(params))), ResultMsg.class); |
| | | if (result.getCode() != HttpStatus.HTTP_OK) { |
| | | logger.error("createAddress:{}",JSONUtil.toJsonStr(result)); |
| | | throw new UdunException(result.getCode(), result.getMessage()); |
| | | } |
| | | return JSONUtil.toBean(result.getData(), Address.class); |
| | | } |
| | | |
| | | public boolean checkAddress(String mainCoinType, String address) { |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("merchantId", merchantId); |
| | | params.put("mainCoinType", mainCoinType); |
| | | params.put("address", address); |
| | | ResultMsg result = JSONUtil.toBean(UdunUtils.post(gateway, merchantKey, ApiPath.CHECK_ADDRESS, StrUtil.format("[{}]", JSONUtil.toJsonStr(params))), ResultMsg.class); |
| | | return result.getCode() == HttpStatus.HTTP_OK; |
| | | } |
| | | |
| | | private static Map<String, Object> createElement(String id, String coin, String img, String address,String blockchain_name) { |
| | |
| | | } |
| | | |
| | | private static List<Map<String, Object>> getCoinData(Map<String, List<Map<String, Object>>> coinMap, String coin) { |
| | | if (coin == null || coin.isEmpty()) { |
| | | List<Map<String, Object>> allData = new ArrayList<>(); |
| | | for (List<Map<String, Object>> coinData : coinMap.values()) { |
| | | allData.addAll(coinData); |
| | | } |
| | | return allData; |
| | | } |
| | | return coinMap.getOrDefault(coin, new ArrayList<>()); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(action +"rechargeCallback.action") |
| | | public ResultMsg rechargeCallback(HttpServletRequest request){ |
| | | String timestamp = request.getParameter("timestamp"); |
| | | String nonce = request.getParameter("nonce"); |
| | | String sign = request.getParameter("sign"); |
| | | String body = request.getParameter("body"); |
| | | logger.info("回调请求参数body{}:",body); |
| | | logger.info("回调请求参数sign{}:",sign); |
| | | try{ |
| | | rechargeBlockchainService.callback(timestamp,nonce,sign,body); |
| | | logger.info("回调成功"); |
| | | ResultMsg resultMsg = new ResultMsg(); |
| | | resultMsg.setCode(200); |
| | | return resultMsg; |
| | | }catch (Exception e){ |
| | | logger.info("回调异常",e); |
| | | ResultMsg resultMsg = new ResultMsg(); |
| | | resultMsg.setCode(500); |
| | | resultMsg.setMessage("回调处理失败"); |
| | | return resultMsg; |
| | | } |
| | | } |
| | | |
| | | } |