package com.qikemi.wechat.api.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.qikemi.packages.xmlJsonAndJavaBean.JavaBean2Xml;
import com.qikemi.wechat.api.constant.WechatReqMsgTypeConstant;
import com.qikemi.wechat.api.entity.message.MsgTypeBean;
import com.qikemi.wechat.api.entity.message.response.RespImageMsg;
import com.qikemi.wechat.api.entity.message.response.RespTextMsg;
import com.qikemi.wechat.api.entity.message.response.baseBean.ImageBean;

/**
 * Response Convert 2 XML 
 * Create Date: 2014年10月12日 下午9:00:55
 * Author XieXianbin<a.b@hotmail.com>
 * Source Repositories Address: <https://github.com/qikemi/open-wechat-sdk>
 */
public class ResponseConvert2XMLService {
	
	@SuppressWarnings("unused")
	private static Logger logger = Logger.getLogger(ResponseConvert2XMLService.class);

	public ResponseConvert2XMLService() {
		super();
	}

	/**
	 * get Text Message xml 
	 * @param reqTextMessage
	 * @param content
	 * @return
	 */
	public String getTextMessage(MsgTypeBean msgTypeBean, String content){
		RespTextMsg resTextMessage = new RespTextMsg();
		resTextMessage.setFromUserName(msgTypeBean.getToUserName());
		resTextMessage.setToUserName(msgTypeBean.getFromUserName());
		resTextMessage.setContent(content);
		resTextMessage.setCreateTime(System.currentTimeMillis()/1000);
		resTextMessage.setMsgType(WechatReqMsgTypeConstant.TEXT);
		return JavaBean2Xml.convert2Xml(resTextMessage, "xml");
	}
	
	/**
	 * get Image Message xml 
	 * @param msgTypeBean
	 * @param image
	 * @return
	 */
	public String getImageMessage(MsgTypeBean msgTypeBean, ImageBean imageBean){
		RespImageMsg respImageMsg = new RespImageMsg();
		respImageMsg.setFromUserName(msgTypeBean.getToUserName());
		respImageMsg.setToUserName(msgTypeBean.getFromUserName());
		
		List<ImageBean> images = new ArrayList<ImageBean>();
		images.add(imageBean);
		respImageMsg.setImageBeans(images);
		respImageMsg.setCreateTime(System.currentTimeMillis()/1000);
		respImageMsg.setMsgType(WechatReqMsgTypeConstant.IMAGE);
		return JavaBean2Xml.convert2Xml(respImageMsg, "xml");
	}
}

@@ -39,63 +39,8 @@
 %0D%0A%0D%0A
-import java.util.ArrayList;%0D%0Aimport java.util.List;%0D%0A%0D%0A
 impo
@@ -1819,90 +1819,8 @@
 %09%09%0D%0A
-%09%09List%3CImageBean%3E images = new ArrayList%3CImageBean%3E();%0D%0A%09%09images.add(imageBean);%0D%0A
 %09%09re
@@ -1849,17 +1849,20 @@
 ns(image
-s
+Bean
 );%0D%0A%09%09re

update get images message