String URL = “二维码接口地址”;
String meetingId=request.getParameter(“id”);//我自己的参数,不用管
log.info("------------------createwxaqrcode"+meetingId);
if(meetingId!=null&&meetingId.trim().length()>0){
String access_token;
InputStream is=null;
OutputStream os=null;
try {
access_token = getAccess_token();//获取token,我自己写的方法,把acess_token获取出来就行
URL = URL + “?access_token=” + access_token;
Map<String, Object> map = new HashMap<String, Object>();
map.put(“path”, “pages/index/index?meetingId=”+meetingId);
map.put(“width”, 375);
JSONObject json = new JSONObject(map);
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(URL);
post.addHeader(HTTP.CONTENT_TYPE, “application/json”);
StringEntity se;
se = new StringEntity(json.toString());
se.setContentType(“application/json”);
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, “UTF-8”));
post.setEntity(se);
StringEntity s = new StringEntity(json.toString(), “utf-8”);
s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
“application/json”));
post.setEntity(s);
HttpResponse res = client.execute(post);
if(res!=null){
HttpEntity resEntity = res.getEntity();
if (resEntity != null) {
// 获取响应输入流
is = resEntity.getContent();
response.setHeader(“Content-Type”,“application/x-msdownload”);
os=response.getOutputStream();
//os=new FileOutputStream(“D:\\test.png”);//生成图片
int count = 0;
byte[] buffer = new byte[1024 * 8];
while ((count = is.read(buffer)) != -1) {
os.write(buffer, 0, count);
os.flush();
}
os.close();
is.close();
}
}
我是直接把流发送到小程序端的,直接用image标签的 src属性读取的