|
|
@@ -1,9 +1,12 @@
|
|
|
package com.yc.ship.module.trade.utils;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.anji.captcha.util.MD5Util;
|
|
|
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;
|
|
|
@@ -11,8 +14,10 @@ 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.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception0;
|
|
|
@@ -173,14 +178,8 @@ public class InsuranceUtil {
|
|
|
|
|
|
log.info("阳光系统校验响应内容: {}", responseBody);
|
|
|
JSONObject responseBodyJson = JSONObject.parseObject(responseBody);
|
|
|
- if ("200".equals(responseBodyJson.getString("code"))) {
|
|
|
- JSONObject data = responseBodyJson.getJSONObject("data");
|
|
|
- String status = data.getString("status");
|
|
|
- if("SUCCESS".equals(status)) {
|
|
|
- return CommonResult.success(responseBody);
|
|
|
- }else {
|
|
|
- return CommonResult.error(500, "阳光系统校验返回错误: " + response.getStatusCode() + responseBody);
|
|
|
- }
|
|
|
+ if ("SUCCESS".equals(responseBodyJson.getString("status"))) {
|
|
|
+ return CommonResult.success(responseBody);
|
|
|
} else {
|
|
|
// 响应失败,返回错误信息
|
|
|
return CommonResult.error(500, "阳光系统校验返回错误: " + response.getStatusCode() + responseBody);
|
|
|
@@ -259,63 +258,30 @@ public class InsuranceUtil {
|
|
|
|
|
|
public CommonResult queryInsurance(String orderNo) {
|
|
|
try {
|
|
|
- JSONObject request = new JSONObject();
|
|
|
+ Map<String, String> request = new LinkedHashMap<>();
|
|
|
+ request.put("appId", APPID);
|
|
|
request.put("externalOrderNo", orderNo);
|
|
|
- String reqJson = JSONObject.toJSONString(request);
|
|
|
- String sign = SignUtil.generateMD5Sign(APPID, reqJson, KEY);
|
|
|
+ request.put("key", KEY);
|
|
|
+ String sign = MD5Util.md5(APPID+orderNo+KEY);
|
|
|
|
|
|
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
|
|
params.add("appId", APPID);
|
|
|
- params.add("req", reqJson);
|
|
|
+ params.add("externalOrderNo", orderNo);
|
|
|
params.add("sign", sign);
|
|
|
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
|
|
|
- HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(params, headers);
|
|
|
+ String url = HOST + QUERY_URL + "?appId=" + APPID + "&externalOrderNo=" + orderNo + "&sign=" + sign;
|
|
|
|
|
|
- log.info("发送退保请求到阳光系统: {}", HOST + RECEIVE_URL);
|
|
|
- log.info("请求参数: appId={}, req={}, sign={}", APPID, reqJson, sign);
|
|
|
|
|
|
- // 发送请求并获取响应
|
|
|
- ResponseEntity<byte[]> response = restTemplate.exchange(
|
|
|
- HOST + RECEIVE_URL,
|
|
|
- HttpMethod.POST,
|
|
|
- entity,
|
|
|
- byte[].class
|
|
|
- );
|
|
|
+ log.info("发送查询请求到阳光系统: {}", url);
|
|
|
|
|
|
- log.info("阳光系统响应状态码: {}", 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);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- log.info("阳光系统响应内容: {}", responseBody);
|
|
|
- JSONObject responseBodyJson = JSONObject.parseObject(responseBody);
|
|
|
-
|
|
|
- if (response.getStatusCode() == HttpStatus.OK) {
|
|
|
- String status = responseBodyJson.getString("status");
|
|
|
- if("FAIL".equals(status)) {
|
|
|
- return CommonResult.error(500, "阳光系统退保返回错误: " + response.getStatusCode() + responseBody);
|
|
|
- }else {
|
|
|
- return CommonResult.success(responseBody);
|
|
|
- }
|
|
|
- } else {
|
|
|
- return CommonResult.error(500, "阳光系统退保返回错误: " + response.getStatusCode() + responseBody);
|
|
|
- }
|
|
|
+ String s = HttpUtils.get(url, null);
|
|
|
|
|
|
+ log.info("阳光系统查询响应内容: {}", s);
|
|
|
+ return CommonResult.success(s);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("发送退保请求失败", e);
|
|
|
- return CommonResult.error(500,"发送退保请求失败: " + e.getMessage());
|
|
|
+ log.error("发送查询请求失败", e);
|
|
|
+ return CommonResult.error(500,"发送查询请求失败: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|