xiaoyong931011
2021-01-15 292a4634d9c52ce193eca9de356d65960bdc35f4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.xcong.excoin.utils;
 
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;
import java.util.Map;
 
/**
 * @author wzy
 * @date 2020-11-05
 **/
@Slf4j
public class TRC20ApiUtils {
    private static final String TRC20_API = "http://101.132.189.0:5002/";
  //public static final String SIGN_STR = "w@a!llokmet";
    public static final String SIGN_STR = "51F40C224CACE2204A998DAB85D5618EE4F3";
 
    /**
     * 提币申请
     */
    public static void coinApply(String orderNo, String userId, String symbol, String amount, String toAddress) {
        Map<String, Object> param = new HashMap<>();
        param.put("orderno", orderNo);
        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(TRC20_API + "transout/created");
        String body = request.body(JSONObject.toJSONString(param)).execute().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");
    }
}