From 5a88c770debe086dd82ab5ce8a4c957a3debdae7 Mon Sep 17 00:00:00 2001 From: “djh” <“3298565835@qq.com”> Date: 星期五, 24 一月 2025 17:07:09 +0800 Subject: [PATCH] 煤矿缴费修改 --- exam-system/src/main/java/com/gkhy/exam/pay/utils/PayUtils.java | 40 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 40 insertions(+), 0 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 36580a6..8c94e73 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 @@ -30,6 +30,7 @@ import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import javax.net.ssl.SSLContext; @@ -63,6 +64,15 @@ @Value("${finance.apiId}") private String appId; + @Value("${finance.queryUrl}") + private String queryUrl; + + /** + * 请求开票,发起支付 + * @param payReqData + * @return + * @throws IOException + */ public ResultVo sendApiPost(PayReqData payReqData) throws IOException { Map<String, String> param = new HashMap<>(); @@ -85,6 +95,7 @@ return resultVo; } + //组装请求体 private static UrlEncodedFormEntity assemblyFormEntity(Map<String, String> parameters, String charset) { List<NameValuePair> formParameters = assemblyParameter(parameters); UrlEncodedFormEntity formEntity = null; @@ -120,6 +131,7 @@ } + //在调用SSL之前需要重写验证方法,取消检测SSL 创建ConnectionManager,添加Connection配置信息 private static HttpClient sslClient() { try { // 在调用SSL之前需要重写验证方法,取消检测SSL @@ -162,6 +174,7 @@ } + //获取响应结果处理器,将响应结果封装为HttpResult对象 private static ResponseHandler<HttpResultVo> getResponseHandler() { ResponseHandler<HttpResultVo> responseHandler = new ResponseHandler<HttpResultVo>() { @Override @@ -202,6 +215,7 @@ return responseHandler; } + //判断相应内容是否为文本类型 private static boolean isTextType(ContentType contentType) { if (contentType == null) { throw new RuntimeException("ContentType is null"); @@ -297,4 +311,30 @@ log.info("请求结果json为:" + result); return result; } + + + //票据查询 + public ResponseEntity<String> findBill(String billNO) throws IOException { + Map<String, String> params = new HashMap<>(); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("billNo",billNO); + String reqdata = Base64.getEncoder().encodeToString(jsonObject.toJSONString().getBytes()); + String mac = appId+"||"+reqdata; + mac = DigestUtils.md5Hex(mac.getBytes()); + params.put("appid",appId); + params.put("reqdata",reqdata); + params.put("mac",mac); + + HttpPost httpPost = new HttpPost(queryUrl); + httpPost.setEntity(assemblyFormEntity(params,"utf-8")); + HttpClient httpClient = getHttpClient(queryUrl); + HttpResultVo execute = httpClient.execute(httpPost, getResponseHandler()); + String stringContent = execute.getStringContent(); + JSONObject jsonObject1 = JSONObject.parseObject(stringContent); + log.info("请求结果转json后为:"+jsonObject1); + String result = (String) jsonObject1.get("reqdata"); + return ResponseEntity.ok(result); + + } } -- Gitblit v1.9.2