微信公开课
微信公开课小程序热门讨论关于「小程序码生成错误图片」的小程序开发问题
补充:小程序码生成错误图片
展开:代码demo:publicMapgetminiqrQr(StringaccessToken){RestTemplaterest=newRestTemplate();InputStreaminputStream=null;OutputStreamoutputStream=null;try{Stringurl=https:apiweixinqqcomwxagetwxacode?access_token=+accessToken;Mapparam=newHashMap<();paramput(page,pagesindexindex);paramput(width,430);paramput(auto_color,false);Mapline_color=newHashMap<();line_colorput(r,0);line_colorput(g,0);line_colorput(b,0);paramput(line_color,line_color);LOGinfo(调用生成微信URL接口传参:+param);MultiValueMapheaders=newLinkedMultiValueMap<();HttpEntityrequestEntity=newHttpEntity(param,headers);ResponseEntityentity=restexchange(url,HttpMethodPOST,requestEntity,byte[]class,newObject[0]);LOGinfo(调用小程序生成微信永久小程序码URL接口返回结果:+entitygetBody());byte[]result=entitygetBody();LOGinfo(Base64encodeBase64String(result));inputStream=newByteArrayInputStream(result);Filefile=newFile(C:UserswangqiulinDesktop1png);if(!fileexists()){filecreateNewFile();}outputStream=newFileOutputStream(file);intlen=0;byte[]buf=newbyte[1024];while((len=inputStreamread(buf,0,1024))!=1){outputStreamwrite(buf,0,len);}outputStreamflush();}catch(Exceptione){LOGerror(调用小程序生成微信永久小程序码URL接口异常,e);}finally{if(inputStream!=null){try{inputStreamclose();}catch(IOExceptione){eprintStackTrace();}}if(outputStream!=null){try{outputStreamclose();}catch(IOExceptione){eprintStackTrace();}}}returnnull;}生成如下图片信息这种现象偶然发生,有时多次调用后就可以成功,请问是什么问题即速小程序:{errcode:40001,errmsg:invalidcredential,access_tokenisinvalidornotlatesthint:[TuPaIa02631511]}将图片格式改成txt,出现上文报错,是token过期了
更多有关「小程序码生成错误图片」的讨论可以前往微信公开课小程序参与互动哦!了解更多