exam-system/src/main/java/com/gkhy/exam/pay/controller/CoalPayController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
exam-system/src/main/java/com/gkhy/exam/pay/controller/PayFeesController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
exam-system/src/main/java/com/gkhy/exam/pay/service/CoalPayService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
exam-system/src/main/java/com/gkhy/exam/pay/service/CoalPayStudentService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
exam-system/src/main/java/com/gkhy/exam/pay/service/impl/CoalPayServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
exam-system/src/main/java/com/gkhy/exam/pay/service/impl/CoalPayStudentServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
exam-system/src/main/java/com/gkhy/exam/pay/utils/PayUtils.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
exam-system/src/test/java/TextPay.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ruoyi-common/pom.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
exam-system/src/main/java/com/gkhy/exam/pay/controller/CoalPayController.java
@@ -8,6 +8,7 @@ import com.gkhy.exam.pay.dto.req.CoalPayTypeReq; import com.gkhy.exam.pay.entity.CoalPayStudent; import com.gkhy.exam.pay.service.CoalPayService; import com.ruoyi.common.annotation.Anonymous; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; @@ -95,20 +96,19 @@ /** * 个人缴费接口 */ @PostMapping("/findStudent") @GetMapping("/findStudent") @Anonymous @ApiOperation(value ="H5个人缴费查询") public AjaxResult findStudent(@RequestBody CoalPayStudentReq coalPayStudent){ List<CoalPayStudentRep> coalPayStudentReps = coalPayService.selectCoalPay(coalPayStudent); public AjaxResult findStudent(@RequestParam("idCard") String idCard,@RequestParam("phone") String phone){ List<CoalPayStudentRep> coalPayStudentReps = coalPayService.selectCoalPay(idCard,phone); return success(coalPayStudentReps); } // @PostMapping("/personPay") // @ApiOperation(value = "个人缴费接口") // public void payFees(){ // // } @PostMapping("/personPay") @ApiOperation(value = "个人缴费接口") public AjaxResult payMoney(@RequestParam("coalPayId") Long coalPayId,@RequestParam("studentId") Long studentId){ return success(coalPayService.personPayMoney(coalPayId,studentId)); } exam-system/src/main/java/com/gkhy/exam/pay/controller/PayFeesController.java
对比新文件 @@ -0,0 +1,41 @@ package com.gkhy.exam.pay.controller; import com.alibaba.fastjson2.JSONObject; import com.gkhy.exam.pay.utils.PayUtils; import com.ruoyi.common.core.controller.BaseController; import io.swagger.annotations.Api; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.io.IOException; import java.util.Map; @RestController @Api(tags = "缴费通知") @RequestMapping("/pay/payFees") public class PayFeesController extends BaseController { @PostMapping("/inform") public Map<String,String> inform(@RequestBody JSONObject jsonObject){ PayUtils payUtils = new PayUtils(); Map<String, String> receive = null; try { receive = payUtils.receive(jsonObject); } catch (IOException e) { throw new RuntimeException(e); } return receive; } } exam-system/src/main/java/com/gkhy/exam/pay/service/CoalPayService.java
@@ -24,7 +24,9 @@ AjaxResult deleteCoalPayByIds(Long[] ids); List<CoalPayStudentRep> selectCoalPay(CoalPayStudentReq coalPayStudent); List<CoalPayStudentRep> selectCoalPay(String idcard,String phone); int updateCoalPayType(CoalPayTypeReq coalPayDto); String personPayMoney(Long coalPayId, Long studentId); } exam-system/src/main/java/com/gkhy/exam/pay/service/CoalPayStudentService.java
@@ -27,4 +27,5 @@ List<CoalPayStudent> selectbyIdcard(CoalPayStudentReq coalPayStudent); CoalPayStudent selectbyId(Long studentId); } exam-system/src/main/java/com/gkhy/exam/pay/service/impl/CoalPayServiceImpl.java
@@ -7,35 +7,37 @@ import com.gkhy.exam.pay.dto.req.CoalPayReq; import com.gkhy.exam.pay.dto.req.CoalPayStudentReq; import com.gkhy.exam.pay.dto.req.CoalPayTypeReq; import com.gkhy.exam.pay.entity.CoalCategory; import com.gkhy.exam.pay.entity.CoalPay; import com.gkhy.exam.pay.entity.CoalPayCategory; import com.gkhy.exam.pay.entity.CoalPayStudent; import com.gkhy.exam.pay.entity.*; import com.gkhy.exam.pay.mapper.CoalCategoryMapper; import com.gkhy.exam.pay.mapper.CoalPayCategoryMapper; 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.PayUtils; import com.gkhy.exam.pay.utils.ResultVo; 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.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; 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 javafx.print.Collation; import org.aspectj.weaver.loadtime.Aj; import org.aspectj.lang.reflect.UnlockSignature; import org.redisson.api.RLock; import org.redisson.api.RedissonClient; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.stream.Collectors; @Service @@ -52,6 +54,11 @@ private CoalCategoryMapper coalCategoryMapper; @Autowired private CoalPayStudentService coalPayStudentService; @Autowired private RedissonClient redissonClient; /** @@ -168,9 +175,12 @@ //个人查询缴费 @Override public List<CoalPayStudentRep> selectCoalPay(CoalPayStudentReq coalPayStudent) { public List<CoalPayStudentRep> selectCoalPay(String idcard,String phone) { CoalPayStudentReq coalPayStudentReq = new CoalPayStudentReq(); coalPayStudentReq.setIdCard(idcard); coalPayStudentReq.setPhone(phone); //查询个人需要缴费 List<CoalPayStudent> coalPayStudents = coalPayStudentService.selectbyIdcard(coalPayStudent); List<CoalPayStudent> coalPayStudents = coalPayStudentService.selectbyIdcard(coalPayStudentReq); List<CoalPayStudentRep> coalPayStudentReps = new ArrayList<>(); for (CoalPayStudent payStudent : coalPayStudents) { //封装学生基础信息 @@ -205,4 +215,69 @@ } return coalPayMapper.updateByPayId(coalPayTypeReq); } @Override public String personPayMoney(Long coalPayId, Long studentId) { CoalPayStudent coalPayStudent = coalPayStudentService.selectbyId(studentId); CoalPay coalPay = coalPayMapper.selectById(coalPayId); List<CoalCategory> coalCategories = coalCategoryMapper.selectByCoalPayId(coalPayId); CoalTicket coalTicket = coalCategoryMapper.selectCoalTicket(); PayReqData payReqData = new PayReqData(); payReqData.setOrderNo(RandomUtil.generateOrderNumber()); payReqData.setMoney(coalPay.getAmount()); payReqData.setAmount(1); payReqData.setPayerName(coalPayStudent.getName()); payReqData.setCertNo(coalPayStudent.getIdCard()); payReqData.setPayerType(1); payReqData.setInvoiceSocialCode(coalTicket.getTicketCompanyCode()); payReqData.setHandlingPerson(coalTicket.getDrawer()); payReqData.setChecker(coalTicket.getCheck()); payReqData.setEnterCode(coalTicket.getCompanyCode()); payReqData.setDesc(coalPay.getBatchName()); PayReqData.Feedata feedata = new PayReqData.Feedata(); List<PayReqData.Feedata> feedatas = new ArrayList<>(); for (CoalCategory coalCategory : coalCategories) { feedata.setAmount(1); feedata.setPrice(coalCategory.getAmount()); feedata.setBusCode(coalCategory.getBusinessCode()); feedatas.add(feedata); } payReqData.setFeeDatas(feedatas); CoalPayStudent payStudent = new CoalPayStudent(); RLock lock = redissonClient.getLock("SWSPKMAS_PAY_PERSON"); try { lock.lock(10, TimeUnit.SECONDS); if (coalPayStudent.getGovPayStatus()!=0){ throw new BusinessException(this.getClass(),ResultConstants.BUSINESS_ERROR,"请勿重复发起支付"); } if (StringUtils.isEmpty(coalPayStudent.getPayCode())){ } ResultVo resultVo = PayUtils.sendApiPost(payReqData); if (resultVo.getRespcode().equals("BUS0000")){ payStudent.setId(studentId); payStudent.setOrderId(resultVo.getRespdata().getOrderNo()); payStudent.setGovPayStatus(1); payStudent.setPayCode(resultVo.getRespdata().getBillNo()); coalPayStudentService.updateByCoalPayStudent(payStudent); return resultVo.getRespdata().getBillNo(); }else { throw new BusinessException(this.getClass(),ResultConstants.BUSINESS_ERROR,"发起支付失败,请稍后重试"); } }catch (BusinessException e){ throw new BusinessException(this.getClass(),ResultConstants.BUSINESS_ERROR,"请稍后重试"); } catch (IOException e) { throw new RuntimeException(e); } finally { if(lock.isLocked()){ lock.unlock(); } } } } exam-system/src/main/java/com/gkhy/exam/pay/service/impl/CoalPayStudentServiceImpl.java
@@ -141,4 +141,9 @@ public List<CoalPayStudent> selectbyIdcard(CoalPayStudentReq coalPayStudent) { return coalPayStudentMapper.selectByIdcard(coalPayStudent); } @Override public CoalPayStudent selectbyId(Long studentId) { return coalPayStudentMapper.selectById(studentId); } } 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; } } exam-system/src/test/java/TextPay.java
@@ -1,6 +1,9 @@ import com.alibaba.fastjson2.JSONObject; import com.gkhy.exam.pay.entity.PayReqData; import com.gkhy.exam.pay.utils.PayUtils; import com.gkhy.exam.pay.utils.ResultVo; import com.google.gson.JsonObject; import com.ruoyi.common.utils.RandomUtil; import com.ruoyi.common.utils.uuid.UUID; import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.Test; @@ -12,6 +15,7 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Map; @SpringBootTest(classes = TextPay.class) @ActiveProfiles("dev") @@ -27,7 +31,7 @@ PayReqData.Feedata feedatas = new PayReqData.Feedata(); payReqData.setDesc("安全技术考试考务费_煤矿安全作业-001504"); payReqData.setOrderNo("10000000001"); payReqData.setOrderNo(RandomUtil.generateOrderNumber()); payReqData.setMoney(BigDecimal.valueOf(103)); payReqData.setAmount(1); payReqData.setPayerName("测试"); @@ -46,13 +50,26 @@ payReqData.setFeeDatas(feedatas1); ResultVo resultVo = PayUtils.sendApiPost(payReqData); PayUtils payUtils = new PayUtils(); ResultVo resultVo = payUtils.sendApiPost(payReqData); System.out.printf("请求结果:"+resultVo); } @Test public void text001(){ try { // String s = PayUtils.affirmPost("10000001"); JSONObject query = PayUtils.query("1000001"); } catch (IOException e) { throw new RuntimeException(e); } } } ruoyi-common/pom.xml
@@ -161,6 +161,11 @@ <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> </dependency> <dependency> <groupId>org.redisson</groupId> <artifactId>redisson-spring-boot-starter</artifactId> <version>3.18.0</version> </dependency> </dependencies> </project>