package com.qxgmat.controller.gateway;

import com.nuliji.tools.Response;
import com.nuliji.tools.ResponseHelp;
import com.qxgmat.dto.response.MyDto;
import com.qxgmat.help.WechatHelp;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.BufferedReader;
import java.io.IOException;

@RestController
@RequestMapping("/gateway/wechat")
public class WechatController {

    @Resource
    private WechatHelp wechatHelp;


    @RequestMapping(value = "/message", method = RequestMethod.POST)
    @ApiOperation(value = "接收微信消息", httpMethod = "POST")
    public void message(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws IOException {
        BufferedReader br = request.getReader();

        String str, wholeStr = "";
        while((str = br.readLine()) != null){
            wholeStr += str;
        }
        response.getWriter().write(wechatHelp.receiveMessage(wholeStr));
    }
}
