PayEaseController.java 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package com.izouma.nineth.web;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson15.JSONObject;
  4. import com.izouma.nineth.config.GeneralProperties;
  5. import com.izouma.nineth.enums.PayMethod;
  6. import com.izouma.nineth.event.OrderNotifyEvent;
  7. import com.izouma.nineth.service.AuctionOrderService;
  8. import com.izouma.nineth.service.AuctionOrderService;
  9. import com.izouma.nineth.service.GiftOrderService;
  10. import com.izouma.nineth.service.MintOrderService;
  11. import com.izouma.nineth.service.UserBalanceService;
  12. import com.upay.sdk.CipherWrapper;
  13. import com.upay.sdk.onlinepay.executer.OnlinePayOrderExecuter;
  14. import lombok.AllArgsConstructor;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.apache.rocketmq.spring.core.RocketMQTemplate;
  17. import org.springframework.web.bind.annotation.*;
  18. @RestController
  19. @RequestMapping("/payease")
  20. @Slf4j
  21. @AllArgsConstructor
  22. public class PayEaseController {
  23. private final GeneralProperties generalProperties;
  24. private final RocketMQTemplate rocketMQTemplate;
  25. @PostMapping("/notify/{type}/{id}")
  26. public String notify(@PathVariable String type, @PathVariable Long id, @RequestHeader String encryptKey,
  27. @RequestHeader String merchantId, @RequestBody JSONObject rawData) {
  28. rawData.put("encryptKey", encryptKey);
  29. rawData.put("merchantId", merchantId);
  30. JSONObject data = CipherWrapper.bothDecryptWrap(rawData);
  31. log.info("payEase回调 type={}, orderId={}, 参数={}", type, id, JSON.toJSONString(data, true));
  32. OnlinePayOrderExecuter executor = new OnlinePayOrderExecuter();
  33. executor.bothVerifyHmacOrder(data);
  34. String status = data.getString("status");
  35. if ("SUCCESS".equals(status)) {
  36. String serialNumber = data.getString("serialNumber");
  37. switch (type) {
  38. case "order":
  39. rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
  40. new OrderNotifyEvent(id, PayMethod.PAYEASE, serialNumber, System.currentTimeMillis()));
  41. break;
  42. case "gift":
  43. rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
  44. new OrderNotifyEvent(id, PayMethod.SANDPAY, serialNumber,
  45. System.currentTimeMillis(), OrderNotifyEvent.TYPE_GIFT_ORDER));
  46. break;
  47. case "mintOrder":
  48. rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
  49. new OrderNotifyEvent(id, PayMethod.SANDPAY, serialNumber,
  50. System.currentTimeMillis(), OrderNotifyEvent.TYPE_MINT_ORDER));
  51. break;
  52. case "recharge":
  53. rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
  54. new OrderNotifyEvent(id, PayMethod.SANDPAY, serialNumber,
  55. System.currentTimeMillis(), OrderNotifyEvent.TYPE_RECHARGE));
  56. break;
  57. case "auctionOrder":
  58. rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
  59. new OrderNotifyEvent(id, PayMethod.SANDPAY, serialNumber,
  60. System.currentTimeMillis(), OrderNotifyEvent.TYPE_AUCTION_ORDER));
  61. break;
  62. }
  63. }
  64. return "SUCCESS";
  65. }
  66. }