You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
2.1 KiB

  1. package org.jeecg;
  2. import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
  3. import org.jeecg.modules.pay.MpWxPayService;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.boot.SpringApplication;
  6. import org.springframework.boot.autoconfigure.SpringBootApplication;
  7. import org.springframework.context.ConfigurableApplicationContext;
  8. import org.springframework.web.bind.annotation.RequestBody;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RestController;
  11. @RestController
  12. @SpringBootApplication
  13. public class PayDemoApplication {
  14. public static void main(String[] args) {
  15. ConfigurableApplicationContext app = SpringApplication.run(PayDemoApplication.class, args);
  16. // 用法说明 @Autowired MpWxPayService mpWxPayService
  17. MpWxPayService bean = app.getBean(MpWxPayService.class);
  18. //Object callback = bean.createAppOrder("产品名", "127.0.0.1", "89", 1, "20219092", "{}","");
  19. //System.err.println(callback.toString());
  20. Object webOrder = bean.createWebOrder("产品名", "117.61.97.157", "89", 1, "20219092", "{}", "");
  21. System.err.println(webOrder.toString());
  22. //缓存该数据用于与异步通知对比处理
  23. //WxPayAppOrderResult(sign=6E404CB2E71FD391BB0FE2C2B12F5264, prepayId=wx17011430290850d50f73c68d61e80a0000, partnerId=1560997691, appId=wx7081b3f6277c100d, packageValue=Sign=WXPay, timeStamp=1637082870, nonceStr=1637082870392)
  24. //取以上数据交由前端调起支付
  25. }
  26. //部署该地址至外网接受异步通知
  27. @RequestMapping("/notify")
  28. public Object notify(@RequestBody String requestBody, @Autowired MpWxPayService mpWxPayService){
  29. WxPayOrderNotifyResult notify = mpWxPayService.notify(requestBody);
  30. String outTradeNo = notify.getOutTradeNo();
  31. System.err.println(outTradeNo);
  32. //对比outTradeNo进行业务处理
  33. if (notify == null){
  34. //会继续通知
  35. return "FAIL";
  36. }
  37. //不再通知该结果
  38. return "SUCCESS";
  39. }
  40. }