From 75b742855cba8106732b561a015a87bd711963ed Mon Sep 17 00:00:00 2001
From: “djh” <“3298565835@qq.com”>
Date: Thu, 23 Jan 2025 17:02:16 +0800
Subject: [PATCH] 煤矿缴费个人缴费
---
exam-system/src/main/java/com/gkhy/exam/pay/utils/PayUtils.java | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 101 insertions(+), 16 deletions(-)
diff --git a/exam-system/src/main/java/com/gkhy/exam/pay/utils/PayUtils.java b/exam-system/src/main/java/com/gkhy/exam/pay/utils/PayUtils.java
index b994838..36580a6 100644
--- a/exam-system/src/main/java/com/gkhy/exam/pay/utils/PayUtils.java
+++ b/exam-system/src/main/java/com/gkhy/exam/pay/utils/PayUtils.java
@@ -2,6 +2,7 @@
import com.alibaba.fastjson2.JSONObject;
import com.gkhy.exam.pay.entity.PayReqData;
+import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@@ -28,6 +29,8 @@
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
@@ -42,30 +45,40 @@
/**
* 缴费相关接口
*/
+@Component
+@Slf4j
public class PayUtils {
- public static ResultVo sendApiPost(PayReqData payReqData) throws IOException {
+// private final static String appid = "ED76A5F1703540BE977D34780B371FEB";
- //正式
- String proUrl="http://finpt.xjcz.gov.cn/fs-service/fs-pay/invoice.do";
- String appid="ED76A5F1703540BE977D34780B371FEB";
- //测试
- String testUrl= "http://finpt.xjcz.gov.cn/fs-service-test/fs-pay/invoice.do";
+ @Value("${finance.orderUrl}")
+ private String orderUrl;
+
+ @Value("${finance.payNotifyUrl}")
+ private String payNotifyUrl;
+
+ @Value("${finance.payQueryUrl}")
+ private String payQueryUrl;
+
+ @Value("${finance.apiId}")
+ private String appId;
+
+ public ResultVo sendApiPost(PayReqData payReqData) throws IOException {
Map<String, String> param = new HashMap<>();
- HttpPost httpPost = new HttpPost(testUrl);
+ HttpPost httpPost = new HttpPost(orderUrl);
//请求参数转为json格式base64编码
String reqData = Base64.getEncoder().encodeToString(JSONObject.toJSONString(payReqData).getBytes());
- String mac = appid+"||"+reqData;
+ String mac = appId + "||" + reqData;
mac = DigestUtils.md5Hex(mac.getBytes());
- param.put("appid",appid);
- param.put("reqdata",reqData);
- param.put("mac",mac);
+ param.put("appid", appId);
+ param.put("reqdata", reqData);
+ param.put("mac", mac);
- httpPost.setEntity(assemblyFormEntity(param,"utf-8"));
- HttpClient httpClient = getHttpClient(testUrl);
+ httpPost.setEntity(assemblyFormEntity(param, "utf-8"));
+ HttpClient httpClient = getHttpClient(orderUrl);
HttpResultVo execute = httpClient.execute(httpPost, getResponseHandler());
String stringContent = execute.getStringContent();
ResultVo resultVo = JSONObject.parseObject(stringContent, ResultVo.class);
@@ -117,13 +130,15 @@
}
@Override
- public void checkClientTrusted(X509Certificate[] xcs, String str) {}
+ public void checkClientTrusted(X509Certificate[] xcs, String str) {
+ }
@Override
- public void checkServerTrusted(X509Certificate[] xcs, String str) {}
+ public void checkServerTrusted(X509Certificate[] xcs, String str) {
+ }
};
SSLContext ctx = SSLContext.getInstance(SSLConnectionSocketFactory.TLS);
- ctx.init(null, new TrustManager[] {trustManager}, null);
+ ctx.init(null, new TrustManager[]{trustManager}, null);
SSLConnectionSocketFactory socketFactory =
new SSLConnectionSocketFactory(ctx, NoopHostnameVerifier.INSTANCE);
// 创建Registry
@@ -209,7 +224,77 @@
}
+ //缴费结果通知
+ public Map<String, String> receive(JSONObject jsonObject) throws IOException {
+ Map<String, String> params = new HashMap<>();
+ JSONObject reqdata = new JSONObject();
+ Map<String, String> result = (Map<String, String>) jsonObject.get("reqdata");
+ String orderNo = result.get("orderNo");
+ //确认是否成功
+ String notarize = affirmPost(orderNo);
+ reqdata.put("orderNo", orderNo);
+ reqdata.put("status", notarize);
+
+ String req = Base64.getEncoder().encodeToString(reqdata.toJSONString().getBytes());
+ String mac = appId + "||" + req;
+ mac = DigestUtils.md5Hex(mac.getBytes());
+ params.put("appid", appId);
+ params.put("reqdata", req);
+ params.put("mac", mac);
+
+ return params;
+ }
+
+ //缴费结果确认查询
+ public String affirmPost(String orderNo) throws IOException {
+
+ HashMap<String, String> param = new HashMap<>();
+
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("orderNo", orderNo);
+ String reqdata = Base64.getEncoder().encodeToString(jsonObject.toJSONString().getBytes());
+ String mac = appId + "||" + reqdata;
+ mac = DigestUtils.md5Hex(mac.getBytes());
+ param.put("appid", appId);
+ param.put("reqdata", reqdata);
+ param.put("mac", mac);
+
+ HttpPost httppost = new HttpPost(payNotifyUrl);
+ httppost.setEntity(assemblyFormEntity(param, "utf-8"));
+ HttpClient httpClient = getHttpClient(payNotifyUrl);
+ HttpResultVo execute = httpClient.execute(httppost, getResponseHandler());
+ String stringContent = execute.getStringContent();
+ ResultVo resultVo = JSONObject.parseObject(stringContent, ResultVo.class);
+ log.info("请求结果为:" + resultVo);
+ if (resultVo.getRespcode().equals("BUS0000")) {
+ return "success";
+ }
+ return "fail";
+ }
+
+ //缴费结果查询
+ public JSONObject query(String orderNo) throws IOException {
+ HashMap<String, String> param = new HashMap<>();
+
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("orderNo", orderNo);
+ String reqdata = Base64.getEncoder().encodeToString(jsonObject.toJSONString().getBytes());
+ String mac = appId + "||" + reqdata;
+ mac = DigestUtils.md5Hex(mac.getBytes());
+ param.put("appid", appId);
+ param.put("reqdata", reqdata);
+ param.put("mac", mac);
+
+ HttpPost httppost = new HttpPost(payQueryUrl);
+ httppost.setEntity(assemblyFormEntity(param, "utf-8"));
+ HttpClient httpClient = getHttpClient(payQueryUrl);
+ HttpResultVo execute = httpClient.execute(httppost, getResponseHandler());
+ String stringContent = execute.getStringContent();
+ JSONObject result = JSONObject.parseObject(stringContent);
+ log.info("请求结果json为:" + result);
+ return result;
+ }
}
--
Gitblit v1.9.2