package com.chuanghai.smartschool.tuitionpayment.controller; import com.chuanghai.smartschool.tuitionpayment.common.exception.BizCodeEnume; import com.chuanghai.smartschool.tuitionpayment.common.exception.RRException; import com.chuanghai.smartschool.tuitionpayment.common.utils.CommonResult; import com.chuanghai.smartschool.tuitionpayment.service.PayOrderService; import com.chuanghai.smartschool.tuitionpayment.service.PayService; import com.chuanghai.smartschool.tuitionpayment.service.PayableInfoService; import com.chuanghai.smartschool.tuitionpayment.service.PayableInfoWaterService; import com.chuanghai.smartschool.tuitionpayment.vo.StudentNameTeleVO; import com.chuanghai.smartschool.tuitionpayment.vo.WechatJsApiPayParamVO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; /** * 支付接口 * * @author codingliang * @email codingliang@gmail.com * @date 2021-08-12 15:52:41 */ @Slf4j @Controller @RequestMapping({"pay", "tuitionpayment/pay"}) public class PayController { @Autowired private PayService payService; @Autowired private PayOrderService payOrderService; @Autowired private PayableInfoService payableInfoService; @Autowired private PayableInfoWaterService payableInfoWaterService; @Autowired private PayableInfoWaterController payableInfoWaterController; @Autowired private WechatController wechatController; /** * 【建行】获取拉起微信支付的参数 * * @param cardNumber 当前登录用户标识 * @param orderNo 订单号 * @param openId 支付者唯一标识 * @param secondOrderNo 携带第二次支付的订单号 * @param payment 1 学费 2 黄家湖水费 3 计算机二级 4 双学位 5 成人教育(函授) * @return * @throws Exception */ @ResponseBody @GetMapping("ccb/getJsApiParam") public CommonResult getCCBJsApiParam(@RequestHeader("card_number") String cardNumber, @RequestParam String orderNo, @RequestParam String openId, String secondOrderNo, String payment) { WechatJsApiPayParamVO jsApiPayParam = payService.getCCBJsApiParam(openId, orderNo, secondOrderNo, payment); //判断该缴费名单是否正在支付 if (payment.equals("2")) { Boolean aBoolean = payableInfoWaterService.queryWaterPay(payOrderService.queryPayInfoByOrderId(orderNo), cardNumber); if (aBoolean) { StudentNameTeleVO studentNameTeleVO = wechatController.getUserNameTele(payableInfoWaterService.queryByPayInfoId(payOrderService.queryPayInfoByOrderId(orderNo))).getData(); throw new RRException(BizCodeEnume.ORDER_IS_PAYING, "订单已被" +studentNameTeleVO.getName() +"支付锁定,解除锁定请联系:"+studentNameTeleVO.getTelephone()); } }else { Boolean bBoolean = payableInfoService.queryInforPay(payOrderService.queryPayInfoByOrderId(orderNo), cardNumber); if (bBoolean) { StudentNameTeleVO studentNameTeleVO = wechatController.getUserNameTele(payableInfoWaterService.queryByPayInfoId(payOrderService.queryPayInfoByOrderId(orderNo))).getData(); throw new RRException(BizCodeEnume.ORDER_IS_PAYING, "订单已被" +studentNameTeleVO.getName() +"支付锁定,解除锁定请联系:"+studentNameTeleVO.getTelephone()); } } if (jsApiPayParam.getErrmsg().contains("支付不成功")) { //订单支付失败则将缴费名单的订单支付中的状态修改为未支付状态 Boolean aaBoolean = payableInfoService.updatePayInfoStatu(payOrderService.queryPayInfoByOrderId(orderNo), "1", "null", "null"); if (!aaBoolean) { Boolean aBoolean1 = payableInfoWaterService.updateWaterInfoStatu(payOrderService.queryPayInfoByOrderId(orderNo), "1", "null", "null"); } } // PayableInfoWaterEntity byId = payableInfoWaterService.getById(payOrderService.queryPayInfoByOrderId(orderNo)); // System.out.println(byId); return CommonResult.ok().setResult(jsApiPayParam); } /** * 【建行】支付结果异步通知 * * @param request 请求原始数据 * @return */ @ResponseBody @PostMapping("ccb/notify") public CommonResult ccbNotify(HttpServletRequest request) { payService.ccbNotify(request); return CommonResult.ok().setResult("处理成功"); } /** * 【建行】支付成功回跳页面 * * @param request * @return * @apiNote 支付成功后,建行服务器会调用该接口 * 该接口监听到建行回调后,会以【fontendUrl + pages/paySuccess/paySuccess?orderNo=123】的形式跳回到前端页面 * 注意: * fontendUrl + pages/paySuccess/paySuccess是前端支付成功之后的页面,需要前端开发人员与后台开发人员协调好 */ @GetMapping("ccb/success") public String ccbSuccess(HttpServletRequest request) { String url = payService.ccbSuccess(request); return "redirect:" + url; } /** * 【农商行】发起支付 * * @return * @apiNote 页面直接跳转链接【https://q.jxnxs.com/newpay?O=&out_no=&amount=&appoint_notify=】发起支付 * O:固定传5494ec3310685daa218382619dd20e27 * out_no:订单号,下单接口获取 * amount:支付金额,单位元,下单接口获取 * appoint_notify:异步通知地址,测试地址:http://7n9xr5.natappfree.cc/pay/jxnxs/notify、正式地址:https://jtishfw.ncjti.edu.cn/jiaofei/backendApi/pay/jxnxs/notify/ * @since 0.1.0 */ @GetMapping("spec001") public String spec001() { return ""; } /** * 【农商行】支付结果异步通知 * * @param request * @return * @since 0.1.0 */ @ResponseBody @GetMapping("jxnxs/notify") public String jxnxsNotify(HttpServletRequest request) { boolean isSuccess = payService.jxnxsNotify(request); if (isSuccess) { return "notify_success"; } else { return "notify_fail"; } } /** * 【农商行】支付成功跳转地址 * * @param orderNo 订单号 * @return * @since 0.1.0 */ @GetMapping("jxnxs/success") public String jxnxsSuccess(@RequestParam("ord_no") String orderNo) { String secondOrderNo = "1"; String url = payService.jxnxsSuccess(orderNo, secondOrderNo); return "redirect:" + url; } }