Java Code Examples for org.springframework.web.context.request.ServletRequestAttributes#getSessionId()

The following examples show how to use org.springframework.web.context.request.ServletRequestAttributes#getSessionId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrderChargeController.java    From seckill-rocketmq with Apache License 2.0 6 votes vote down vote up
/**
 * 平台下单接口
 * @param chargeOrderRequest
 * @return
 */
@RequestMapping(value = "charge.do", method = {RequestMethod.POST})
public @ResponseBody Result chargeOrder(@ModelAttribute ChargeOrderRequest chargeOrderRequest) {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String sessionId = attributes.getSessionId();
    // 下单前置参数校验
    if (!secKillChargeService.checkParamsBeforeSecKillCharge(chargeOrderRequest, sessionId)) {
        return Result.error(CodeMsg.PARAM_INVALID);
    }
    // 前置商品校验
    String prodId = chargeOrderRequest.getProdId();
    if (!secKillChargeService.checkProdConfigBeforeKillCharge(prodId, sessionId)) {
        return Result.error(CodeMsg.PRODUCT_NOT_EXIST);
    }
    // 前置预减库存
    if (!secKillProductConfig.preReduceProdStock(prodId)) {
        return Result.error(CodeMsg.PRODUCT_STOCK_NOT_ENOUGH);
    }
    // 秒杀订单入队
    return secKillChargeService.secKillOrderEnqueue(chargeOrderRequest, sessionId);
}
 
Example 2
Source File: OrderChargeController.java    From seckill-rocketmq with Apache License 2.0 5 votes vote down vote up
/**
 * 平台查单接口
 * @param queryOrderRequest
 * @return
 */
@RequestMapping(value = "query.do", method = {RequestMethod.GET})
public @ResponseBody String queryOrder(@ModelAttribute QueryOrderRequest queryOrderRequest) {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String sessionId = attributes.getSessionId();
    // 查询前置参数校验
    if (!secKillChargeService.checkParamsBeforeSecKillQuery(queryOrderRequest, sessionId)) {
        return JSON.toJSONString(Result.error(CodeMsg.PARAM_INVALID));
    }
    // 查询订单
    return JSON.toJSONString(secKillChargeService.queryOrder(queryOrderRequest, sessionId));
}
 
Example 3
Source File: OrderChargeController.java    From order-charge-notify with Apache License 2.0 5 votes vote down vote up
/**
 * 平台下单接口
 * @param chargeOrderRequest
 * @return
 */
@RequestMapping(value = "charge.do", method = {RequestMethod.POST})
public @ResponseBody Result chargeRequst(@RequestBody ChargeOrderRequest chargeOrderRequest) {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String sessionId = attributes.getSessionId();
    // 下单前置校验
    if (!orderChargeService.checkValidBeforeChargeOrder(chargeOrderRequest, sessionId)) {
        return new Result("20000", "FAIL", null);
    }
    return orderChargeService.sendPaymentTransactionMsg(chargeOrderRequest, sessionId);
}
 
Example 4
Source File: OrderNotifyController.java    From order-charge-notify with Apache License 2.0 5 votes vote down vote up
/**
 * 接受充值结果通知
 * @param chargeNotifyRequest
 * orderStatus 订单状态
 * channelOrderId  本平台订单
 * platOrderId 充值平台订单
 * finishTime 订单结束时间,时间戳yyyyMMddHHmmss
 */
@RequestMapping(value = "callback", method = {RequestMethod.POST})
public @ResponseBody String chargeNotify(@ModelAttribute ChargeNotifyRequest chargeNotifyRequest) {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String sessionId = attributes.getSessionId();

    if (chargeNotifyRequest == null) {
        LOGGER.info("sessionId={},通知请求参数chargeNotifyDto==null,不进行处理。", sessionId);
        return NotifyConstant.NOTIFY_RETURN_FAIL;
    }
    LOGGER.info("sessionId={},充值结果通知处理开始,请求入参:chargeNotifyRequest={}", sessionId, chargeNotifyRequest.toString());
    // 获取详细通知参数
    String orderStatus = chargeNotifyRequest.getOrder_status();
    String channelOrderId = chargeNotifyRequest.getChannel_orderid();
    String platOrderId = chargeNotifyRequest.getPlat_orderid();
    String finishTime = chargeNotifyRequest.getFinish_time();

    if (StringUtils.isBlank(orderStatus) ||
            StringUtils.isBlank(channelOrderId) ||
            StringUtils.isBlank(platOrderId) ||
            StringUtils.isBlank(finishTime)) {
        LOGGER.info("sessionId={},通知请求参数存在空值,不进行处理。", sessionId);
        return NotifyConstant.NOTIFY_RETURN_FAIL;
    }
    // 签名校验
    String originSign = chargeNotifyRequest.getSign();
    String localSign = chargeNotifyRequest.sign(privateKey);
    if (!localSign.equals(originSign)) {
        LOGGER.info("sessionId={},签名校验失败,不进行处理。originSign={},localSign={}", sessionId, originSign, localSign);
        return NotifyConstant.NOTIFY_RETURN_FAIL;
    }
    LOGGER.info("sessionId={},签名校验成功,准备进行通知处理。originSign={},localSign={}", sessionId, originSign, localSign);
    // 执行通知处理逻辑
    return orderService.doNotify(sessionId, orderStatus, channelOrderId, platOrderId, finishTime);
}