From dcf2c39ca10e6b7e91a7970cd784a5bf07a55207 Mon Sep 17 00:00:00 2001
From: heheng <heheng@123456>
Date: Tue, 18 Feb 2025 16:41:52 +0800
Subject: [PATCH] merge
---
exam-system/src/main/java/com/gkhy/exam/pay/service/impl/CoalPayServiceImpl.java | 163 ++++-------
exam-system/src/main/java/com/gkhy/exam/pay/service/CoalPayService.java | 12
exam-system/src/main/java/com/gkhy/exam/pay/utils/BillSignUtils.java | 137 ++++++++++
exam-system/src/main/java/com/gkhy/exam/pay/utils/DemoUtils.java | 178 ++++++++-----
exam-system/src/main/java/com/gkhy/exam/pay/entity/NonCoalPayStudent.java | 2
exam-system/src/main/resources/mapper/pay/CoalPayStudentMapper.xml | 48 ++-
exam-system/src/main/java/com/gkhy/exam/pay/entity/CoalPayStudent.java | 29 +
exam-system/src/main/java/com/gkhy/exam/pay/service/impl/NonCoalPayStudentServiceImpl.java | 20 +
exam-system/src/main/java/com/gkhy/exam/pay/service/PaymentService.java | 13 +
exam-system/src/main/java/com/gkhy/exam/pay/utils/SignCommond.java | 2
exam-system/src/main/java/com/gkhy/exam/pay/controller/PaymentApiController.java | 55 ++++
exam-system/src/main/java/com/gkhy/exam/pay/service/impl/PaymentServiceImpl.java | 63 ++++
12 files changed, 528 insertions(+), 194 deletions(-)
diff --git a/exam-system/src/main/java/com/gkhy/exam/pay/controller/PaymentApiController.java b/exam-system/src/main/java/com/gkhy/exam/pay/controller/PaymentApiController.java
new file mode 100644
index 0000000..6d93aab
--- /dev/null
+++ b/exam-system/src/main/java/com/gkhy/exam/pay/controller/PaymentApiController.java
@@ -0,0 +1,55 @@
+package com.gkhy.exam.pay.controller;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.gkhy.exam.pay.service.PaymentService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.Base64;
+import java.util.Map;
+
+@Api(tags = {"支付Api"})
+@RestController
+@RequestMapping({"/paymentApi"})
+@Slf4j
+public class PaymentApiController {
+
+ @Resource
+ private PaymentService paymentService;
+
+ @ApiOperation(value = "支付Api-回调", notes = "支付Api-回调")
+ @PostMapping({"/callBack"})
+ public JSONObject add(@RequestParam Map<String, Object> callBackParam) {
+ String jsonStr = baseToString(callBackParam.get("reqdata").toString());
+ JSONObject jsonObject = JSONObject.parseObject(jsonStr);
+ log.info("财政回调接收到参数=" + jsonObject.toString());
+ try {
+ JSONObject jsonObject1 = new JSONObject();
+ String orderNo = jsonObject.getString("orderNo");
+ String status = jsonObject.getString("status");
+ if ("1".equals(status)) {
+ paymentService.paySuccess(orderNo, jsonObject.getDate("payTime"));
+ }
+ jsonObject1.put("orderNo", orderNo);
+ jsonObject1.put("status", Boolean.TRUE);
+ return jsonObject1;
+ } catch (Exception e) {
+ log.info("财政回调处理订单发生错误");
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+
+ public String baseToString(String baseString) {
+ byte[] byteArray = Base64.getDecoder().decode(baseString);
+ String decodedString = new String(byteArray);
+ return decodedString;
+ }
+}
diff --git a/exam-system/src/main/java/com/gkhy/exam/pay/entity/CoalPayStudent.java b/exam-system/src/main/java/com/gkhy/exam/pay/entity/CoalPayStudent.java
index 394e699..30365e4 100644
--- a/exam-system/src/main/java/com/gkhy/exam/pay/entity/CoalPayStudent.java
+++ b/exam-system/src/main/java/com/gkhy/exam/pay/entity/CoalPayStudent.java
@@ -5,7 +5,6 @@
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
-import com.ruoyi.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@@ -101,19 +100,31 @@
private Integer govPayStatus;
- /** 创建者 */
+ /**
+ * 创建者
+ */
private String createBy;
- /** 创建时间 */
+ /**
+ * 创建时间
+ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
- /** 更新者 */
+ /**
+ * 更新者
+ */
private String updateBy;
- /** 更新时间 */
+ /**
+ * 更新时间
+ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
+
+ @ApiModelProperty("缴费时间")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private Date payTime;
/**
* 删除标志(0代表存在2代表删除)
@@ -263,4 +274,12 @@
public void setOrderNo(String orderNo) {
this.orderNo = orderNo;
}
+
+ public Date getPayTime() {
+ return payTime;
+ }
+
+ public void setPayTime(Date payTime) {
+ this.payTime = payTime;
+ }
}
diff --git a/exam-system/src/main/java/com/gkhy/exam/pay/entity/NonCoalPayStudent.java b/exam-system/src/main/java/com/gkhy/exam/pay/entity/NonCoalPayStudent.java
index 9500fad..2f0188b 100644
--- a/exam-system/src/main/java/com/gkhy/exam/pay/entity/NonCoalPayStudent.java
+++ b/exam-system/src/main/java/com/gkhy/exam/pay/entity/NonCoalPayStudent.java
@@ -104,7 +104,7 @@
/**
* 财政订单状态0未生成1生成中2未生成
*/
- @ApiModelProperty("财政订单状态0未生成1生成中2未生成")
+ @ApiModelProperty("财政订单状态0未生成1生成中2已生成")
private Integer govPayStatus;
/**
* 删除标志(0代表存在2代表删除)
diff --git a/exam-system/src/main/java/com/gkhy/exam/pay/service/CoalPayService.java b/exam-system/src/main/java/com/gkhy/exam/pay/service/CoalPayService.java
index 1015cf4..0bde276 100644
--- a/exam-system/src/main/java/com/gkhy/exam/pay/service/CoalPayService.java
+++ b/exam-system/src/main/java/com/gkhy/exam/pay/service/CoalPayService.java
@@ -1,12 +1,14 @@
package com.gkhy.exam.pay.service;
-import cn.com.jit.new_vstk.Bean.SignResult;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gkhy.exam.pay.dto.rep.CoalPayRepDto;
import com.gkhy.exam.pay.dto.rep.CoalPayStudentRep;
-import com.gkhy.exam.pay.dto.req.*;
+import com.gkhy.exam.pay.dto.req.CoalPayDto;
+import com.gkhy.exam.pay.dto.req.CoalPayReq;
+import com.gkhy.exam.pay.dto.req.CoalPayTypeReq;
+import com.gkhy.exam.pay.dto.req.CoalTeamPayReq;
import com.gkhy.exam.pay.entity.CoalPay;
-import com.gkhy.exam.pay.entity.CoalPayStudent;
+import com.gkhy.exam.pay.utils.BillSignException;
import com.gkhy.exam.pay.utils.ResultVo;
import com.ruoyi.common.core.domain.AjaxResult;
@@ -24,7 +26,7 @@
AjaxResult deleteCoalPayByIds(Long[] ids);
- List<CoalPayStudentRep> selectCoalPay(String idcard,String phone);
+ List<CoalPayStudentRep> selectCoalPay(String idcard, String phone);
int updateCoalPayType(CoalPayTypeReq coalPayDto);
@@ -32,5 +34,5 @@
String teamPayMoney(CoalTeamPayReq coalTeamPayReq);
- ResultVo topay() throws IOException, BillSignException;
+ ResultVo topay() throws IOException, BillSignException, BillSignException;
}
diff --git a/exam-system/src/main/java/com/gkhy/exam/pay/service/PaymentService.java b/exam-system/src/main/java/com/gkhy/exam/pay/service/PaymentService.java
new file mode 100644
index 0000000..a2b1c85
--- /dev/null
+++ b/exam-system/src/main/java/com/gkhy/exam/pay/service/PaymentService.java
@@ -0,0 +1,13 @@
+package com.gkhy.exam.pay.service;
+
+import java.util.Date;
+
+/**
+ * @author admin
+ */
+public interface PaymentService {
+
+ void notifyConfirm(String orderNo);
+
+ void paySuccess(String orderNo, Date payTime);
+}
diff --git a/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/CoalPayServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/CoalPayServiceImpl.java
index bfd4605..86d86f7 100644
--- a/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/CoalPayServiceImpl.java
+++ b/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/CoalPayServiceImpl.java
@@ -1,7 +1,5 @@
package com.gkhy.exam.pay.service.impl;
-import cn.com.jit.mof.bean.MOFVerifyResult;
-import cn.com.jit.new_vstk.Bean.EnvelopResult;
import cn.com.jit.new_vstk.Bean.SignResult;
import cn.com.jit.new_vstk.Bean.VerifyResult;
import com.alibaba.fastjson2.JSONObject;
@@ -15,14 +13,16 @@
import com.gkhy.exam.pay.mapper.CoalPayMapper;
import com.gkhy.exam.pay.service.CoalPayService;
import com.gkhy.exam.pay.service.CoalPayStudentService;
-import com.gkhy.exam.pay.utils.*;
+import com.gkhy.exam.pay.utils.PayUtils;
+import com.gkhy.exam.pay.utils.ResultVo;
+import com.gkhy.exam.pay.utils.Sign;
+import com.gkhy.exam.pay.utils.SignDto;
import com.ruoyi.common.constant.ResultConstants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.RandomUtil;
import com.ruoyi.common.utils.SecurityUtils;
-import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.SysDeptMapper;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.Document;
@@ -37,17 +37,15 @@
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.Date;
+import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
-
-import static com.gkhy.exam.pay.utils.DemoUtils.generateBase64StringToFile;
@Service
@Slf4j
@@ -94,7 +92,7 @@
//学员数据
List<CoalPayStudent> coalPayStudents = coalPayStudentService.selectByCoalPayId(pay.getId());
List<CoalPayStudent> havePay = coalPayStudents.stream()
- .filter(stu -> stu.getPayStatus() != null && stu.getPayStatus()==1)
+ .filter(stu -> stu.getPayStatus() != null && stu.getPayStatus() == 1)
.collect(Collectors.toList());
coalPayRepDto.setTotalNum(coalPayStudents.size());
coalPayRepDto.setHavePayNum(havePay.size());
@@ -230,7 +228,7 @@
throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "已为团体缴费,不可更改");
}
int i = coalPayMapper.updateByPayId(coalPayTypeReq);
- if (i>0){
+ if (i > 0) {
CoalPayStudent coalPayStudent = new CoalPayStudent();
coalPayStudent.setCoalPayId(coalPayTypeReq.getCoalPayId());
coalPayStudent.setPayType(2);
@@ -252,20 +250,17 @@
CoalPay coalPay = coalPayMapper.selectById(coalPayId);
List<CoalCategory> coalCategories = coalCategoryMapper.selectByCoalPayId(coalPayId);
CoalTicket coalTicket = coalCategoryMapper.selectCoalTicket();
- if (CollectionUtils.isEmpty(coalPayStudent)){
- throw new BusinessException(this.getClass(),ResultConstants.BUSINESS_ERROR,"缴费学员不存在");
+ if (CollectionUtils.isEmpty(coalPayStudent)) {
+ throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "缴费学员不存在");
}
- if (coalPay==null){
- throw new BusinessException(this.getClass(),ResultConstants.BUSINESS_ERROR,"未找到相关缴费信息");
+ if (coalPay == null) {
+ throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "未找到相关缴费信息");
}
- if (student.getPayStatus()==1){
- throw new BusinessException(this.getClass(),ResultConstants.BUSINESS_ERROR,"请勿重新缴费");
- }
- if (student.getGovPayStatus() == 2){
- return student.getOrderId();
+ if (student.getPayStatus() == 1) {
+ throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "请勿重新缴费");
}
- PayReqData payReqData = fillData(coalPayStudent,coalPay,coalCategories,coalTicket,1,null);
+ PayReqData payReqData = fillData(coalPayStudent, coalPay, coalCategories, coalTicket, 1, null);
ResultVo resultVo = payUtils.sendApiPost(payReqData);
if (resultVo.getRespcode().equals("BUS0000")) {
@@ -275,9 +270,8 @@
// throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "签名验证错误");
// }
payStudent.setId(studentId);
- payStudent.setOrderId(resultVo.getRespdata().getOrderId());
- payStudent.setOrderNo(resultVo.getRespdata().getOrderNo());
- payStudent.setGovPayStatus(2);
+ payStudent.setOrderId(resultVo.getRespdata().getOrderNo());
+ payStudent.setGovPayStatus(1);
payStudent.setPayCode(resultVo.getRespdata().getBillNo());
coalPayStudentService.updateByCoalPayStudent(payStudent);
return resultVo.getRespdata().getOrderId();
@@ -299,35 +293,34 @@
public String teamPayMoney(CoalTeamPayReq coalTeamPayReq) {
RLock lock = redissonClient.getLock("SWSPKMAS_TEAM_PAY_" + coalTeamPayReq.getCoalPayId());
try {
- lock.lock(10,TimeUnit.SECONDS);
+ lock.lock(10, TimeUnit.SECONDS);
List<CoalPayStudent> coalPayStudents = coalPayStudentService.selectByCoalPayIdAndPayStatus(coalTeamPayReq.getCoalPayId(), 0);
CoalPay coalPay = coalPayMapper.selectById(coalTeamPayReq.getCoalPayId());
List<CoalCategory> coalCategories = coalCategoryMapper.selectByCoalPayId(coalTeamPayReq.getCoalPayId());
CoalTicket coalTicket = coalCategoryMapper.selectCoalTicket();
- if (CollectionUtils.isEmpty(coalPayStudents)){
- throw new BusinessException(this.getClass(),ResultConstants.BUSINESS_ERROR,"缴费学员不存在");
+ if (CollectionUtils.isEmpty(coalPayStudents)) {
+ throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "缴费学员不存在");
}
- if (coalPay==null){
- throw new BusinessException(this.getClass(),ResultConstants.BUSINESS_ERROR,"未找到相关缴费信息");
+ if (coalPay == null) {
+ throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "未找到相关缴费信息");
}
CoalPayStudent payStudent = new CoalPayStudent();
- PayReqData payReqData = fillData(coalPayStudents, coalPay, coalCategories, coalTicket,2,coalTeamPayReq);
+ PayReqData payReqData = fillData(coalPayStudents, coalPay, coalCategories, coalTicket, 2, coalTeamPayReq);
ResultVo resultVo = payUtils.sendApiPost(payReqData);
if (resultVo.getRespcode().equals("BUS0000")) {
payStudent.setCoalPayId(coalPay.getId());
- payStudent.setOrderId(resultVo.getRespdata().getOrderId());
- payStudent.setOrderNo(resultVo.getRespdata().getOrderNo());
- payStudent.setGovPayStatus(2);
+ payStudent.setOrderId(resultVo.getRespdata().getOrderNo());
+ payStudent.setGovPayStatus(1);
payStudent.setPayCode(resultVo.getRespdata().getBillNo());
coalPayStudentService.updateByCoalPayIdAndStatus(payStudent);
return resultVo.getRespdata().getOrderId();
} else {
throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "发起支付失败,请稍后重试");
}
- }catch (Exception e){
+ } catch (Exception e) {
throw new RuntimeException(e);
- }finally {
+ } finally {
if (lock.isLocked()) {
lock.unlock();
}
@@ -335,86 +328,56 @@
}
@Override
- public ResultVo topay() throws IOException, BillSignException {
+ public ResultVo topay() throws IOException {
PayReqData payReqData = new PayReqData();
PayReqData.Feedata feedatas = new PayReqData.Feedata();
//订单编号
- payReqData.setOrderNo("CO202502180328549421");
+ payReqData.setOrderNo("NC202502170905105061");
//订单总金额
- payReqData.setMoney(BigDecimal.valueOf(159));
+ payReqData.setMoney(BigDecimal.valueOf(112));
//子订单数目
- payReqData.setAmount(2);
+ payReqData.setAmount(1);
//缴费人姓名(单位填单位名称)阿克苏地区博安煤矿安全技术服务中心
- payReqData.setPayerName("闵强明");
+ payReqData.setPayerName("阿克苏地区博安煤矿安全技术服务中心");
//缴费人证件号(单位填同一信用代码)52652900789893140A
- payReqData.setCertNo("321023197209184616");
+ payReqData.setCertNo("52652900789893140A");
//缴款人类型(1个人 2单位)
- payReqData.setPayerType(1);
+ payReqData.setPayerType(2);
//开票单位社会信用代码12650000MB1A9612XD
- payReqData.setInvoiceSocialCode("65000023000000172848");
+ payReqData.setInvoiceSocialCode("11650000MB1957293J");
//开票人
- payReqData.setHandlingPerson("张三");
+ payReqData.setHandlingPerson("姜倩");
//复核人
- payReqData.setChecker("李四");
+ payReqData.setChecker("薄晓洁");
//单位编码547185129
payReqData.setEnterCode("547185129");
//订单描述(非必填)
- payReqData.setDesc("单位业务");
+ payReqData.setDesc("非煤安全作业理论考试-002002");
//订单明细
List<PayReqData.Feedata> feedatas1 = new ArrayList<>();
//数量
- feedatas.setAmount(1);
- //业务代码
- feedatas.setBusCode("DZ011573");
- //单价
- feedatas.setPrice(BigDecimal.valueOf(56));
+// feedatas.setAmount(1);
+// //业务代码
+// feedatas.setBusCode("DZ12401");
+// //单价
+// feedatas.setPrice(BigDecimal.valueOf(56));
PayReqData.Feedata feedata = new PayReqData.Feedata();
- feedata.setBusCode("DZ011574");
- feedata.setAmount(1);
- feedata.setPrice(BigDecimal.valueOf(103));
- feedatas1.add(feedatas);
+ feedata.setBusCode("DZ002002");
+ feedata.setAmount(2);
+ feedata.setPrice(BigDecimal.valueOf(112));
+// feedatas1.add(feedatas);
feedatas1.add(feedata);
payReqData.setFeeDatas(feedatas1);
- log.info("请求参数:"+ JSONObject.toJSONString(payReqData));
+ log.info("请求参数:" + JSONObject.toJSONString(payReqData));
PayUtils payUtils = new PayUtils();
ResultVo resultVo = payUtils.sendApiPost(payReqData);
-
String fileData = resultVo.getRespdata().getFileData();
-// String orderNo = resultVo.getRespdata().getOrderNo();
-// String xmlFilePath = "F:\\text/" + orderNo + ".xml";
-// generateBase64StringToFile(fileData, xmlFilePath);
-// String trr2 = "";
-// try {
-// File file2 = new File(xmlFilePath);
-// FileReader reader1 = new FileReader(file2);
-// BufferedReader bReader = new BufferedReader(reader1);
-// StringBuilder sb = new StringBuilder();
-// String s = "";
-// while ((s = bReader.readLine()) != null) {
-// sb.append(s);
-// }
-// bReader.close();
-// trr2 = sb.toString();
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// log.info("拼接原文为trr2:"+trr2);
-//
-// BillSign billSign = new BillSign();
-// String signData="";
-// try {
-// signData = billSign.signBill(trr2);
-// } catch (BillSignException e) {
-// throw new RuntimeException(e);
-// } catch (Exception e) {
-// throw new RuntimeException(e);
-// }
//票据原文转为byte字节文件
- byte[] decode = Base64.getDecoder().decode(fileData);
+ byte[] decode = Base64.getDecoder().decode(fileData);
//byte字节文件转为xml字符串
String xmlString = new String(decode, StandardCharsets.UTF_8);
Document document = null;
@@ -423,27 +386,25 @@
} catch (DocumentException e) {
throw new RuntimeException(e);
}
- log.info("票据原文为:"+document.asXML());
- BillSign billSign = new BillSign();
- String s = billSign.readRefSignDto(document);
+ log.info("票据原文为:" + document.asXML());
Element rootElement = document.getRootElement();
- SignResult sign = payUtils.sign(s);
- MOFVerifyResult verify = payUtils.verify(sign.getSignData(),s);
- SignDto signDto = new SignDto(verify.getSignTime(), new String(Base64.getEncoder().encode(sign.getSignData())), verify.getIssure(),verify.getSn());
- log.info("拼接对象为:"+JSONObject.toJSONString(signDto));
+ SignResult sign = payUtils.sign(decode);
+ VerifyResult verify = payUtils.verify(decode, sign.getSignData());
+ SignDto signDto = new SignDto(new Date(), verify.getSubjectdn(), verify.getSn(), verify.getIssure());
+ log.info("拼接对象为:" + JSONObject.toJSONString(signDto));
Sign sign1 = new Sign();
Document signature = sign1.getSignature(signDto);
// Element rootElement1 = signature.getRootElement();
- log.info("拼接结果为:"+signature.asXML());
+ log.info("拼接结果为:" + signature.asXML());
rootElement.add(signature.getRootElement());
// EnvelopResult envelopResult = payUtils.encryptEnvelop(document.asXML().getBytes());
// log.info("制作数字信封为:"+ Arrays.toString(envelopResult.getEnvelopData()));
- log.info("签名后票据为:"+document.asXML());
- ResultVo resultVo1 = payUtils.uploadXml(resultVo.getRespdata().getOrderNo(), document.asXML());
+ log.info("签名后票据为:" + document.asXML());
+ ResultVo resultVo1 = payUtils.uploadXml(resultVo.getRespdata().getOrderNo(), document.asXML().getBytes());
return resultVo1;
}
- private PayReqData fillData(List<CoalPayStudent> coalPayStudent, CoalPay coalPay, List<CoalCategory> coalCategories, CoalTicket coalTicket,Integer payType,CoalTeamPayReq coalTeamPayReq) {
+ private PayReqData fillData(List<CoalPayStudent> coalPayStudent, CoalPay coalPay, List<CoalCategory> coalCategories, CoalTicket coalTicket, Integer payType, CoalTeamPayReq coalTeamPayReq) {
PayReqData payReqData = new PayReqData();
payReqData.setOrderNo(RandomUtil.generateOrderNumber(coalPay.getId(), "CO"));
payReqData.setMoney(coalPay.getAmount().multiply(BigDecimal.valueOf(coalPayStudent.size())));
@@ -465,11 +426,11 @@
}
payReqData.setFeeDatas(feedatas);
- if (1==payType){
+ if (1 == payType) {
payReqData.setPayerName(coalPayStudent.get(0).getName());
payReqData.setCertNo(coalPayStudent.get(0).getIdCard());
payReqData.setPayerType(1);
- }else if (2==payType){
+ } else if (2 == payType) {
payReqData.setPayerName(coalTeamPayReq.getPayCompanyName());
payReqData.setCertNo(coalTeamPayReq.getPayCompanyCard());
payReqData.setPayerType(2);
diff --git a/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/NonCoalPayStudentServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/NonCoalPayStudentServiceImpl.java
index c6df39a..6703e96 100644
--- a/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/NonCoalPayStudentServiceImpl.java
+++ b/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/NonCoalPayStudentServiceImpl.java
@@ -1,5 +1,6 @@
package com.gkhy.exam.pay.service.impl;
+import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -174,6 +175,25 @@
if (nonCoalStuRep.getPayStatus() == 1) {
throw new BusinessException(this.getClass(), ResultConstants.BUSINESS_ERROR, "已缴费请勿重复缴费");
}
+ if (nonCoalStuRep.getGovPayStatus() == 2 && nonCoalStuRep.getPayStatus() == 0) {
+ try {
+ JSONObject result = payUtils.query(nonCoalStuRep.getOrderNo());
+ String status = result.getString("status");
+ if (("1").equals(status)) {
+
+ nonCoalPayStudentMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate()
+ .set(NonCoalPayStudent::getPayStatus, 1)
+ .set(NonCoalPayStudent::getPayTime, result.getDate("payTime"))
+ .eq(NonCoalPayStudent::getOrderNo, nonCoalStuRep.getOrderNo()).eq(NonCoalPayStudent::getDelFlag, 0)
+ .eq(NonCoalPayStudent::getPayStatus, 0));
+ } else if (status == null) {
+ log.error("查询财政订单失败:" + result.getString("respmsg") + ",错误编码:" + result.getString("respcode"));
+ }
+ } catch (Exception e) {
+ log.error("查询财政订单失败:" + e.getMessage());
+
+ }
+ }
return nonCoalStuRep;
}
diff --git a/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/PaymentServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/PaymentServiceImpl.java
new file mode 100644
index 0000000..bbe9588
--- /dev/null
+++ b/exam-system/src/main/java/com/gkhy/exam/pay/service/impl/PaymentServiceImpl.java
@@ -0,0 +1,63 @@
+package com.gkhy.exam.pay.service.impl;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.gkhy.exam.pay.entity.CoalPayStudent;
+import com.gkhy.exam.pay.entity.NonCoalPayStudent;
+import com.gkhy.exam.pay.mapper.CoalPayStudentMapper;
+import com.gkhy.exam.pay.mapper.NonCoalPayStudentMapper;
+import com.gkhy.exam.pay.service.PaymentService;
+import com.gkhy.exam.pay.utils.PayUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Date;
+
+@Service
+@Slf4j
+public class PaymentServiceImpl implements PaymentService {
+
+ @Autowired
+ private PayUtils payUtils;
+ @Resource
+ private NonCoalPayStudentMapper nonCoalPayStudentMapper;
+ @Resource
+ private CoalPayStudentMapper coalPayStudentMapper;
+
+ @Override
+ public void notifyConfirm(String orderNo) {
+ try {
+ String resultStr1 = payUtils.affirmPost(orderNo);
+ JSONObject result1 = JSONObject.parseObject(resultStr1);
+ log.info("通知确定回参===" + result1);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ @Override
+ public void paySuccess(String orderNo, Date payTime) {
+
+ if (orderNo.startsWith("NC")) {
+ //非煤
+ nonCoalPayStudentMapper.update(null, Wrappers.<NonCoalPayStudent>lambdaUpdate()
+ .set(NonCoalPayStudent::getPayStatus, 1)
+ .set(NonCoalPayStudent::getPayTime, payTime)
+ .eq(NonCoalPayStudent::getOrderNo, orderNo).eq(NonCoalPayStudent::getDelFlag, 0)
+ .eq(NonCoalPayStudent::getPayStatus, 0));
+ } else {
+ coalPayStudentMapper.update(null, Wrappers.<CoalPayStudent>lambdaUpdate()
+ .set(CoalPayStudent::getPayStatus, 1)
+ .set(CoalPayStudent::getPayTime, payTime)
+ .eq(CoalPayStudent::getOrderNo, orderNo).eq(CoalPayStudent::getDelFlag, 0)
+ .eq(CoalPayStudent::getPayStatus, 0));
+ }
+ notifyConfirm(orderNo);
+
+ }
+
+
+}
diff --git a/exam-system/src/main/java/com/gkhy/exam/pay/utils/BillSignUtils.java b/exam-system/src/main/java/com/gkhy/exam/pay/utils/BillSignUtils.java
new file mode 100644
index 0000000..a8b9c9c
--- /dev/null
+++ b/exam-system/src/main/java/com/gkhy/exam/pay/utils/BillSignUtils.java
@@ -0,0 +1,137 @@
+package com.gkhy.exam.pay.utils;
+
+import com.alibaba.fastjson2.JSONObject;
+import org.dom4j.*;
+
+public class BillSignUtils {
+
+ private static final String HEADER_TAG = "Header";
+ private static final String EINVOICE_TAG = "EInvoiceData";
+
+
+// public static String signBill(byte[] bytes) throws BillSignException {
+// /* 41 */
+// return signBill(new String(bytes));
+//
+// }
+//
+//
+// public static String signBill(File file) throws BillSignException {
+// /* 54 */
+// if (!file.exists()) {
+// /* 55 */
+// throw new BillSignException("文件不存在。文件名称" + file.getAbsolutePath());
+//
+// }
+//
+//
+// try {
+// /* 59 */
+// byte[] bytes = FileUtils.readFileToByteArray(file);
+// /* 60 */
+// return signBill(new String(bytes));
+// /* 61 */
+// } catch (IOException e) {
+// /* 62 */
+// throw new BillSignException("文件读取失败。文件名称" + file.getAbsolutePath(), e);
+//
+// }
+//
+// }
+
+
+ public static String signBill(String xml, JSONObject data) throws BillSignException {
+ /* 78 */
+ Document xmlDoc = null;
+
+ try {
+ /* 80 */
+ xmlDoc = DocumentHelper.parseText(xml);
+ /* 81 */
+ } catch (DocumentException e) {
+ /* 82 */
+ throw new BillSignException("解析票据文件失败。", e);
+
+ }
+
+
+ /* 86 */
+ String plain = readRefSignDto(xmlDoc);
+
+
+ /* 89 */
+ Node signNode = genUnitSignNode(plain, data);
+
+
+ /* 92 */
+ addUnitSign(xmlDoc, signNode);
+
+ /* 94 */
+ return xmlDoc.asXML();
+
+ }
+
+
+ private static Node genUnitSignNode(String plain, JSONObject data) {
+ /* 100 */
+ SignDto signDto = new SignDto(data.getDate("signTime"), data.getString("signResult"), data.getString("issure"), data.getString("sn"));
+
+ /* 102 */
+ Document document = DocumentHelper.createDocument();
+ /* 103 */
+ Element signature = document.addElement("Signature");
+ /* 104 */
+ signature.addAttribute("id", "InvoicingParty");
+
+ /* 106 */
+ Element signedInfo = signature.addElement("SignedInfo");
+ /* 107 */
+ signedInfo.addElement("Reference").addAttribute("URI", "/EInvoice/Header|/EInvoice/EInvoiceData");
+ /* 108 */
+ signedInfo.addElement("SignatureAlgorithm").setText(signDto.getSignatureAlgorithm());
+ /* 109 */
+ signedInfo.addElement("SignatureFormat").setText(signDto.getSignatureFormat());
+
+ /* 111 */
+ signature.addElement("SignatureTime").setText(signDto.getSignatureTime());
+ /* 112 */
+ signature.addElement("SignatureValue").setText(signDto.getSignatureValue());
+
+ /* 114 */
+ Element keyInfo = signature.addElement("KeyInfo");
+ /* 115 */
+ keyInfo.addElement("SerialNumber").setText(signDto.getSerialNumber());
+ /* 116 */
+ keyInfo.addElement("X509IssuerName").setText(signDto.getIssuerDn());
+ /* 117 */
+ return (Node) signature;
+
+ }
+
+
+ private static String readRefSignDto(Document xmlDoc) throws BillSignException {
+ /* 130 */
+ Element root = xmlDoc.getRootElement();
+ /* 131 */
+ if (root.element("Header") == null || root.element("EInvoiceData") == null) {
+ /* 132 */
+ throw new BillSignException("票据文件格式不正确");
+
+ }
+ /* 134 */
+ return root.element("Header").asXML() + root.element("EInvoiceData").asXML();
+
+ }
+
+
+ private static void addUnitSign(Document xmlDoc, Node signNode) {
+ /* 146 */
+ Element eInvoiceSignature = xmlDoc.getRootElement().addElement("EInvoiceSignature");
+ /* 147 */
+ eInvoiceSignature.add(signNode);
+
+ }
+
+}
+
+
diff --git a/exam-system/src/main/java/com/gkhy/exam/pay/utils/DemoUtils.java b/exam-system/src/main/java/com/gkhy/exam/pay/utils/DemoUtils.java
index 66612af..aac0545 100644
--- a/exam-system/src/main/java/com/gkhy/exam/pay/utils/DemoUtils.java
+++ b/exam-system/src/main/java/com/gkhy/exam/pay/utils/DemoUtils.java
@@ -1,12 +1,18 @@
package com.gkhy.exam.pay.utils;
+import cn.com.jit.mof.MOFClient;
+import cn.com.jit.mof.bean.MOFSignResult;
+import cn.com.jit.mof.bean.MOFVerifyResult;
+import cn.com.jit.new_vstk.exception.NewCSSException;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
+import com.gkhy.exam.pay.entity.PayReqData;
import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Encoder;
import java.io.*;
import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
@@ -72,7 +78,7 @@
e.printStackTrace();
}
- String jmsignfile = signFilejdnew(trr2);
+ String jmsignfile = signFilejdnew(trr2, null);
String zuizhongpath = montageXmlV3(xmlFilePath, jmsignfile);
String zzsignfile = convertFileToBase64(zuizhongpath);
@@ -82,6 +88,44 @@
File file1 = new File(zuizhongpath);
file1.delete();
return result;
+ }
+
+
+ public void faqiV3(PayReqData payReqData) throws Exception {
+
+ PayUtils payUtils = new PayUtils();
+ ResultVo resultVo = payUtils.sendApiPost(payReqData);
+ String fileData = resultVo.getRespdata().getFileData();
+ String orderNo = resultVo.getRespdata().getOrderNo();
+
+ String xmlFilePath = "D:/files/" + orderNo + ".xml";
+ generateBase64StringToFile(fileData, xmlFilePath);
+ String trr2 = "";
+ try {
+ File file2 = new File(xmlFilePath);
+ FileReader reader1 = new FileReader(file2);
+ BufferedReader bReader = new BufferedReader(reader1);
+ StringBuilder sb = new StringBuilder();
+ String s = "";
+ while ((s = bReader.readLine()) != null) {
+ sb.append(s);
+ }
+ bReader.close();
+ trr2 = sb.toString();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ JSONObject jsonObject = signFileV2(fileData);
+ String jmsignfile = signFilejdnew(trr2, jsonObject);
+ String zuizhongpath = montageXmlV3(xmlFilePath, jmsignfile);
+ String zzsignfile = convertFileToBase64(zuizhongpath);
+
+ uploadXml(orderNo, zzsignfile);
+ File file = new File(xmlFilePath);
+ file.delete();
+ File file1 = new File(zuizhongpath);
+ file1.delete();
+
}
public String getMD5(String input) {
@@ -129,11 +173,11 @@
}
}
- public String signFilejdnew(String plain) {
- BillSign sign = new BillSign((ISignCommond) new Object());
+ public String signFilejdnew(String plain, JSONObject job) {
+
try {
- String xx = sign.signBill(plain);
- return xx;
+ String s = BillSignUtils.signBill(plain, job);
+ return s;
} catch (BillSignException e) {
e.printStackTrace();
return null;
@@ -159,68 +203,68 @@
return null;
}
-// public JSONObject signFileV2(JSONObject job) throws Exception {
-// JSONObject xysfResult = new JSONObject();
-// String certId = "11650000MB1957293J";
-// String plain = job.getString("data").trim();
-// MOFSignResult result = null;
-// Map<String, Object> mmp = new HashMap<>();
-//
-// try {
-// String filePath = "F:/cssconfig.properties";
-// System.out.println("配置文件路径:" + filePath);
-//
-// MOFClient client = new MOFClient(filePath);
-// System.out.println("证书标识为:" + certId);
-// System.out.println("待签名数据:" + plain);
-//
-//
-// result = client.sign(certId, plain.getBytes(StandardCharsets.UTF_8));
-// /* 323 */
-// System.out.println("签名返回结果:" + JSONObject.toJSONString(result));
-//
-// /* 325 */
-// byte[] signData = result.getSignData();
-//
-// /* 327 */
-// String base64Str = new String(Base64.encode(signData));
-// /* 328 */
-// mmp.put("signResult", base64Str);
-//
-// /* 330 */
-// MOFVerifyResult resultVer = client.verifySign(signData, plain.getBytes(StandardCharsets.UTF_8));
-// /* 331 */
-// System.out.println("验签结果为:" + JSONObject.toJSONString(resultVer));
-//
-// /* 333 */
-// mmp.put("issure", resultVer.getIssure());
-// /* 334 */
-// mmp.put("sn", resultVer.getSn());
-// /* 335 */
-// mmp.put("signTime", resultVer.getSignTime());
-//
-// /* 337 */
-// xysfResult.put("success", Boolean.valueOf(true));
-// /* 338 */
-// xysfResult.put("content", mmp);
-// /* 339 */
-// return xysfResult;
-// }
-// /* 341 */ catch (NewCSSException e) {
-// /* 342 */
-// System.out.println("****签名失败****");
-// /* 343 */
-// System.out.println("错误号为:" + e.getCode());
-// /* 344 */
-// System.out.println("错误描述为:" + e.getDescription());
-// /* 345 */
-// xysfResult.put("success", Boolean.valueOf(false));
-// /* 346 */
-// xysfResult.put("msg", "系统错误");
-// /* 347 */
-// return xysfResult;
-// }
-// }
+ public JSONObject signFileV2(String plain) throws Exception {
+ JSONObject xysfResult = new JSONObject();
+ String certId = "11650000MB1957293J";
+
+ MOFSignResult result = null;
+ Map<String, Object> mmp = new HashMap<>();
+
+ try {
+ String filePath = "F:/cssconfig.properties";
+ System.out.println("配置文件路径:" + filePath);
+
+ MOFClient client = new MOFClient(filePath);
+ System.out.println("证书标识为:" + certId);
+ System.out.println("待签名数据:" + plain);
+
+
+ result = client.sign(certId, plain.getBytes(StandardCharsets.UTF_8));
+ /* 323 */
+ System.out.println("签名返回结果:" + JSONObject.toJSONString(result));
+
+ /* 325 */
+ byte[] signData = result.getSignData();
+
+ /* 327 */
+ String base64Str = new String(Base64.decodeBase64(signData));
+ /* 328 */
+ mmp.put("signResult", base64Str);
+
+ /* 330 */
+ MOFVerifyResult resultVer = client.verifySign(signData, plain.getBytes(StandardCharsets.UTF_8));
+ /* 331 */
+ System.out.println("验签结果为:" + JSONObject.toJSONString(resultVer));
+
+ /* 333 */
+ mmp.put("issure", resultVer.getIssure());
+ /* 334 */
+ mmp.put("sn", resultVer.getSn());
+ /* 335 */
+ mmp.put("signTime", resultVer.getSignTime());
+
+ /* 337 */
+ xysfResult.put("success", Boolean.valueOf(true));
+ /* 338 */
+ xysfResult.put("content", mmp);
+ /* 339 */
+ return xysfResult;
+ }
+ /* 341 */ catch (NewCSSException e) {
+ /* 342 */
+ System.out.println("****签名失败****");
+ /* 343 */
+ System.out.println("错误号为:" + e.getCode());
+ /* 344 */
+ System.out.println("错误描述为:" + e.getDescription());
+ /* 345 */
+ xysfResult.put("success", Boolean.valueOf(false));
+ /* 346 */
+ xysfResult.put("msg", "系统错误");
+ /* 347 */
+ return xysfResult;
+ }
+ }
public static String montageXmlV3(String ywfilePath, String xmlStr) {
diff --git a/exam-system/src/main/java/com/gkhy/exam/pay/utils/SignCommond.java b/exam-system/src/main/java/com/gkhy/exam/pay/utils/SignCommond.java
index aaf9a89..5a43539 100644
--- a/exam-system/src/main/java/com/gkhy/exam/pay/utils/SignCommond.java
+++ b/exam-system/src/main/java/com/gkhy/exam/pay/utils/SignCommond.java
@@ -17,7 +17,7 @@
// 将摘要转换为 Base64 编码的字符串
String signatureValue = Base64.getEncoder().encodeToString(hashBytes);
- SignDto signDto = new SignDto( new Date(), signatureValue, "1234567890", "issuerDn");
+ SignDto signDto = new SignDto(new Date(), signatureValue, "1234567890", "issuerDn");
return signDto;
diff --git a/exam-system/src/main/resources/mapper/pay/CoalPayStudentMapper.xml b/exam-system/src/main/resources/mapper/pay/CoalPayStudentMapper.xml
index 1f0eecd..4b45803 100644
--- a/exam-system/src/main/resources/mapper/pay/CoalPayStudentMapper.xml
+++ b/exam-system/src/main/resources/mapper/pay/CoalPayStudentMapper.xml
@@ -1,10 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gkhy.exam.pay.mapper.CoalPayStudentMapper">
<sql id="selectCoalPayStudentVo">
- select id, coal_pay_id, name, id_card, phone, sex, pay_code, pay_status,pay_type,order_id,order_no,file_data,gov_pay_status, update_by, update_time, create_by, create_time, del_flag from coal_pay_student
+ select id,
+ coal_pay_id,
+ name,
+ id_card,
+ phone,
+ sex,
+ pay_code,
+ pay_status,
+ pay_type,
+ order_id,
+ file_data,
+ gov_pay_status,
+ update_by,
+ update_time,
+ create_by,
+ create_time,
+ del_flag,
+ order_no,
+ pay_time
+ from coal_pay_student
</sql>
<insert id="insertCoalPayStudent">
insert into coal_pay_student
@@ -19,7 +38,7 @@
<if test="payStatus != null">pay_status,</if>
<if test="payType != null">pay_type,</if>
<if test="orderId!=null">order_id,</if>
- <if test="orderNo!=null">order_no,</if>
+ <if test="orderNo != null and orderNo != '' ">order_no,</if>
<if test="fileData!=null">file_data,</if>
<if test="govPayStatus!=null">gov_pay_status,</if>
<if test="createBy != null">create_by,</if>
@@ -39,7 +58,7 @@
<if test="payStatus != null">#{payStatus},</if>
<if test="payType != null">#{payType},</if>
<if test="orderId!=null">#{orderId},</if>
- <if test="orderNo!=null">#{orderNo},</if>
+ <if test="orderNo != null and orderNo != '' ">#{orderNo},</if>
<if test="fileData!=null">#{fileData},</if>
<if test="govPayStatus!=null">#{govPayStatus},</if>
<if test="createBy != null">#{createBy},</if>
@@ -66,9 +85,9 @@
<if test="sex != null">sex = #{sex},</if>
<if test="payType != null">pay_type = #{payType},</if>
<if test="payCode != null">pay_code = #{payCode},</if>
+ <if test="payTime != null">pay_time = #{payTime},</if>
<if test="payStatus != null">pay_status = #{payStatus},</if>
<if test="orderId!=null">order_id=#{orderId},</if>
- <if test="orderNo!=null">order_no=#{orderNo},</if>
<if test="fileData!=null">file_data=#{fileData},</if>
<if test="govPayStatus!=null">gov_pay_status=#{govPayStatus},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
@@ -86,15 +105,16 @@
</update>
<update id="updateByCoalPayIdAndStatus">
update coal_pay_student
- set order_id = #{orderId},order_no=#{orderNo},
- gov_pay_status = #{govPayStatus},pay_code = #{payCode}
- where coal_pay_id = #{coalPayId} and pay_status = 0 and pay_type = 2
+ <trim prefix="SET" suffixOverrides=",">
+ <if test="payType != null">pay_type = #{payType},</if>
+ </trim>
+ where coal_pay_id = #{coalPayId} and pay_status = 0
</update>
<select id="selectByCoalPayId" resultType="com.gkhy.exam.pay.entity.CoalPayStudent">
<include refid="selectCoalPayStudentVo"></include>
- where coal_pay_id = #{coalPayId}
- and del_flag =0
+ where coal_pay_id = #{coalPayId}
+ and del_flag =0
</select>
<select id="selectByCoalPayIdAndPayStatus" resultType="com.gkhy.exam.pay.entity.CoalPayStudent">
@@ -103,9 +123,9 @@
<if test="status == 0">
and pay_type = 2
</if>
- and coal_pay_id = #{id}
- and pay_status = #{status}
- and del_flag =0
+ and coal_pay_id = #{id}
+ and pay_status = #{status}
+ and del_flag =0
</where>
</select>
--
Gitblit v1.9.2