收藏
回答

小程序码生成错误图片

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug https://api.weixin.qq.com/wxa/getwxacode?access_token="+accessToken 客户端 6.5.3 2.0.0
代码demo:


public Map getminiqrQr(String accessToken) { RestTemplate rest = new RestTemplate(); InputStream inputStream = null; OutputStream outputStream = null; try { String url = "https://api.weixin.qq.com/wxa/getwxacode?access_token="+accessToken; Mapparam = new HashMap<>(); param.put("page", "pages/index/index"); param.put("width", 430); param.put("auto_color", false); Mapline_color = new HashMap<>(); line_color.put("r", 0); line_color.put("g", 0); line_color.put("b", 0); param.put("line_color", line_color); LOG.info("调用生成微信URL接口传参:" + param); MultiValueMapheaders = new LinkedMultiValueMap<>(); HttpEntity requestEntity = new HttpEntity(param, headers); ResponseEntityentity = rest.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]); LOG.info("调用小程序生成微信永久小程序码URL接口返回结果:" + entity.getBody()); byte[] result = entity.getBody(); LOG.info(Base64.encodeBase64String(result)); inputStream = new ByteArrayInputStream(result); File file = new File("C:/Users/wangqiulin/Desktop/1.png"); if (!file.exists()){ file.createNewFile(); } outputStream = new FileOutputStream(file); int len = 0; byte[] buf = new byte[1024]; while ((len = inputStream.read(buf, 0, 1024)) != -1) { outputStream.write(buf, 0, len); } outputStream.flush(); } catch (Exception e) { LOG.error("调用小程序生成微信永久小程序码URL接口异常",e); } finally { if(inputStream != null){ try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } if(outputStream != null){ try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; }




生成如下图片信息



这种现象偶然发生,有时多次调用后就可以成功,请问是什么问题

回答关注问题邀请回答
收藏

1 个回答

  • TAO
    TAO
    2018-12-04

    {"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest hint: [TuPaIa02631511]"}


    将图片格式改成txt,出现上文报错,是token过期了

    2018-12-04
    有用
    回复
登录 后发表内容