新版仿ok交易所-后端
peter
2025-10-13 e69a57d95f9c85be977f0429394e3dc82cc55129
trading-order-admin/src/main/java/com/yami/trading/api/UD/UdunClient.java
@@ -4,43 +4,46 @@
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpStatus;
import cn.hutool.json.JSONUtil;
import com.yami.trading.common.constants.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class UdunClient implements UdunApi {
    private static Logger logger = LoggerFactory.getLogger(UdunClient.class);
    /**
     * UDUN API Gateway
     */
    private final String gateway;
    /**
     * UDUN Merchant Number
     */
    private final String merchantId;
    private final String gateway =  "https://sig11.udun.io";
    /**
     * UDUN Merchant Key
     */
    private final String merchantKey;
    private final String merchantKey =  "7161e42ff45204dca8b9c4e203b24f63";
    /**
     * Callback to business system
     * UDUN Merchant Number
     */
    private final String defaultCallBackUrl;
    private final String merchantId =  "321176";
    public UdunClient(String gateway, String merchantId, String merchantKey, String defaultCallBackUrl) {
        this.gateway = gateway;
        this.merchantId = merchantId;
        this.merchantKey = merchantKey;
        this.defaultCallBackUrl = defaultCallBackUrl;
    }
    /**
     * Callback 充值
     */
    private final String defaultCallBackUrl = Constants.API_HTTP + "api/channelBlockchain!rechargeCallback.action";
    /**
     * Callback 提币
     */
    private final String withdrawCallBackUrl =  Constants.API_HTTP + "api/withdraw/withdrawCallback.action";
    @Override
    public Address createAddress(String mainCoinType)  throws UdunException {
@@ -56,7 +59,7 @@
    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("mainCoinType", mainCoinType);
        params.put("callUrl", callUrl);
        params.put("walletId", walletId);
        params.put("alias", alias);
@@ -71,7 +74,7 @@
    @Override
    public ResultMsg withdraw(String address, BigDecimal amount, String mainCoinType, String coinType, String businessId, String memo) {
        return withdraw(address, amount, mainCoinType, coinType, businessId, memo, defaultCallBackUrl);
        return withdraw(address, amount, mainCoinType, coinType, businessId, memo, withdrawCallBackUrl);
    }
    @Override
@@ -90,7 +93,7 @@
    @Override
    public ResultMsg autoWithdraw(String address, BigDecimal amount, String mainCoinType, String coinType, String businessId, String memo) {
        return autoWithdraw(address, amount, mainCoinType, coinType, businessId, memo, defaultCallBackUrl);
        return autoWithdraw(address, amount, mainCoinType, coinType, businessId, memo, withdrawCallBackUrl);
    }
    @Override
@@ -129,4 +132,19 @@
        }
        return JSONUtil.toList(JSONUtil.parseArray(result.getData()), Coin.class);
    }
    public boolean checkSign(String timestamp, String nonce, String body, String sign) {
        String checkSign = UdunUtils.sign(merchantKey, timestamp, nonce, body);
        return checkSign.equals(sign);
    }
    public static void main(String[] args) {
        Map<String, Object> params = new HashMap<>();
        params.put("merchantId", 321176);
        params.put("showBalance", false);
        ResultMsg result = JSONUtil.toBean(UdunUtils.post("https://sig11.udun.io", "7161e42ff45204dca8b9c4e203b24f63", ApiPath.SUPPORT_COIN, JSONUtil.toJsonStr(params)), ResultMsg.class);
        if (result.getCode() != HttpStatus.HTTP_OK) {
            Console.error(JSONUtil.toJsonStr(result));
        }
        System.out.println(JSONUtil.toList(JSONUtil.parseArray(result.getData()), Coin.class));
    }
}