| | |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.wechat.pay.contrib.apache.httpclient.notification.NotificationRequest; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping(value = "/api/xcxPay") |
| | | @RequiredArgsConstructor |
| | | public class XcxPayController { |
| | | |
| | | @Autowired |
| | | MallOrderInfoMapper mallOrderInfoMapper; |
| | | @Autowired |
| | | MallMoneyFlowMapper mallMoneyFlowMapper; |
| | | @Autowired |
| | | MallMemberWalletMapper mallMemberWalletMapper; |
| | | @Autowired |
| | | MallMemberMapper mallMemberMapper; |
| | | @Autowired |
| | | DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | @Autowired |
| | | IMallMoneyFlowService mallMoneyFlowService; |
| | | @Autowired |
| | | RedisUtils redisUtils; |
| | | @Autowired |
| | | private IApiMallMemberWalletService memberWalletService; |
| | | @Autowired |
| | | private IApiMallMemberService mallMemberService; |
| | | @Autowired |
| | | private MallAgentRecordMapper mallAgentRecordMapper; |
| | | @Autowired |
| | | private AgentProducer agentProducer; |
| | | |
| | | @Autowired |
| | | private IXcxPayService iXcxPayService; |
| | | |
| | | @Autowired |
| | | private WxFaPiaoService wxFaPiaoService; |
| | | |
| | | private final HappyActivityOrderMapper happyActivityOrderMapper; |
| | | private final MallOrderInfoMapper mallOrderInfoMapper; |
| | | private final MallMoneyFlowMapper mallMoneyFlowMapper; |
| | | private final MallMemberWalletMapper mallMemberWalletMapper; |
| | | private final MallMemberMapper mallMemberMapper; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final IMallMoneyFlowService mallMoneyFlowService; |
| | | private final RedisUtils redisUtils; |
| | | private final IApiMallMemberWalletService memberWalletService; |
| | | private final IApiMallMemberService mallMemberService; |
| | | private final MallAgentRecordMapper mallAgentRecordMapper; |
| | | private final AgentProducer agentProducer; |
| | | private final IXcxPayService iXcxPayService; |
| | | private final WxFaPiaoService wxFaPiaoService; |
| | | private final XcxProperties xcxProperties = SpringContextHolder.getBean(XcxProperties.class); |
| | | /** |
| | | * 微信充值回调接口 |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 活动门票支付回调接口 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @RequestMapping(value = "/activityOrderCallback") |
| | | public void activityOrderCallback(HttpServletResponse response, HttpServletRequest request) throws IOException { |
| | | log.info("活动门票支付回调start...."); |
| | | |
| | | // 获取输入参数 |
| | | String inputLine; |
| | | StringBuffer notityXml = new StringBuffer(); |
| | | String resXml = ""; |
| | | String orderId = ""; |
| | | |
| | | FebsResponse threadResult = new FebsResponse(); |
| | | try { |
| | | while ((inputLine = request.getReader().readLine()) != null) { |
| | | notityXml.append(inputLine); |
| | | } |
| | | request.getReader().close(); |
| | | log.info("notityXml ---- :{} ", notityXml); |
| | | |
| | | |
| | | // XMl转对象 |
| | | Object bb = Util.getObjectFromXML(notityXml.toString(), NotifyData.class); |
| | | NotifyData data = new NotifyData(); |
| | | BeanUtils.copyProperties(bb,data); |
| | | log.info("----return_code = {}", data.getReturn_code()); |
| | | |
| | | // 返回状态码 SUCCESS/FAIL |
| | | if (WechatConfigure.CODE_SUCCESS.equals(data.getReturn_code())) { |
| | | |
| | | orderId = data.getAttach(); |
| | | // 检验订单状态 |
| | | HappyActivityOrder happyActivityOrder = happyActivityOrderMapper.selectById(Long.valueOf(orderId)); |
| | | |
| | | // 校验签名 |
| | | String paySecret = xcxProperties.getWecharpaySecret(); |
| | | if (Signature.checkIsSignValidFromResponseString(notityXml.toString(),paySecret)) { |
| | | // 校验业务结果 |
| | | if (WechatConfigure.CODE_SUCCESS.equals(data.getResult_code())) { |
| | | // 返回SUCCESS报文 |
| | | resXml = WechatConfigure.RESULT_XML_SUCCESS; |
| | | // 支付费用 |
| | | Double total_fee = Double.parseDouble(data.getTotal_fee()); |
| | | //微信支付订单号 |
| | | String transaction_id = data.getTransaction_id(); |
| | | // 商户订单号 |
| | | String payNum = data.getOut_trade_no(); |
| | | |
| | | log.info("支付回调关键信息---total_fee:{},payNum:{},orderId:{}", total_fee, payNum, orderId); |
| | | // 订单ID |
| | | BigDecimal payMoney = new BigDecimal(total_fee).divide(new BigDecimal(100), 2, |
| | | RoundingMode.HALF_UP); |
| | | |
| | | |
| | | if (happyActivityOrder != null && StateUpDownEnum.PAY_STATE_NOT_PAY.getCode() == happyActivityOrder.getPayState()) { |
| | | log.debug("检查支付金额payMoney={},order.getPayMoney()={}", payMoney, happyActivityOrder.getAmount()); |
| | | happyActivityOrder.setState(StateUpDownEnum.ORDER_STATE_WAIT_USE.getCode()); |
| | | happyActivityOrder.setPayState(StateUpDownEnum.PAY_STATE_PAY_SUCCESS.getCode()); |
| | | happyActivityOrder.setUpdatedTime(new Date()); |
| | | happyActivityOrder.setPayOrderNo(payNum); |
| | | happyActivityOrder.setWxOrderNo(transaction_id); |
| | | happyActivityOrderMapper.updateById(happyActivityOrder); |
| | | |
| | | mallMoneyFlowService.addMoneyFlow( |
| | | happyActivityOrder.getMemberId(), |
| | | happyActivityOrder.getAmount().negate(), |
| | | MoneyFlowTypeEnum.WECHAT_PAY.getValue(), |
| | | happyActivityOrder.getOrderNo(), |
| | | FlowTypeEnum.WECHAT.getValue(), |
| | | "微信支付", |
| | | 2); |
| | | threadResult.success().message("支付成功"); |
| | | } else { |
| | | log.info("订单状态不为待付款,happyActivityOrder state=", happyActivityOrder.getPayState()); |
| | | } |
| | | } else { |
| | | log.info("微信标识业务是失败"); |
| | | threadResult.fail().message("查询支付信息失败,请联系客服或者刷新支付信息(错误码:001)"); |
| | | // resXml = AppConstance.RESULT_XML_FAIL.replace(ERRORMSG, "微信标识业务是失败"); |
| | | } |
| | | } else { |
| | | log.info("无效签名"); |
| | | threadResult.fail().message("查询支付信息失败,请联系客服或者刷新支付信息(错误码:002)"); |
| | | // resXml = AppConstance.RESULT_XML_FAIL.replace(ERRORMSG, "微信标识业务是失败"); |
| | | } |
| | | } else { |
| | | log.info("通信标识失败"); |
| | | threadResult.fail().message("查询支付信息失败,请联系客服或者刷新支付信息(错误码:003)"); |
| | | // resXml = AppConstance.RESULT_XML_FAIL.replace(ERRORMSG, "通信标识失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("支付回调签名错误", e); |
| | | threadResult.fail().message("查询支付信息失败,请联系客服或者刷新支付信息(错误码:004)"); |
| | | // resXml = AppConstance.RESULT_XML_FAIL.replace(ERRORMSG, "支付回调签名错误"); |
| | | } finally { |
| | | // 通知线程消息 |
| | | // PayThreadPool.notifyThread(Integer.valueOf(orderId), threadResult); |
| | | sendResultBack(response, resXml); |
| | | } |
| | | return; |
| | | |
| | | } |
| | | |
| | | private void sendResultBack(HttpServletResponse response, String resXml) throws IOException { |
| | | log.info("返回微信数据={}", resXml); |
| | | ServletOutputStream out = response.getOutputStream(); |