|
|
@ -235,22 +235,16 @@ public class RedServiceImpl implements RedService { |
|
|
@Override |
|
|
@Override |
|
|
public String checkRed(BigDecimal price,String linkId)throws Exception { |
|
|
public String checkRed(BigDecimal price,String linkId)throws Exception { |
|
|
try { |
|
|
try { |
|
|
// 构造 参数(order_id=L125) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构造参数 |
|
|
String body = "{\"order_id\":\"" + linkId + "\",\"amount\":" + price.divideToIntegralValue(BigDecimal.valueOf(100)).intValue() + "}"; |
|
|
String body = "{\"order_id\":\"" + linkId + "\",\"amount\":" + price.divideToIntegralValue(BigDecimal.valueOf(100)).intValue() + "}"; |
|
|
|
|
|
|
|
|
// 构建 HttpRequest |
|
|
// 构建 HttpRequest |
|
|
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(BASE_URL_Margen+PATH_CHECK)) |
|
|
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(BASE_URL_Margen+PATH_CHECK)) |
|
|
.header("Content-Type", "application/json") |
|
|
.header("Content-Type", "application/json") |
|
|
// ⭐ 透传 token,避免 JWT 过期问题 |
|
|
|
|
|
// .header("Authorization", authHeader) |
|
|
|
|
|
.POST(HttpRequest.BodyPublishers.ofString(body)) |
|
|
.POST(HttpRequest.BodyPublishers.ofString(body)) |
|
|
.build(); |
|
|
.build(); |
|
|
|
|
|
|
|
|
// 发送请求 |
|
|
// 发送请求 |
|
|
HttpResponse<String> resp = |
|
|
HttpResponse<String> resp = |
|
|
CLIENT.send(request, HttpResponse.BodyHandlers.ofString()); |
|
|
CLIENT.send(request, HttpResponse.BodyHandlers.ofString()); |
|
|
|
|
|
|
|
|
// HTTP 层校验 |
|
|
// HTTP 层校验 |
|
|
if (resp.statusCode() != 200 ) { |
|
|
if (resp.statusCode() != 200 ) { |
|
|
log.warn("红包接口 HTTP 异常,status:{},body:{}", |
|
|
log.warn("红包接口 HTTP 异常,status:{},body:{}", |
|
|
@ -260,6 +254,10 @@ public class RedServiceImpl implements RedService { |
|
|
// 解析返回 JSON |
|
|
// 解析返回 JSON |
|
|
JsonNode root = objectMapper.readTree(resp.body()); |
|
|
JsonNode root = objectMapper.readTree(resp.body()); |
|
|
int code = root.path("code").asInt(); |
|
|
int code = root.path("code").asInt(); |
|
|
|
|
|
if (code==0){ |
|
|
|
|
|
//旧订单 |
|
|
|
|
|
return "old"; |
|
|
|
|
|
} |
|
|
if (code == 400) { |
|
|
if (code == 400) { |
|
|
// 400 状态码表示参数错误 |
|
|
// 400 状态码表示参数错误 |
|
|
log.warn("该订单无法处理,status:{},body:{}", |
|
|
log.warn("该订单无法处理,status:{},body:{}", |
|
|
|