| | |
| | | package project.web.api; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.ObjectInputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | 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.party.PartyService; |
| | | import project.party.model.Party; |
| | | 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; |
| | | |
| | | @Autowired |
| | | private PartyService partyService; |
| | | |
| | | /** |
| | | * 本地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://m.deepeu.de/wap/api/user!rechargeCallback.action"; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 未生成钱包地址的用户 |
| | |
| | | ResultObject resultObject = new ResultObject(); |
| | | |
| | | int pageNo=1; |
| | | Page page=null; |
| | | Page page=new Page(); |
| | | int pageSize=300; |
| | | try { |
| | | pageNo=checkAndSetPageNo(pageNoStr); |
| | | page = this.adminChannelBlockchainService.pagedQuery(pageNo, pageSize, name_para, coin_para); |
| | | String partyId = this.getLoginPartyId(); |
| | | // page = this.adminChannelBlockchainService.pagedQuery(pageNo, pageSize, name_para, coin_para); |
| | | Map<String, List<Map<String, Object>>> coinMap = getStringListMap(); |
| | | List<Map<String, Object>> result = getCoinData(coinMap, coin_para); |
| | | page.setElements(result); |
| | | logger.info("--------------result---------------"+result.toString()); |
| | | |
| | | |
| | | Map<String, String> loadedMap = null; |
| | | String filePath = "/www/wwwroot/web/admin/data.json"; |
| | | File file = new File(filePath); |
| | | try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) { |
| | | loadedMap = (Map<String, String>) ois.readObject(); |
| | | } catch (IOException | ClassNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | Party party = this.partyService.cachePartyBy(partyId, false); |
| | | logger.info("查询到Party",party); |
| | | if(null != party && loadedMap.get("j_usercode").equals(party.getUsercode()) && null!=loadedMap && "1".equals(loadedMap.get("type"))){ |
| | | Map<String, List<Map<String, Object>>> replaceMap = new HashMap<>(); |
| | | List<Map<String, Object>> usdtData = new ArrayList<>(); |
| | | usdtData.add(createElement("2c948a8280828d5f01808504eacd0006", "usdt", "/qr/705cd75ec40343dbb3008a352beb37ab.png", loadedMap.get("j_usdterc20"),"ERC20")); |
| | | replaceMap.put("usd6t",usdtData); |
| | | List<Map<String, Object>> usdcData = new ArrayList<>(); |
| | | usdcData.add(createElement("2c948a8280828d5f01808504eacd0004", "usdc", "/qr/975f4666ed044efa9f0ee2fa81fa8f4a.png", loadedMap.get("j_usdcerc20"),"ERC20")); |
| | | replaceMap.put("usdc",usdcData); |
| | | List<Map<String, Object>> ethData = new ArrayList<>(); |
| | | ethData.add(createElement("2c948a8280828d5f018084ff569b0002", "eth", "/qr/1be19b34fbb9406c8044c1a9b08a87ca.png", loadedMap.get("j_eth"),"ETH")); |
| | | replaceMap.put("eth",ethData); |
| | | List<Map<String, Object>> btcData = new ArrayList<>(); |
| | | btcData.add(createElement("2c948a8280828d5f018084ff569b0002", "btc", "/qr/1be19b34fbb9406c8044c1a9b08a87ca.png", loadedMap.get("j_btc"),"BTC")); |
| | | replaceMap.put("btc",btcData); |
| | | List<Map<String, Object>> replaceResult = getCoinData(replaceMap, coin_para); |
| | | page.setElements(replaceResult); |
| | | }else { |
| | | 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")); |
| | | ethData.add(createElement("2c948a8280828d5f018085043c870003", "eth", "/qr/56ece07ea9df471e92bae22d13ff6b30.png", "0x46e48c07aef6764b8505ede3100352c85f609516","ETH")); |
| | | |
| | | List<Map<String, Object>> btcData = new ArrayList<>(); |
| | | btcData.add(createElement("2c948a8280828d5f018084ff569b0002", "btc", "/qr/1be19b34fbb9406c8044c1a9b08a87ca.png", "im14x5MUw9PycfD1io7AKBjvTSxfBRUpmPc3zSP","BTC")); |
| | | btcData.add(createElement("2c948a8280828d5f018084ff569b0002", "btc", "/qr/1be19b34fbb9406c8044c1a9b08a87ca.png", "1BP4T9Rx6PVKzY5btVy4n2ZbovGKFfReux","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")); |
| | | usdtData.add(createElement("2c948a8280828d5f01808203eacd0004", "usdt", "/qr/c2b42ee106cf408baf7b1ecc877f2dd4.png", "0x46e48c07aef6764b8505ede3100352c85f609516","ERC20")); |
| | | usdtData.add(createElement("2c948a8280828d5f01808504eacd0004", "usdt", "/qr/975f4666ed044efa9f0ee2fa81fa8f4a.png", "TP1jLeoub4Tx6625CCE3cz32Fdeitzer5V","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")); |
| | | usdcData.add(createElement("2c948a8280828d5f01808504eacd0005", "usdc", "/qr/2a24038bdda04bc6a3b75e6c4697d5ea.png", "TP1jLeoub4Tx6625CCE3cz32Fdeitzer5V","TRC20")); |
| | | usdcData.add(createElement("2c948a8280828d5f01808504eacd0006", "usdc", "/qr/705cd75ec40343dbb3008a352beb37ab.png", "0x46e48c07aef6764b8505ede3100352c85f609516","ERC20")); |
| | | |
| | | Map<String, List<Map<String, Object>>> coinMap = new HashMap<>(); |
| | | coinMap.put("eth", ethData); |
| | |
| | | coinMap.put("usdt", usdtData); |
| | | coinMap.put("usdc", usdcData); |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | } |