package org.fouram.core.plugin.weixin.cp.util;

import java.util.List;

import org.fouram.core.plugin.weixin.cp.core.WXCpMessage;
import org.fouram.core.util.ConfConfig;
import org.fouram.core.util.LoggerUtil;

import com.google.common.collect.Lists;

import me.chanjar.weixin.common.api.WxConsts.KefuMsgType;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpMessage;
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
import me.chanjar.weixin.cp.bean.article.NewArticle;

/**
 * 企业微信用户工具类
 * 
 * @author Liup
 */
public class WXCpMessageUtil {

	public static void sendQuitUserMsg(String title) throws WxErrorException {
		try {
			WxCpMessage message = new WxCpMessage();
			message.setToUser(ConfConfig.getConfigString("wxCp.massage.toUser"));
			message.setMsgType(KefuMsgType.NEWS);
			NewArticle article = NewArticle.builder().title(title)
					.url(ConfConfig.getConfigString("wxCp.massage.quitUserUrl")).build();
			List<NewArticle> articles = Lists.newArrayList(article);
			message.setArticles(articles);
			WxCpMessageSendResult sendResult = WXCpMessage.service.messageSend(message);
			LoggerUtil.info(sendResult.toString());
		} catch (WxErrorException e) {
			LoggerUtil.error(e);
		}
	}

	public static void main(String[] args) throws WxErrorException {
		sendQuitUserMsg("test");
	}
}
