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(); } }