shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.iplatform.pay.notify;
 
import com.iplatform.pay.BasePayApi;
import com.iplatform.pay.Constants;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.pay.exception.NotifyException;
import com.walker.pay.wechat.WechatV2PayEngineProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.io.IOException;
 
/**
 * 微信支付v2版本的通知接口。
 * @author 时克英
 * @date 2023-03-01
 */
@RestController
@RequestMapping("/pay/notify/wx_v2")
@ConditionalOnClass({WechatV2PayEngineProvider.class})
public class WechatPayV2Api extends BasePayApi {
 
    @PostMapping("/orderNotify")
    public void orderPayNotify(@RequestBody String raw) throws IOException {
        if(StringUtils.isEmpty(raw)){
            throw new IllegalArgumentException("'微信v2支付'通知,未接收到原始数据:" + raw, null);
        }
 
        try {
            String error = this.getPayEngineManager().notifyOrder(Constants.PAY_DEFINITION_ID_WECHAT_V2, raw);
            if(StringUtils.isNotEmpty(error)){
                throw new RuntimeException("'微信v2支付'引擎返回错误:" + error, null);
            }
        } catch (NotifyException e) {
            throw new RuntimeException("'微信v2支付'结果通知异常:" + e.getMessage() + ", raw = " + raw , e);
        }
 
        // 微信v2版本,必须返回成功响应,还是xml格式。
        String response = this.getPayEngineManager().generateNotifyResponse(Constants.PAY_DEFINITION_ID_WECHAT_V2, true);
        this.ajaxOutPutXml(response);
//        return ResponseValue.success();
    }
}