package cn.van.business.controller.wx;


import cn.van.business.model.wx.WxMessage;
import cn.van.business.util.WxMessageConsumer;
import com.alibaba.fastjson2.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;

/**
 * @author Leo
 * @version 1.0
 * @create 2023/12/18 0018 下午 05:12V
 * @description：
 */
@Controller
@RequestMapping("/wx")
@RestController
public class WXListener {

    private static final Logger logger = LoggerFactory.getLogger(WXListener.class);

    @Autowired
    private WxMessageConsumer wxMessageConsumer;



    /**
     * {
     * "event": 10009,
     * "wxid": "wxid_kr145nk7l0an31",
     * "data": {
     * "type": "D0003",* "des": "鏀跺埌娑堟伅",
     * "data": {
     * "timeStamp": "1702951964728",
     * "fromType": 1,
     * "msgType": 1,
     * "msgSource": 0,
     * "fromWxid": "wxid_ytpc72mdoskt22",
     * "finalFromWxid": "",
     * "atWxidList": [],
     * "silence": 0,
     * "membercount": 0,
     * "signature": "v1_MllZwZMZ",
     * "msg": "785",
     * "msgBase64": "Nzg1"
     * },
     * "timestamp": "1702951964740",
     * "wxid": "wxid_kr145nk7l0an31",
     * "port": 16888,
     * "pid": 10468,
     * "flag": "7777"
     * }
     * }
     **/
    @RequestMapping("/message")
    public String message(@RequestBody String requestBody) throws Exception {
        WxMessage message = JSONObject.parseObject(requestBody, WxMessage.class);
        wxMessageConsumer.consume(message);
        return "OK";
    }
    //@RequestMapping("/test")
    //public String test(@RequestBody String requestBody) {
    //
    //    System.out.println("测试接口收到数据：");
    //    System.out.println(requestBody);
    //    return "OK";
    //}
    //@RequestMapping("/receive_msg")
    //public String receiveMsg(@RequestBody String requestBody) throws Exception {
    //
    //    System.out.println("测试接口收到数据：");
    //    System.out.println(requestBody);
    //    WxMessage message = JSONObject.parseObject(requestBody, WxMessage.class);
    //    wxMessageConsumer.consume(message);
    //
    //    return "OK";
    //}

}
