PayController.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package com.chuanghai.smartschool.tuitionpayment.controller;
  2. import com.chuanghai.smartschool.tuitionpayment.common.exception.BizCodeEnume;
  3. import com.chuanghai.smartschool.tuitionpayment.common.exception.RRException;
  4. import com.chuanghai.smartschool.tuitionpayment.common.utils.CommonResult;
  5. import com.chuanghai.smartschool.tuitionpayment.service.PayOrderService;
  6. import com.chuanghai.smartschool.tuitionpayment.service.PayService;
  7. import com.chuanghai.smartschool.tuitionpayment.service.PayableInfoService;
  8. import com.chuanghai.smartschool.tuitionpayment.service.PayableInfoWaterService;
  9. import com.chuanghai.smartschool.tuitionpayment.vo.StudentNameTeleVO;
  10. import com.chuanghai.smartschool.tuitionpayment.vo.WechatJsApiPayParamVO;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Controller;
  14. import org.springframework.web.bind.annotation.*;
  15. import javax.servlet.http.HttpServletRequest;
  16. /**
  17. * 支付接口
  18. *
  19. * @author codingliang
  20. * @email codingliang@gmail.com
  21. * @date 2021-08-12 15:52:41
  22. */
  23. @Slf4j
  24. @Controller
  25. @RequestMapping({"pay", "tuitionpayment/pay"})
  26. public class PayController {
  27. @Autowired
  28. private PayService payService;
  29. @Autowired
  30. private PayOrderService payOrderService;
  31. @Autowired
  32. private PayableInfoService payableInfoService;
  33. @Autowired
  34. private PayableInfoWaterService payableInfoWaterService;
  35. @Autowired
  36. private PayableInfoWaterController payableInfoWaterController;
  37. @Autowired
  38. private WechatController wechatController;
  39. /**
  40. * 【建行】获取拉起微信支付的参数
  41. *
  42. * @param cardNumber 当前登录用户标识
  43. * @param orderNo 订单号
  44. * @param openId 支付者唯一标识
  45. * @param secondOrderNo 携带第二次支付的订单号
  46. * @param payment 1 学费 2 黄家湖水费 3 计算机二级 4 双学位 5 成人教育(函授)
  47. * @return
  48. * @throws Exception
  49. */
  50. @ResponseBody
  51. @GetMapping("ccb/getJsApiParam")
  52. public CommonResult<WechatJsApiPayParamVO> getCCBJsApiParam(@RequestHeader("card_number") String cardNumber,
  53. @RequestParam String orderNo,
  54. @RequestParam String openId,
  55. String secondOrderNo,
  56. String payment) {
  57. WechatJsApiPayParamVO jsApiPayParam = payService.getCCBJsApiParam(openId, orderNo, secondOrderNo, payment);
  58. //判断该缴费名单是否正在支付
  59. if (payment.equals("2")) {
  60. Boolean aBoolean = payableInfoWaterService.queryWaterPay(payOrderService.queryPayInfoByOrderId(orderNo), cardNumber);
  61. if (aBoolean) {
  62. StudentNameTeleVO studentNameTeleVO = wechatController.getUserNameTele(payableInfoWaterService.queryByPayInfoId(payOrderService.queryPayInfoByOrderId(orderNo))).getData();
  63. throw new RRException(BizCodeEnume.ORDER_IS_PAYING, "订单已被" +studentNameTeleVO.getName() +"支付锁定,解除锁定请联系:"+studentNameTeleVO.getTelephone());
  64. }
  65. }else {
  66. Boolean bBoolean = payableInfoService.queryInforPay(payOrderService.queryPayInfoByOrderId(orderNo), cardNumber);
  67. if (bBoolean) {
  68. StudentNameTeleVO studentNameTeleVO = wechatController.getUserNameTele(payableInfoWaterService.queryByPayInfoId(payOrderService.queryPayInfoByOrderId(orderNo))).getData();
  69. throw new RRException(BizCodeEnume.ORDER_IS_PAYING, "订单已被" +studentNameTeleVO.getName() +"支付锁定,解除锁定请联系:"+studentNameTeleVO.getTelephone());
  70. }
  71. }
  72. if (jsApiPayParam.getErrmsg().contains("支付不成功")) {
  73. //订单支付失败则将缴费名单的订单支付中的状态修改为未支付状态
  74. Boolean aaBoolean = payableInfoService.updatePayInfoStatu(payOrderService.queryPayInfoByOrderId(orderNo), "1", "null", "null");
  75. if (!aaBoolean) {
  76. Boolean aBoolean1 = payableInfoWaterService.updateWaterInfoStatu(payOrderService.queryPayInfoByOrderId(orderNo), "1", "null", "null");
  77. }
  78. }
  79. // PayableInfoWaterEntity byId = payableInfoWaterService.getById(payOrderService.queryPayInfoByOrderId(orderNo));
  80. // System.out.println(byId);
  81. return CommonResult.ok().setResult(jsApiPayParam);
  82. }
  83. /**
  84. * 【建行】支付结果异步通知
  85. *
  86. * @param request 请求原始数据
  87. * @return
  88. */
  89. @ResponseBody
  90. @PostMapping("ccb/notify")
  91. public CommonResult<String> ccbNotify(HttpServletRequest request) {
  92. payService.ccbNotify(request);
  93. return CommonResult.ok().setResult("处理成功");
  94. }
  95. /**
  96. * 【建行】支付成功回跳页面
  97. *
  98. * @param request
  99. * @return
  100. * @apiNote 支付成功后,建行服务器会调用该接口
  101. * 该接口监听到建行回调后,会以【fontendUrl + pages/paySuccess/paySuccess?orderNo=123】的形式跳回到前端页面
  102. * <strong>注意:</strong>
  103. * fontendUrl + pages/paySuccess/paySuccess是前端支付成功之后的页面,需要前端开发人员与后台开发人员协调好
  104. */
  105. @GetMapping("ccb/success")
  106. public String ccbSuccess(HttpServletRequest request) {
  107. String url = payService.ccbSuccess(request);
  108. return "redirect:" + url;
  109. }
  110. /**
  111. * 【农商行】发起支付
  112. *
  113. * @return
  114. * @apiNote 页面直接跳转链接【https://q.jxnxs.com/newpay?O=&out_no=&amount=&appoint_notify=】发起支付
  115. * O:固定传5494ec3310685daa218382619dd20e27
  116. * out_no:订单号,下单接口获取
  117. * amount:支付金额,单位元,下单接口获取
  118. * appoint_notify:异步通知地址,测试地址:http://7n9xr5.natappfree.cc/pay/jxnxs/notify、正式地址:https://jtishfw.ncjti.edu.cn/jiaofei/backendApi/pay/jxnxs/notify/
  119. * @since 0.1.0
  120. */
  121. @GetMapping("spec001")
  122. public String spec001() {
  123. return "";
  124. }
  125. /**
  126. * 【农商行】支付结果异步通知
  127. *
  128. * @param request
  129. * @return
  130. * @since 0.1.0
  131. */
  132. @ResponseBody
  133. @GetMapping("jxnxs/notify")
  134. public String jxnxsNotify(HttpServletRequest request) {
  135. boolean isSuccess = payService.jxnxsNotify(request);
  136. if (isSuccess) {
  137. return "notify_success";
  138. } else {
  139. return "notify_fail";
  140. }
  141. }
  142. /**
  143. * 【农商行】支付成功跳转地址
  144. *
  145. * @param orderNo 订单号
  146. * @return
  147. * @since 0.1.0
  148. */
  149. @GetMapping("jxnxs/success")
  150. public String jxnxsSuccess(@RequestParam("ord_no") String orderNo) {
  151. String secondOrderNo = "1";
  152. String url = payService.jxnxsSuccess(orderNo, secondOrderNo);
  153. return "redirect:" + url;
  154. }
  155. }