| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- package com.izouma.nineth.web;
- import cn.com.sandpay.cashier.sdk.CertUtil;
- import cn.com.sandpay.cashier.sdk.CryptoUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.izouma.nineth.config.GeneralProperties;
- import com.izouma.nineth.enums.PayMethod;
- import com.izouma.nineth.event.OrderNotifyEvent;
- import lombok.AllArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.codec.binary.Base64;
- import org.apache.rocketmq.spring.core.RocketMQTemplate;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.nio.charset.StandardCharsets;
- @RestController
- @RequestMapping("/sandpay")
- @Slf4j
- @AllArgsConstructor
- public class SandPayController {
- private GeneralProperties generalProperties;
- private RocketMQTemplate rocketMQTemplate;
- @PostMapping("/notify")
- public Object notifyOrder(HttpServletRequest req, HttpServletResponse resp) {
- String data = req.getParameter("data");
- String sign = req.getParameter("sign");
- // 验证签名
- boolean valid;
- try {
- valid = CryptoUtil.verifyDigitalSign(data.getBytes(StandardCharsets.UTF_8), Base64.decodeBase64(sign),
- CertUtil.getPublicKey(), "SHA1WithRSA");
- if (!valid) {
- log.error("verify sign fail.");
- log.error("签名字符串(data)为:" + data);
- log.error("签名值(sign)为:" + sign);
- } else {
- log.info("verify sign success");
- JSONObject dataJson = JSONObject.parseObject(data);
- if (dataJson != null) {
- log.info("通知业务数据为:" + JSONObject.toJSONString(dataJson, true));
- if ("000000".equals(dataJson.getJSONObject("head").getString("respCode"))) {
- JSONObject body = dataJson.getJSONObject("body");
- JSONObject extend = body.getJSONObject("extend");
- String type = extend.getString("type");
- Long id = extend.getLong("id");
- String payOrderCode = body.getString("payOrderCode");
- String orderCode = body.getString("orderCode");
- String bankserial = body.getString("bankserial");
- switch (type) {
- case "order":
- rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
- new OrderNotifyEvent(id, PayMethod.SANDPAY,
- payOrderCode, System.currentTimeMillis()));
- break;
- case "gift":
- rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
- new OrderNotifyEvent(id, PayMethod.SANDPAY, payOrderCode,
- System.currentTimeMillis(), OrderNotifyEvent.TYPE_GIFT_ORDER));
- break;
- case "mintOrder":
- rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
- new OrderNotifyEvent(id, PayMethod.SANDPAY, payOrderCode,
- System.currentTimeMillis(), OrderNotifyEvent.TYPE_MINT_ORDER));
- break;
- case "recharge":
- rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
- new OrderNotifyEvent(id, PayMethod.SANDPAY, payOrderCode,
- System.currentTimeMillis(), OrderNotifyEvent.TYPE_RECHARGE));
- break;
- case "auctionOrder":
- rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
- new OrderNotifyEvent(id, PayMethod.SANDPAY, payOrderCode,
- System.currentTimeMillis(), OrderNotifyEvent.TYPE_AUCTION_ORDER));
- case "picOrder":
- rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
- new OrderNotifyEvent(id, PayMethod.SANDPAY, payOrderCode,
- System.currentTimeMillis(), OrderNotifyEvent.TYPE_PIC));
- break;
- case "domain":
- rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
- new OrderNotifyEvent(id, PayMethod.SANDPAY, payOrderCode,
- System.currentTimeMillis(), OrderNotifyEvent.DOMAIN));
- break;
- case "ask":
- rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
- new OrderNotifyEvent(id, PayMethod.SANDPAY, payOrderCode,
- System.currentTimeMillis(), OrderNotifyEvent.TYPE_ASK));
- break;
- }
- }
- return "respCode=000000";
- } else {
- log.error("通知数据异常!!!");
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- }
|