wlzboy
6 天以前 3bbd80a63ac7728ac01b641a48a26befcb171a0f
dryad-payment/src/main/java/com/ruoyi/payment/interfaces/controller/PaymentNotifyController.java
@@ -37,7 +37,7 @@
     * 微信支付回调
     */
    @Anonymous
    @PostMapping("/wechat")
    @PostMapping("/wechat/notify")
    public String wechatNotify(HttpServletRequest request) {
        try {
            log.info("接收到微信支付回调");
@@ -78,7 +78,7 @@
     * 支付宝回调
     */
    @Anonymous
    @PostMapping("/alipay")
    @PostMapping("/alipay/notify")
    public String alipayNotify(HttpServletRequest request) {
        try {
            log.info("接收到支付宝回调");
@@ -113,6 +113,105 @@
    }
    /**
     * 第三方支付宝回调(GET请求)
     * <p>
     * 第三方支付宝通过GET方式回调,参数通过URL传递
     * <p>
     * 参数格式:
     * method=xxx&APPID=xxx&PaidMoneyType=xxx&PaidMoney=xxx&PaidRemarks=xxx&UnixTime=xxx&Sign=xxx
     * <p>
     * 参数说明:
     * - method: 方法名
     * - APPID: 应用ID
     * - PaidMoneyType: 支付类型
     * - PaidMoney: 支付金额(单位:分)
     * - PaidRemarks: 支付备注(包含订单号和交易号信息)
     * - UnixTime: 时间戳
     * - Sign: 签名
     * <p>
     * 示例:
     * GET /api/pay/notify/alipay/thirdparty?method=alipay.pay&APPID=123456&PaidMoneyType=alipay&PaidMoney=100&PaidRemarks=1234567890&UnixTime=1638360000&Sign=abc123
     */
    @Anonymous
    @GetMapping("/alipay/thirdparty")
    public String alipayThirdPartyNotify(HttpServletRequest request) {
        try {
            log.info("接收到第三方支付宝回调(GET请求)");
            // 1. 获取所有参数
            Map<String, String> params = new HashMap<>();
            Enumeration<String> parameterNames = request.getParameterNames();
            while (parameterNames.hasMoreElements()) {
                String name = parameterNames.nextElement();
                params.put(name, request.getParameter(name));
            }
            log.info("第三方支付宝回调参数: {}", params);
            // 2. 第三方支付宝不需要验签,或者根据第三方平台的签名规则进行验证
            // 这里直接处理,如果需要验签可以在Service层添加
            // 3. 处理回调(更新订单状态、触发业务回调)
            paymentNotifyService.processAlipayThirdPartyNotify(params);
            // 4. 返回第三方支付宝要求的应答
            return "success";
        } catch (Exception e) {
            log.error("处理第三方支付宝回调失败", e);
            return "fail";
        }
    }
    /**
     * 第三方微信回调(GET请求)
     * <p>
     * 第三方微信通过GET方式回调,参数通过URL传递
     * <p>
     * 参数格式:
     * method=xxx&APPID=xxx&PaidMoneyType=xxx&PaidMoney=xxx&PaidRemarks=xxx&UnixTime=xxx
     * <p>
     * 参数说明:
     * - method: 方法名
     * - APPID: 应用ID
     * - PaidMoneyType: 支付类型
     * - PaidMoney: 支付金额(单位:分)
     * - PaidRemarks: 支付备注(包含订单号和交易号信息)
     * - UnixTime: 时间戳
     * <p>
     * 示例:
     * GET /api/pay/notify/wechat/thirdparty?method=wechat.pay&APPID=123456&PaidMoneyType=wechat&PaidMoney=100&PaidRemarks=1234567890&UnixTime=1638360000
     */
    @Anonymous
    @GetMapping("/wechat/thirdparty")
    public String wechatThirdPartyNotify(HttpServletRequest request) {
        try {
            log.info("接收到第三方微信回调(GET请求)");
            // 1. 获取所有参数
            Map<String, String> params = new HashMap<>();
            Enumeration<String> parameterNames = request.getParameterNames();
            while (parameterNames.hasMoreElements()) {
                String name = parameterNames.nextElement();
                params.put(name, request.getParameter(name));
            }
            log.info("第三方微信回调参数: {}", params);
            // 2. 第三方微信不需要验签,或者根据第三方平台的签名规则进行验证
            // 这里直接处理,如枟需要验签可以在Service层添加
            // 3. 处理回调(更新订单状态、触发业务回调)
            paymentNotifyService.processWechatThirdPartyNotify(params);
            // 4. 返回第三方微信要求的应答
            return "success";
        } catch (Exception e) {
            log.error("处理第三方微信回调失败", e);
            return "fail";
        }
    }
    /**
     * 读取请求体
     */
    private String readRequestBody(HttpServletRequest request) throws Exception {