From 37f0bbe5f120e083469b293779bbea1e106b97c2 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 19 Nov 2020 16:55:13 +0800
Subject: [PATCH] modify
---
src/main/java/com/xcong/excoin/utils/TRC20ApiUtils.java | 64 ++++++++++++++++++++++++++------
1 files changed, 52 insertions(+), 12 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/utils/TRC20ApiUtils.java b/src/main/java/com/xcong/excoin/utils/TRC20ApiUtils.java
index dde4c24..d60d55b 100644
--- a/src/main/java/com/xcong/excoin/utils/TRC20ApiUtils.java
+++ b/src/main/java/com/xcong/excoin/utils/TRC20ApiUtils.java
@@ -3,6 +3,8 @@
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
+import com.xcong.excoin.common.exception.GlobalException;
+import lombok.extern.slf4j.Slf4j;
import java.math.BigDecimal;
import java.util.HashMap;
@@ -12,26 +14,64 @@
* @author wzy
* @date 2020-11-05
**/
+@Slf4j
public class TRC20ApiUtils {
- private static final String SRC_API = "http://27.50.59.35:5002/";
- private static final String SIGN_STR = "w@a!llokmet";
+ private static final String TRC20_API = "http://27.50.59.35:5002/";
+ public static final String SIGN_STR = "w@a!llokmet";
- public static void apply() {
+ /**
+ * 提币申请
+ */
+ public static void coinApply(String orderNo, String userId, String symbol, String amount, String toAddress) {
Map<String, Object> param = new HashMap<>();
- String orderNo = "123445";
- String userid = "11";
- String symbol = "USDT";
- String amount = "1";
- String toAddress = "Ox";
param.put("orderno", orderNo);
- param.put("userid", userid);
+ param.put("userid", userId);
param.put("symbol", symbol);
param.put("toAddress", toAddress);
param.put("amount", new BigDecimal(amount));
- param.put("sign", SecureUtil.md5(orderNo + userid + symbol + amount + toAddress + SIGN_STR));
- HttpRequest request = HttpRequest.post(SRC_API + "transout/created");
+ param.put("sign", SecureUtil.md5(orderNo + userId + symbol + amount + toAddress + SIGN_STR));
+ HttpRequest request = HttpRequest.post(TRC20_API + "transout/created");
String body = request.body(JSONObject.toJSONString(param)).execute().body();
- System.out.println(body);
+ if (!"200".equals(JSONObject.parseObject(body).getString("code"))) {
+ log.error("TRC20提币申请失败 : {}", body);
+ throw new GlobalException("提币申请失败");
+ }
}
+
+ /**
+ * 提币订单查询
+ *
+ * @param orderNo 订单编号
+ */
+ public static String getApplyOrderInfo(String orderNo) {
+ String body = HttpRequest.get(TRC20_API + "transout/gettransout?orderNo=" + orderNo).execute().body();
+ if (!"200".equals(JSONObject.parseObject(body).getString("code"))) {
+ log.error("TRC20获取订单失败:{}, {}", orderNo, body);
+ throw new GlobalException("获取订单失败");
+ }
+
+ return JSONObject.parseObject(body).getString("row");
+ }
+
+ public static void createWallet(Long userId, String userName, String symbol, String address) {
+ log.info("创建钱包开始:{}", System.currentTimeMillis());
+ Map<String, Object> param = new HashMap<>();
+ param.put("userId", userId);
+ param.put("symbol", symbol);
+ param.put("userName", userName);
+ param.put("walletAddress", address);
+ param.put("accountFlag", 1);
+ param.put("sign", SecureUtil.md5(userId + symbol + address + SIGN_STR));
+ String body = HttpRequest.post(TRC20_API + "account/created").body(JSONObject.toJSONString(param)).execute().body();
+ log.info("创建钱包结束:{}", System.currentTimeMillis());
+ if (!"200".equals(JSONObject.parseObject(body).getString("code"))) {
+ log.error("TRC20创建钱包失败:{}, {}, {}", userId, address, body);
+ throw new GlobalException("获取订单失败");
+ }
+ }
+
+ public static void main(String[] args) {
+ createWallet(1L, "1", "USDT", "11");
+ }
}
--
Gitblit v1.9.1