|
@@ -26,6 +26,7 @@ import java.util.Enumeration;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.LinkedHashMap;
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.TreeMap;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @Author: codingliang
|
|
* @Author: codingliang
|
|
@@ -37,6 +38,7 @@ import java.util.Map;
|
|
|
@Component
|
|
@Component
|
|
|
public class PayComponent {
|
|
public class PayComponent {
|
|
|
|
|
|
|
|
|
|
+ private ObjectMapper mapper = new ObjectMapper();
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private JXNXSPayConfig jxnxsPayConfig;
|
|
private JXNXSPayConfig jxnxsPayConfig;
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -83,41 +85,93 @@ public class PayComponent {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 退款
|
|
|
|
|
+ * @param orderNo 订单编号
|
|
|
|
|
+ * @param refundOrderNo 退款订单编号
|
|
|
|
|
+ * @param refundAmount 退款金额
|
|
|
|
|
+ */
|
|
|
|
|
+ public Map<String, String> payRefund(String orderNo, String refundOrderNo, Integer refundAmount) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ TreeMap<String, String> dataMap = new TreeMap<>(); // data参数的map
|
|
|
|
|
+ dataMap.put("out_no", orderNo);
|
|
|
|
|
+ dataMap.put("refund_out_no", refundOrderNo);
|
|
|
|
|
+ dataMap.put("refund_ord_name", "消费退款");
|
|
|
|
|
+ dataMap.put("refund_amount", refundAmount + "");
|
|
|
|
|
+// dataMap.put("remark", "");
|
|
|
|
|
+ dataMap.put("shop_pass", ""); // TODO shopPass
|
|
|
|
|
+
|
|
|
|
|
+ return doRequest("payrefund", dataMap);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RRException(BizCodeEnume.JXNXS_ORDER_QUERY_ERROR);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 支付结果查询
|
|
* 支付结果查询
|
|
|
* @param orderNo 订单编号
|
|
* @param orderNo 订单编号
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
public Map<String, String> queryOrderStatus(String orderNo) {
|
|
public Map<String, String> queryOrderStatus(String orderNo) {
|
|
|
try {
|
|
try {
|
|
|
|
|
+ Map<String, String> dataMap = new LinkedHashMap<>(); // data参数
|
|
|
|
|
+ dataMap.put("out_no", orderNo);
|
|
|
|
|
+ dataMap.put("ord_no", "");
|
|
|
|
|
+
|
|
|
|
|
+ return doRequest("paystatus", dataMap);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RRException(BizCodeEnume.JXNXS_ORDER_QUERY_ERROR);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发送请求
|
|
|
|
|
+ * @param uri
|
|
|
|
|
+ * @param dataMap 参数
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private Map<String, String> doRequest(String uri, Map<String, String> dataMap) {
|
|
|
|
|
+ try {
|
|
|
// 构建请求参数
|
|
// 构建请求参数
|
|
|
Map<String, String> postParam = new LinkedHashMap<>();
|
|
Map<String, String> postParam = new LinkedHashMap<>();
|
|
|
postParam.put("open_id", jxnxsPayConfig.getOpenId());
|
|
postParam.put("open_id", jxnxsPayConfig.getOpenId());
|
|
|
postParam.put("timestamp", new Date().getTime() / 1000 + "");
|
|
postParam.put("timestamp", new Date().getTime() / 1000 + "");
|
|
|
- Map<String, String> dataMap = new LinkedHashMap<>(); // data参数
|
|
|
|
|
- dataMap.put("out_no", orderNo);
|
|
|
|
|
- dataMap.put("ord_no", "");
|
|
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // data加密
|
|
|
String data = JXNXSPayUtil.handleEncrypt(mapper.writeValueAsString(dataMap), jxnxsPayConfig.getOpenKey());
|
|
String data = JXNXSPayUtil.handleEncrypt(mapper.writeValueAsString(dataMap), jxnxsPayConfig.getOpenKey());
|
|
|
postParam.put("data", data);
|
|
postParam.put("data", data);
|
|
|
postParam.put("open_key", jxnxsPayConfig.getOpenKey());
|
|
postParam.put("open_key", jxnxsPayConfig.getOpenKey());
|
|
|
String sign = JXNXSPayUtil.sign(postParam);
|
|
String sign = JXNXSPayUtil.sign(postParam);
|
|
|
postParam.put("sign", sign);
|
|
postParam.put("sign", sign);
|
|
|
|
|
|
|
|
- MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
|
|
|
|
|
- params.setAll(postParam);
|
|
|
|
|
|
|
+
|
|
|
// 发送请求
|
|
// 发送请求
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
MediaType type = MediaType.parseMediaType("application/x-www-form-urlencoded");
|
|
MediaType type = MediaType.parseMediaType("application/x-www-form-urlencoded");
|
|
|
headers.setContentType(type);
|
|
headers.setContentType(type);
|
|
|
|
|
|
|
|
|
|
+ MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
|
|
|
|
|
+ params.setAll(postParam);
|
|
|
HttpEntity<MultiValueMap<String,String>> formEntity = new HttpEntity<>(params, headers);
|
|
HttpEntity<MultiValueMap<String,String>> formEntity = new HttpEntity<>(params, headers);
|
|
|
|
|
|
|
|
RestTemplate client = new RestTemplate();
|
|
RestTemplate client = new RestTemplate();
|
|
|
- String url = "https://api.jxnxs.com/mct1/paystatus";
|
|
|
|
|
|
|
+ String url = "https://api.jxnxs.com/mct1/" + uri;
|
|
|
|
|
|
|
|
ResponseEntity<String> resp = client.postForEntity(url, formEntity, String.class);
|
|
ResponseEntity<String> resp = client.postForEntity(url, formEntity, String.class);
|
|
|
String body = resp.getBody();
|
|
String body = resp.getBody();
|
|
|
|
|
|
|
|
|
|
+ return analysisResult(body);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RRException(BizCodeEnume.JXNXS_ORDER_QUERY_ERROR, e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解析结果
|
|
|
|
|
+ * @param body
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private Map<String, String> analysisResult(String body) {
|
|
|
|
|
+ try {
|
|
|
Map<String, String> map = mapper.readValue(body, new TypeReference<HashMap<String, String>>() {});
|
|
Map<String, String> map = mapper.readValue(body, new TypeReference<HashMap<String, String>>() {});
|
|
|
if (JXNXSPayUtil.verifySign(map, jxnxsPayConfig.getOpenKey())) {
|
|
if (JXNXSPayUtil.verifySign(map, jxnxsPayConfig.getOpenKey())) {
|
|
|
// data 解密
|
|
// data 解密
|
|
@@ -127,7 +181,7 @@ public class PayComponent {
|
|
|
return map;
|
|
return map;
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- throw new RRException(BizCodeEnume.JXNXS_ORDER_QUERY_ERROR);
|
|
|
|
|
|
|
+ throw new RRException(BizCodeEnume.JXNXS_ORDER_QUERY_ERROR, "农商行返回结果解析失败");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|