package com.gxwebsoft.open.mp;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class TextHandler implements WxMpMessageHandler {

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map<String, Object> map, WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException {
        System.out.println("wxMpXmlMessage:" + wxMpXmlMessage);
        System.out.println("map:" + map);
        String content = wxMpXmlMessage.getContent();
        String responseText = "你好。";
        if (content.equals("绑定")) {
            responseText = "<a href=\"https://tower-bind.gxwebsoft.com\">点击绑定</a>";
        }
        return WxMpXmlOutMessage.TEXT()
                .fromUser(wxMpXmlMessage.getToUser())
                .toUser(wxMpXmlMessage.getFromUser())
                .content(responseText)
                .build();
    }
}
