Skip to content

Commit

Permalink
添加Logback日志
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn authored and Shawn committed Apr 8, 2022
1 parent edf381f commit 11933b8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@

<groupId>com.uduncloud</groupId>
<artifactId>udun-sdk</artifactId>
<version>2.1.3</version>
<version>2.1.4</version>

<dependencies>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.4.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/uduncloud/sdk/client/UdunApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.uduncloud.sdk.domain.Address;
import com.uduncloud.sdk.domain.Coin;
import com.uduncloud.sdk.domain.ResultMsg;
import com.uduncloud.sdk.exception.UdunException;

import java.math.BigDecimal;
import java.util.List;
Expand All @@ -14,7 +15,7 @@ public interface UdunApi {
* @param mainCoinType 主币种编号,使用获取商户币种信息接口
* @return 地址
*/
Address createAddress(String mainCoinType);
Address createAddress(String mainCoinType) throws UdunException;

/**
* 创建币种地址,别名和钱包编号自定义,回调地址使用统一配置
Expand All @@ -24,7 +25,7 @@ public interface UdunApi {
* @param walletId 钱包编号
* @return 地址
*/
Address createAddress(String mainCoinType, String alias, String walletId);
Address createAddress(String mainCoinType, String alias, String walletId) throws UdunException;

/**
* 创建币种地址,别名和钱包编号自定义,回调地址自定义
Expand All @@ -35,7 +36,7 @@ public interface UdunApi {
* @param callUrl 回调地址
* @return 地址
*/
Address createAddress(String mainCoinType, String alias, String walletId, String callUrl);
Address createAddress(String mainCoinType, String alias, String walletId, String callUrl) throws UdunException;


/**
Expand Down
26 changes: 17 additions & 9 deletions src/main/java/com/uduncloud/sdk/client/UdunClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,36 @@
import com.uduncloud.sdk.domain.Address;
import com.uduncloud.sdk.domain.Coin;
import com.uduncloud.sdk.domain.ResultMsg;
import com.uduncloud.sdk.exception.UdunException;
import com.uduncloud.sdk.util.UdunUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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;

/**
* 商户key
* UDUN Merchant Key
*/
private final String merchantKey;

/**
* 默认回调地址
* Callback to business system
*/
private final String defaultCallBackUrl;

Expand All @@ -41,17 +49,17 @@ public UdunClient(String gateway, String merchantId, String merchantKey, String
}

@Override
public Address createAddress(String mainCoinType) {
public Address createAddress(String mainCoinType) throws UdunException{
return createAddress(mainCoinType, "", "", defaultCallBackUrl);
}

@Override
public Address createAddress(String mainCoinType, String alias, String walletId) {
public Address createAddress(String mainCoinType, String alias, String walletId) throws UdunException{
return createAddress(mainCoinType, alias, walletId, defaultCallBackUrl);
}

@Override
public Address createAddress(String mainCoinType, String alias, String walletId, String callUrl) {
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);
Expand All @@ -61,8 +69,8 @@ public Address createAddress(String mainCoinType, String alias, String walletId,

ResultMsg result = JSONUtil.toBean(UdunUtils.post(gateway, merchantKey, ApiPath.CREATE_ADDRESS, StrUtil.format("[{}]", JSONUtil.toJsonStr(params))), ResultMsg.class);
if (result.getCode() != HttpStatus.HTTP_OK) {
Console.error(JSONUtil.toJsonStr(result));
return null;
logger.error("createAddress:{}",JSONUtil.toJsonStr(result));
throw new UdunException(result.getCode(), result.getMessage());
}
return JSONUtil.toBean(result.getData(), Address.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.uduncloud.sdk.exception;

public class CustomException extends RuntimeException {
public class UdunException extends RuntimeException {
private Integer code;
private String message;

public CustomException(Integer code, String message) {
public UdunException(Integer code, String message) {
this.code = code;
this.message = message;
}
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/uduncloud/sdk/util/UdunUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;


public class UdunUtils {
private static Logger logger = LoggerFactory.getLogger(UdunUtils.class);

public static String post(String gateway, String merchantKey, String path, String body) {
HttpResponse response = HttpRequest.post(gateway + path).body(parseParams(merchantKey, body)).execute();
return response.body();
String rawBody = parseParams(merchantKey, body);
logger.debug("HttpRequest POST {}",gateway+path);
logger.debug("BODY {}",rawBody);
HttpResponse response = HttpRequest.post(gateway + path)
.body(rawBody)
.execute();
String resp = response.body();
logger.debug("HttpResponse {}",resp);
return resp;
}

public static String parseParams(String merchantKey, String body) {
Expand Down

0 comments on commit 11933b8

Please sign in to comment.