|
|
@@ -12,7 +12,9 @@ import com.github.kevinsawicki.http.HttpRequest;
|
|
|
import com.huifu.adapay.core.AdapayCore;
|
|
|
import com.huifu.adapay.core.util.AdapaySign;
|
|
|
import com.izouma.nineth.config.AlipayProperties;
|
|
|
+import com.izouma.nineth.config.GeneralProperties;
|
|
|
import com.izouma.nineth.enums.PayMethod;
|
|
|
+import com.izouma.nineth.event.OrderNotifyEvent;
|
|
|
import com.izouma.nineth.service.AssetService;
|
|
|
import com.izouma.nineth.service.GiftOrderService;
|
|
|
import com.izouma.nineth.service.OrderService;
|
|
|
@@ -20,10 +22,12 @@ import com.izouma.nineth.utils.SnowflakeIdWorker;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
+import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
@@ -42,6 +46,8 @@ public class OrderNotifyController {
|
|
|
private final AssetService assetService;
|
|
|
private final GiftOrderService giftOrderService;
|
|
|
private final SnowflakeIdWorker snowflakeIdWorker;
|
|
|
+ private final RocketMQTemplate rocketMQTemplate;
|
|
|
+ private final GeneralProperties generalProperties;
|
|
|
|
|
|
@PostMapping("/order/alipay")
|
|
|
@ResponseBody
|
|
|
@@ -133,26 +139,51 @@ public class OrderNotifyController {
|
|
|
return "ok";
|
|
|
}
|
|
|
|
|
|
+// @PostMapping("/adapay/order/{orderId}")
|
|
|
+// @ResponseBody
|
|
|
+// public void adapayNotify(@PathVariable Long orderId, HttpServletRequest request) {
|
|
|
+// log.info("adapay notify: \n{}", JSON.toJSONString(request.getParameterMap(), PrettyFormat));
|
|
|
+// try {
|
|
|
+// String data = request.getParameter("data");
|
|
|
+// String sign = request.getParameter("sign");
|
|
|
+// String type = request.getParameter("type");
|
|
|
+// if ("payment.succeeded".equals(type)) {
|
|
|
+// boolean checkSign = AdapaySign.verifySign(data, sign, AdapayCore.PUBLIC_KEY);
|
|
|
+// log.info("checkSign {}", checkSign);
|
|
|
+// if (checkSign) {
|
|
|
+// JSONObject jsonObject = JSON.parseObject(data);
|
|
|
+// String channel = jsonObject.getString("pay_channel");
|
|
|
+// String id = jsonObject.getString("id");
|
|
|
+//
|
|
|
+// rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
|
|
|
+// new OrderNotifyEvent(orderId, channel.startsWith("wx") ? PayMethod.WEIXIN : PayMethod.ALIPAY, id, LocalDateTime.now()));
|
|
|
+//
|
|
|
+// orderService.notifyOrder(orderId, channel.startsWith("wx") ? PayMethod.WEIXIN : PayMethod.ALIPAY, id);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
@PostMapping("/adapay/order/{orderId}")
|
|
|
@ResponseBody
|
|
|
- public void adapayNotify(@PathVariable Long orderId, HttpServletRequest request) {
|
|
|
+ public void adapayNotify(@PathVariable Long orderId, HttpServletRequest request) throws Exception {
|
|
|
log.info("adapay notify: \n{}", JSON.toJSONString(request.getParameterMap(), PrettyFormat));
|
|
|
- try {
|
|
|
- String data = request.getParameter("data");
|
|
|
- String sign = request.getParameter("sign");
|
|
|
- String type = request.getParameter("type");
|
|
|
- if ("payment.succeeded".equals(type)) {
|
|
|
- boolean checkSign = AdapaySign.verifySign(data, sign, AdapayCore.PUBLIC_KEY);
|
|
|
- log.info("checkSign {}", checkSign);
|
|
|
- if (checkSign) {
|
|
|
- JSONObject jsonObject = JSON.parseObject(data);
|
|
|
- String channel = jsonObject.getString("pay_channel");
|
|
|
- String id = jsonObject.getString("id");
|
|
|
- orderService.notifyOrder(orderId, channel.startsWith("wx") ? PayMethod.WEIXIN : PayMethod.ALIPAY, id);
|
|
|
- }
|
|
|
+ String data = request.getParameter("data");
|
|
|
+ String sign = request.getParameter("sign");
|
|
|
+ String type = request.getParameter("type");
|
|
|
+ if ("payment.succeeded".equals(type)) {
|
|
|
+ boolean checkSign = AdapaySign.verifySign(data, sign, AdapayCore.PUBLIC_KEY);
|
|
|
+ log.info("checkSign {}", checkSign);
|
|
|
+ if (checkSign) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(data);
|
|
|
+ String channel = jsonObject.getString("pay_channel");
|
|
|
+ String id = jsonObject.getString("id");
|
|
|
+
|
|
|
+ rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
|
|
|
+ new OrderNotifyEvent(orderId, channel.startsWith("wx") ? PayMethod.WEIXIN : PayMethod.ALIPAY, id, LocalDateTime.now()));
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|