package com.iamberry.wechat.handles.wechat.config;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.iamberry.wechat.filters.WechatFilter;
import net.sf.json.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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.iamberry.wechat.face.wechat.ConfigService;
import com.iamberry.wechat.tools.NameUtils;
/**
 * @company	深圳爱贝源科技有限公司
 * @website www.iamberry.com
 * @author 	献
 * @tel		18271840547
 * @date	2016年11月3日
 * @explain	分享的业务需求
 */
@Controller
@RequestMapping("/config")
public class ConfigHandler {

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

	@Autowired
	private ConfigService configService;
	public void setConfigService(ConfigService configService) {
		this.configService = configService;
	}
	
	@RequestMapping(value="/get", method=RequestMethod.GET)
	public void getConfig(HttpServletRequest request, HttpServletResponse response) throws IOException{
		// 如果数据不为空,拼装数据
		String appid = NameUtils.appId, url = request.getParameter("url");
		if(appid ==null || url ==null){
			return;
		}
		// 拼装数据
		JSONObject json = configService.selectConfig(appid, url);
		if(json == null){
			return;
		}
		response.getWriter().write(json.toString());
		response.getWriter().close();
	}
}
