| | |
| | | import cn.hutool.json.JSONUtil; |
| | | 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 = "871fb1a18afd7229f5e62e4cba5016a6"; |
| | | |
| | | /** |
| | | * Callback to business system |
| | | * UDUN Merchant Number |
| | | */ |
| | | private final String defaultCallBackUrl; |
| | | private final String merchantId = "321127"; |
| | | |
| | | 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 = "https://syjysapi.yanshiz.com/api/channelBlockchain!rechargeCallback.action"; |
| | | |
| | | /** |
| | | * Callback 提币 |
| | | */ |
| | | private final String withdrawCallBackUrl = "https://syjysapi.yanshiz.com/api/withdraw/withdrawCallback.action"; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public Address createAddress(String mainCoinType) throws UdunException { |
| | |
| | | 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); |
| | |
| | | |
| | | @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 |
| | |
| | | |
| | | @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 |
| | |
| | | } |
| | | 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); |
| | | } |
| | | } |