From 5cc9063aafa13e75d0fd918bd968c59f61525e2d Mon Sep 17 00:00:00 2001 From: “djh” <“3298565835@qq.com”> Date: 星期四, 23 一月 2025 14:01:59 +0800 Subject: [PATCH] 煤矿缴费 --- exam-system/src/main/java/com/gkhy/exam/pay/utils/PayUtils.java | 85 ++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 80 insertions(+), 5 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..135fade 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 @@ -3,10 +3,7 @@ import com.alibaba.fastjson2.JSONObject; import com.gkhy.exam.pay.entity.PayReqData; import org.apache.commons.codec.digest.DigestUtils; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.NameValuePair; -import org.apache.http.StatusLine; +import org.apache.http.*; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.HttpResponseException; @@ -29,6 +26,7 @@ import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; +import javax.annotation.Resource; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; @@ -44,11 +42,13 @@ */ public class PayUtils { + private final static String appid="ED76A5F1703540BE977D34780B371FEB"; + + public static ResultVo sendApiPost(PayReqData payReqData) throws IOException { //正式 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"; @@ -209,7 +209,82 @@ } + //缴费结果通知 + public static 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 static String affirmPost(String orderNo) throws IOException { + String porUrl="http://finpt.xjcz.gov.cn/fs-service/fs-pay/notifyConfirm.do"; + String testUrl="http://finpt.xjcz.gov.cn/fs-service-test/fs-pay/notifyConfirm.do"; + + 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(testUrl); + httppost.setEntity(assemblyFormEntity(param,"utf-8")); + HttpClient httpClient = getHttpClient(testUrl); + HttpResultVo execute = httpClient.execute(httppost, getResponseHandler()); + String stringContent = execute.getStringContent(); + ResultVo resultVo = JSONObject.parseObject(stringContent, ResultVo.class); + System.out.printf("请求结果为:"+resultVo); + if (resultVo.getRespcode().equals("BUS0000")){ + return "success"; + } + return "fail"; + } + + //缴费结果查询 + public static JSONObject query(String orderNo) throws IOException { + String proUrl="http://finpt.xjcz.gov.cn/fs-service/fs-pay/query.do"; + String testUrl="http://finpt.xjcz.gov.cn/fs-service-test/fs-pay/query.do"; + + 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(testUrl); + httppost.setEntity(assemblyFormEntity(param,"utf-8")); + HttpClient httpClient = getHttpClient(testUrl); + HttpResultVo execute = httpClient.execute(httppost, getResponseHandler()); + String stringContent = execute.getStringContent(); + JSONObject result = JSONObject.parseObject(stringContent); + System.out.printf("请求结果json为:"+result); + return result; + } } -- Gitblit v1.9.2