|
|
|
@ -1,19 +1,27 @@ |
|
|
|
package com.example.demo.serviceImpl.Temporary; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.example.demo.Util.BusinessException; |
|
|
|
import com.example.demo.config.RedTimeRuleConfig; |
|
|
|
import com.example.demo.domain.vo.Red; |
|
|
|
import com.example.demo.exception.SystemException; |
|
|
|
import com.example.demo.mapper.Temporary.RedMapper; |
|
|
|
import com.example.demo.service.Temporary.RedService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.http.HttpClient; |
|
|
|
import java.net.http.HttpRequest; |
|
|
|
import java.net.http.HttpResponse; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @program: GOLD |
|
|
|
* @ClassName RedServiceImpl |
|
|
|
@ -22,8 +30,15 @@ import java.time.format.DateTimeFormatter; |
|
|
|
* @create: 2025−12-03 16:37 |
|
|
|
* @Version 1.0 |
|
|
|
**/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class RedServiceImpl implements RedService { |
|
|
|
private static final String BASE_URLProd = "http://39.101.133.168:8828/scms"; |
|
|
|
private static final String BASE_URLDev = "http://gf977328.natappfree.cc"; |
|
|
|
private static final String PATH = "/api/coupon/IssueRechargeRedPacket"; |
|
|
|
|
|
|
|
private static final HttpClient CLIENT = HttpClient.newHttpClient(); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RedMapper redMapper; |
|
|
|
@Autowired |
|
|
|
@ -62,6 +77,35 @@ public class RedServiceImpl implements RedService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
调用充值红包发放接口 |
|
|
|
|
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String sendJwcode(Integer jwcode) { |
|
|
|
try { |
|
|
|
String body = JSON.toJSONString(java.util.Map.of("jwcode", jwcode)); |
|
|
|
|
|
|
|
HttpRequest request = HttpRequest.newBuilder() |
|
|
|
.uri(URI.create(BASE_URLDev + PATH)) //URL记得换 |
|
|
|
.header("Content-Type", "application/json") |
|
|
|
.POST(HttpRequest.BodyPublishers.ofString(body)) |
|
|
|
.build(); |
|
|
|
|
|
|
|
HttpResponse<String> resp = CLIENT.send(request, HttpResponse.BodyHandlers.ofString()); |
|
|
|
|
|
|
|
if (resp.statusCode() != 200) { |
|
|
|
log.warn("红包接口异常,status:{},body:{}", resp.statusCode(), resp.body()); |
|
|
|
} |
|
|
|
return resp.body(); |
|
|
|
} catch (IOException | InterruptedException e) { |
|
|
|
log.error("调用红包接口失败,jwcode:{}", jwcode, e); |
|
|
|
return "{\"success\":false,\"msg\":\"网络异常\"}"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// --- 校验方法 --- |
|
|
|
private void validateParams(Integer jwcode, Integer type, BigDecimal delta) { |
|
|
|
if (jwcode == null || jwcode <= 0) { |
|
|
|
|