| | |
| | | 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; |
| | |
| | | * @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://101.132.189.0:5002/"; |
| | | //public static final String SIGN_STR = "w@a!llokmet"; |
| | | public static final String SIGN_STR = "51F40C224CACE2204A998DAB85D5618EE4F3"; |
| | | |
| | | 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"); |
| | | } |
| | | } |