| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.utils.CodeGenerateUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.model.TCourseOrder; |
| | | import com.ruoyi.system.service.TCourseOrderService; |
| | | import com.ruoyi.system.wxPay.enums.RefundEnum; |
| | | import com.ruoyi.system.wxPay.enums.TradeStateEnum; |
| | | import com.ruoyi.system.wxPay.model.WeixinPayProperties; |
| | | import com.ruoyi.system.wxPay.utils.WxTimeUtils; |
| | | import com.ruoyi.system.wxPay.utils.WxV3Pay; |
| | | import com.wechat.pay.contrib.apache.httpclient.util.AesUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.bind.annotation.CrossOrigin; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | import java.math.BigDecimal; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 微信相关接口 |
| | |
| | | private TokenService tokenService; |
| | | @Autowired |
| | | private WeixinPayProperties weixinPayProperties; |
| | | |
| | | @Autowired |
| | | private TCourseOrderService courseOrderService; |
| | | |
| | | |
| | | |
| | |
| | | String success_time = jsonInfo.getString("success_time"); |
| | | // 查询订单 |
| | | |
| | | TCourseOrder order = courseOrderService.getOne(Wrappers.lambdaQuery(TCourseOrder.class) |
| | | .eq(TCourseOrder::getOrderNumber, out_trade_no).last("LIMIT 1")); |
| | | if (trade_state.equals(TradeStateEnum.SUCCESS.name())) { |
| | | log.info("回调成功"); |
| | | // 订单号查询订单 |
| | | order.setPayStatus(2); |
| | | order.setPayTime(WxTimeUtils.dateToLocalDateTime(WxTimeUtils.toRfc3339Date(success_time))); |
| | | order.setTransactionId(transaction_id); |
| | | courseOrderService.updateById(order); |
| | | |
| | | PrintWriter out = response.getWriter(); |
| | | out.print("SUCCESS"); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 退款回调 |
| | | */ |
| | | // @PostMapping("refund/notify") |
| | | // @ApiOperation("退款回调") |
| | | // public void refundNotify(HttpServletRequest request, HttpServletResponse response) throws Exception { |
| | | // try { |
| | | //// System.err.println("微信回调"); |
| | | //// BufferedReader reader = request.getReader(); |
| | | //// StringBuilder requestBody = new StringBuilder(); |
| | | //// String line; |
| | | //// while ((line = reader.readLine()) != null) { |
| | | //// requestBody.append(line); |
| | | //// } |
| | | //// System.err.println("全部请求体" + requestBody); |
| | | //// JSONObject jsonObject = JSONObject.parseObject(requestBody.toString()); |
| | | //// JSONObject resource = jsonObject.getJSONObject("resource"); |
| | | //// AesUtil aesUtil = new AesUtil(weixinPayProperties.getV3().getApiKey().getBytes(StandardCharsets.UTF_8)); |
| | | //// String decryptedData = aesUtil.decryptToString(resource.getString("associated_data").getBytes(StandardCharsets.UTF_8), resource.getString("nonce").getBytes(StandardCharsets.UTF_8), resource.getString("ciphertext")) |
| | | // } |
| | | // } |
| | | @PostMapping("refund/notify") |
| | | public void refundNotify(HttpServletRequest request) throws IOException { |
| | | try { |
| | |
| | | // 微信支付订单号 |
| | | String transaction_id = params.get("transaction_id").toString(); |
| | | if (tradeState.equals(RefundEnum.SUCCESS.name())) { |
| | | TCourseOrder order = courseOrderService.getOne(Wrappers.lambdaQuery(TCourseOrder.class) |
| | | .eq(TCourseOrder::getRefundNumber, out_refund_no).last("LIMIT 1")); |
| | | order.setPayStatus(3); |
| | | order.setRefundStatus(2); |
| | | order.setRefundTransactionId(transaction_id); |
| | | courseOrderService.updateById(order); |
| | | |
| | | |
| | | wxV3Pay.ack(); |
| | | } |