AliPayInterceptor.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package com.ruoyi.app.pay;
  2. import com.alipay.api.AlipayApiException;
  3. import com.ijpay.alipay.AliPayApiConfigKit;
  4. import org.springframework.web.method.HandlerMethod;
  5. import org.springframework.web.servlet.HandlerInterceptor;
  6. import javax.servlet.http.HttpServletRequest;
  7. import javax.servlet.http.HttpServletResponse;
  8. /**
  9. * <p>IJPay 让支付触手可及,封装了微信支付、支付宝支付、银联支付常用的支付方式以及各种常用的接口。</p>
  10. *
  11. * <p>不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。 </p>
  12. *
  13. * <p>IJPay 交流群: 723992875</p>
  14. *
  15. * <p>Node.js 版: https://gitee.com/javen205/TNWX</p>
  16. *
  17. * <p>支付宝支付拦截器</p>
  18. *
  19. * @author Javen
  20. */
  21. public class AliPayInterceptor implements HandlerInterceptor {
  22. @Override
  23. public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object handler) throws AlipayApiException {
  24. if (httpServletRequest.getRequestURI().contains("/app/aliPay/")) {
  25. HandlerMethod method = (HandlerMethod) handler;
  26. Object controller = method.getBean();
  27. if (!(controller instanceof AbstractAliPayApiController)) {
  28. throw new RuntimeException("控制器需要继承 AbstractAliPayApiController");
  29. }
  30. AliPayApiConfigKit.setThreadLocalAliPayApiConfig(((AbstractAliPayApiController) controller).getApiConfig());
  31. }
  32. return true;
  33. }
  34. }