// 官方文档连接地址:
https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.htmlString accesstoken="xxx"; Preconditions.checkArgument(!Strings.isNullOrEmpty(requestString), "request is null"); JSONObject jsonObject = JSONObject.parseObject(requestString); // page路径必须为已发布的小程序页面路径 String page="pages/shelf/shelf"; // 设置返回的图片格式 byte[] result = null; // 创建httpClient对象 HttpClient client = HttpClients.createDefault(); // 要调用的接口路径 String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+accesstoken; //声明请求方式 HttpPost post = new HttpPost(url); try { // 设置通用属性 StringEntity s = new StringEntity(jsonObject.toString(),"UTF-8"); s.setContentEncoding("UTF-8"); s.setContentType("application/json"); // 设置发送的数据(数据尽量为json格式) post.setEntity(s); post.addHeader("content-type", "application/json;charset=UTF-8"); // 获取数据 HttpResponse res = client.execute(post); // 判断网络请求的是否成功,成功的状态码为200 if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // HttpEntity为消息实体,内容是http传送的报文,获取数据 HttpEntity entity = res.getEntity(); result=EntityUtils.toByteArray(entity); } } catch (Exception e) { throw new RuntimeException(e); }finally { // 释放连接 post.releaseConnection(); } return result;
// 返回的结果为图片流 vue获取二进制流图片的方法在下篇文章