package com.order.controller.notify;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

@Controller
@RequestMapping(value = "/cinemaNotify")
@Api(value = "千猪电影票通知")
public class QzCinemaNotify {

    private static final Logger log = LoggerFactory.getLogger(QzCinemaNotify.class);

    @RequestMapping(value = "/notify", method = RequestMethod.POST)
    @ApiOperation(value = "回调")
    @ResponseBody
    public void notify(@RequestBody String reqBodyStr, HttpServletRequest request, HttpServletResponse response) {
        try {

            JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class);

            log.info("============回调任务Start=============");
            log.info("尖椒订单充值-回调参数: " + dataObject);
            log.info("============回调任务End=============");


            response.setCharacterEncoding("UTF-8");
            response.setContentType("text/html;charset=utf-8");
            PrintWriter writer= response.getWriter();
            writer.write("SUCCESS");


        } catch (Exception e) {
            log.error("WechatPayController --> wechatNotify() error!", e);
        }
    }

}
