package cn.hmsoft.weixin.request;

import cn.hmsoft.weixin.entity.response.MaterialResponseJson;
import cn.hmsoft.weixin.entity.response.WxResponseJson;

/*************************
 * @note 获取一个多媒体文件
 * @author revisit@126.com
 * @Company: www.hmsoft.cn
 * @create 2017-05-09 00:28:09
 * @version 4.0.0
 */
public class MaterialGetRequest extends AbstractRequest<WxResponseJson, WxResponseJson, MaterialResponseJson> {

	private final static String url = "https://api.weixin.qq.com/cgi-bin/material/get_material?";
	// private final static String UPDATE_SQL = "update WX_MATERIAL set local_file_id=? where media_id=?";

	/****************************
	 * @param media_id
	 *            多媒体文件编号
	 */
	public MaterialGetRequest(String media_id) {
		this.requestEntity = new MaterialResponseJson();
		this.requestEntity.setMedia_id(media_id);
	}

	@Override
	protected String makeUrl() {
		this.method = "POST";
		return url + "access_token=" + this.wxDefine.getApp_accesstoken();
	}

	@Override
	protected String receiveMessage() {
//		String file_name = this.getDownloadFileName();
//		if (StringHelper.isEmpty(file_name)) {
//			return super.receiveMessage();
//		}
//		File file = new File(FrameParamUtil.getFrameUploadFilePath() + this.getDownloadFileName());
//		int size = 0;
//		try {
//			size = this.receiveAsFile(new FileOutputStream(file));
//		} catch (Exception e) {
//
//		}
//		if (size == 0)
//			throw new BusinessException("未获取到文件，请检查");
//		FrameFile frameFile = FrameFileService.addFrameFile(file, size);
//		SpringHelper.AppGobalDao.insert(frameFile);
//		SpringHelper.AppGobalDao.updateBySql(UPDATE_SQL, frameFile.getFile_id(), this.requestEntity.getMedia_id());
//
//		this.jsonEntity = new WxResponseJson();
		return null;
	}
}
