|
@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.http.*;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.MimeType;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.util.Map;
|
|
@@ -28,9 +29,14 @@ public class CallBackUtil {
|
|
|
|
|
|
static {
|
|
|
headers = new HttpHeaders();
|
|
|
- MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
- headers.setContentType(type);
|
|
|
- headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
+
|
|
|
+ //MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
+ //MediaType type = MediaType.parseMediaType("text/html; charset=UTF-8");
|
|
|
+ //headers.setContentType(type);
|
|
|
+
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+
|
|
|
+ headers.add("Accept", MediaType.ALL_VALUE);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -50,28 +56,34 @@ public class CallBackUtil {
|
|
|
/**
|
|
|
* 将请求的数据封装成json格式
|
|
|
*/
|
|
|
- HttpEntity<String> formEntity = new HttpEntity<String>(cardSecretStatus.toJson().toJSONString(), headers);
|
|
|
- ResponseEntity<JSONObject> response = restTemplate.postForEntity(callbackUrl, formEntity, JSONObject.class);
|
|
|
+ //HttpEntity<String> formEntity = new HttpEntity<String>(cardSecretStatus.toJson().toJSONString(), headers);
|
|
|
+
|
|
|
+ HttpEntity<CallbackCardSecretStatus> formEntity = new HttpEntity<CallbackCardSecretStatus>(cardSecretStatus, headers);
|
|
|
+ log.info("request is : {} , url is : {}",cardSecretStatus.toJson().toJSONString(), callbackUrl);
|
|
|
+
|
|
|
+ //ResponseEntity<JSONObject> response = restTemplate.postForEntity(callbackUrl, formEntity, JSONObject.class);
|
|
|
+ ResponseEntity<String> response = restTemplate.postForEntity(callbackUrl, formEntity, String.class);
|
|
|
+ log.info("response code is : {} , body is : {}",response.getStatusCodeValue(), response.getBody());
|
|
|
|
|
|
/**
|
|
|
* 判断回调是否成功,返回的body 数据为1 代表返回成功
|
|
|
*/
|
|
|
- if (response.getStatusCode() == HttpStatus.OK) {
|
|
|
- JSONObject tmp = response.getBody();
|
|
|
- if(tmp.getInteger("status") == 1){
|
|
|
- log.info("request is : {}, response is : {} ",cardSecretStatus.toJson().toJSONString() ,tmp.toJSONString());
|
|
|
- }else{
|
|
|
- log.info("卡密通知结果回调失败,发送信息为 {} ", cardSecretStatus.toJson().toJSONString());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }else {
|
|
|
- /**
|
|
|
- * 回调地址连接不成功的日志
|
|
|
- */
|
|
|
- log.error("回调网络连接失败url: {} , response is : {},", callbackUrl, response.getBody());
|
|
|
-
|
|
|
- }
|
|
|
+// if (response.getStatusCode() == HttpStatus.OK) {
|
|
|
+// JSONObject tmp = response.getBody();
|
|
|
+// if(tmp.getInteger("status") == 1){
|
|
|
+// log.info("request is : {}, response is : {} ",cardSecretStatus.toJson().toJSONString() ,tmp.toJSONString());
|
|
|
+// }else{
|
|
|
+// log.info("卡密通知结果回调失败,发送信息为 {} ", cardSecretStatus.toJson().toJSONString());
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// }else {
|
|
|
+// /**
|
|
|
+// * 回调地址连接不成功的日志
|
|
|
+// */
|
|
|
+// log.error("回调网络连接失败url: {} , response is : {},", callbackUrl, response.getBody());
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
|
|
|
}
|