net.mingsoft.mweixin.action.web.FileForwardAction Maven / Gradle / Ivy
package net.mingsoft.mweixin.action.web;
import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONArray;
import io.swagger.annotations.Api;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.mweixin.entity.FileEntity;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
/**
* 解决防盗链的问题
* @Author: 铭飞开源团队--huise
* @Date: 2019/6/4 15:55
*/
@Api(value = "微信素材重定向")
@Controller("fileForwardAction")
@RequestMapping("/mweixin/forward")
public class FileForwardAction {
/**
* 传入一个src 返回原图片
* @param src 图片链接
* @param response
* @param request
* @return
* @throws IOException
*/
@GetMapping(value = "/image",produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public byte[] image(String src, HttpServletResponse response, HttpServletRequest request) throws IOException {
ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
HttpUtil.download(src,outputStream,true);
return outputStream.toByteArray();
}
}