|
|
@@ -6,7 +6,6 @@ import com.yc.ship.framework.common.pojo.CommonResult;
|
|
|
import com.yc.ship.framework.common.util.http.HttpUtils;
|
|
|
import com.yc.ship.module.trade.api.insurance.dto.InsuranceApplyReqDTO;
|
|
|
import com.yc.ship.module.trade.api.insurance.dto.InsuranceCancelReqDTO;
|
|
|
-import com.yc.ship.module.trade.framework.mq.TradePublishUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.http.*;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
@@ -14,8 +13,8 @@ import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.Map;
|
|
|
@@ -43,7 +42,9 @@ public class InsuranceUtil {
|
|
|
|
|
|
private final Integer VALIDATE_LEVEL = 0; //校验级别,其值有 0/1
|
|
|
|
|
|
- /** REST模板 */
|
|
|
+ /**
|
|
|
+ * REST模板
|
|
|
+ */
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
/**
|
|
|
@@ -57,6 +58,7 @@ public class InsuranceUtil {
|
|
|
/**
|
|
|
* 发送投保请求
|
|
|
* 将投保请求发送到阳光系统
|
|
|
+ *
|
|
|
* @param request 投保请求
|
|
|
* @return 投保响应
|
|
|
*/
|
|
|
@@ -105,9 +107,9 @@ public class InsuranceUtil {
|
|
|
|
|
|
if (response.getStatusCode() == HttpStatus.OK) {
|
|
|
String status = responseBodyJson.getString("status");
|
|
|
- if("FAIL".equals(status)) {
|
|
|
+ if ("FAIL".equals(status)) {
|
|
|
return CommonResult.error(500, "阳光系统投保返回错误: " + response.getStatusCode() + responseBody);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
return CommonResult.success(responseBody);
|
|
|
}
|
|
|
} else {
|
|
|
@@ -116,19 +118,20 @@ public class InsuranceUtil {
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error("发送投保请求失败", e);
|
|
|
- return CommonResult.error(500,"发送投保请求失败: " + e.getMessage());
|
|
|
+ return CommonResult.error(500, "发送投保请求失败: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 校验保险请求
|
|
|
* 在调用投保接口前,为了提高投保成功率,可先调用校验接口,检查客户系统组织的请求是否符合预期
|
|
|
+ *
|
|
|
* @param request 投保请求
|
|
|
* @return 校验响应
|
|
|
*/
|
|
|
public CommonResult validateInsuranceRequest(InsuranceApplyReqDTO request) {
|
|
|
try {
|
|
|
- String reqJson = JSONObject.toJSONString(request);
|
|
|
+ String reqJson = JSONObject.toJSONString(request);
|
|
|
|
|
|
// 构建校验请求参数
|
|
|
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
|
|
@@ -186,13 +189,14 @@ public class InsuranceUtil {
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("发送校验请求失败", e);
|
|
|
- throw exception0(500,"发送校验请求失败: " + e.getMessage(), e);
|
|
|
+ throw exception0(500, "发送校验请求失败: " + e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 发送退保请求
|
|
|
* 将退保请求发送到阳光系统
|
|
|
+ *
|
|
|
* @param request 退保请求
|
|
|
* @return 退保响应
|
|
|
*/
|
|
|
@@ -205,15 +209,11 @@ public class InsuranceUtil {
|
|
|
params.add("appId", APPID);
|
|
|
params.add("req", reqJson);
|
|
|
params.add("sign", sign);
|
|
|
-
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
-
|
|
|
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(params, headers);
|
|
|
-
|
|
|
- log.info("发送退保请求到阳光系统: {}", HOST + RECEIVE_URL);
|
|
|
- log.info("请求参数: appId={}, req={}, sign={}", APPID, reqJson, sign);
|
|
|
-
|
|
|
+ log.error("发送退保请求到阳光系统: {}", HOST + RECEIVE_URL);
|
|
|
+ log.error("请求参数: appId={}, req={}, sign={}", APPID, reqJson, sign);
|
|
|
// 发送请求并获取响应
|
|
|
ResponseEntity<byte[]> response = restTemplate.exchange(
|
|
|
HOST + RECEIVE_URL,
|
|
|
@@ -221,29 +221,20 @@ public class InsuranceUtil {
|
|
|
entity,
|
|
|
byte[].class
|
|
|
);
|
|
|
-
|
|
|
- log.info("阳光系统响应状态码: {}", response.getStatusCode());
|
|
|
-
|
|
|
+ log.error("阳光系统响应状态码: {}", response.getStatusCode());
|
|
|
// 手动处理响应字节流,确保使用UTF-8编码
|
|
|
byte[] responseBytes = response.getBody();
|
|
|
String responseBody = null;
|
|
|
if (responseBytes != null) {
|
|
|
- try {
|
|
|
- responseBody = new String(responseBytes, "UTF-8");
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
- log.error("解析响应内容编码失败", e);
|
|
|
- responseBody = new String(responseBytes);
|
|
|
- }
|
|
|
+ responseBody = new String(responseBytes, StandardCharsets.UTF_8);
|
|
|
}
|
|
|
-
|
|
|
- log.info("阳光系统响应内容: {}", responseBody);
|
|
|
+ log.error("阳光系统响应内容: {}", responseBody);
|
|
|
JSONObject responseBodyJson = JSONObject.parseObject(responseBody);
|
|
|
-
|
|
|
if (response.getStatusCode() == HttpStatus.OK) {
|
|
|
String status = responseBodyJson.getString("status");
|
|
|
- if("FAIL".equals(status)) {
|
|
|
+ if ("FAIL".equals(status)) {
|
|
|
return CommonResult.error(500, "阳光系统退保返回错误: " + response.getStatusCode() + responseBody);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
return CommonResult.success(responseBody);
|
|
|
}
|
|
|
} else {
|
|
|
@@ -252,7 +243,7 @@ public class InsuranceUtil {
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error("发送退保请求失败", e);
|
|
|
- return CommonResult.error(500,"发送退保请求失败: " + e.getMessage());
|
|
|
+ return CommonResult.error(500, "发送退保请求失败: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -262,26 +253,20 @@ public class InsuranceUtil {
|
|
|
request.put("appId", APPID);
|
|
|
request.put("externalOrderNo", orderNo);
|
|
|
request.put("key", KEY);
|
|
|
- String sign = MD5Util.md5(APPID+orderNo+KEY);
|
|
|
+ String sign = MD5Util.md5(APPID + orderNo + KEY);
|
|
|
|
|
|
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
|
|
params.add("appId", APPID);
|
|
|
params.add("externalOrderNo", orderNo);
|
|
|
params.add("sign", sign);
|
|
|
-
|
|
|
-
|
|
|
String url = HOST + QUERY_URL + "?appId=" + APPID + "&externalOrderNo=" + orderNo + "&sign=" + sign;
|
|
|
-
|
|
|
-
|
|
|
- log.info("发送查询请求到阳光系统: {}", url);
|
|
|
-
|
|
|
+ log.error("发送查询请求到阳光系统: {}", url);
|
|
|
String s = HttpUtils.get(url, null);
|
|
|
-
|
|
|
- log.info("阳光系统查询响应内容: {}", s);
|
|
|
+ log.error("阳光系统查询响应内容: {}", s);
|
|
|
return CommonResult.success(s);
|
|
|
} catch (Exception e) {
|
|
|
log.error("发送查询请求失败", e);
|
|
|
- return CommonResult.error(500,"发送查询请求失败: " + e.getMessage());
|
|
|
+ return CommonResult.error(500, "发送查询请求失败: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|