调getWXACodeUnlimit失败
java开发使用post请求调接口失败了,返回错误信息{“errcode”:41002,“errmsg”:“appid missing hint: [2YPCrA06382994]”},这接口也没有让传appid啊,access_token成功获取到了。有没有例子,求一个~
2 回复
我用Spring 的 RestTemplate
是这样写的
public static void getQr(String sceneStr, String accessToken) { RestTemplate rest = new RestTemplate(); InputStream inputStream = null ; OutputStream outputStream = null ; try { String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" +accessToken; Map<String,Object> param = new HashMap<String,Object>(); param.put( "scene" , sceneStr); param.put( "page" , "pages/index/index" ); param.put( "width" , 430 ); param.put( "auto_color" , false ); Map<String,Object> line_color = new HashMap<String,Object>(); line_color.put( "r" , 0 ); line_color.put( "g" , 0 ); line_color.put( "b" , 0 ); param.put( "line_color" , line_color); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); System.out.println( "参数" + param); HttpEntity requestEntity = new HttpEntity(param, headers); ResponseEntity< byte []> entity = rest.exchange(url, HttpMethod.POST, requestEntity, byte []. class , new Object[ 0 ]); byte [] result = entity.getBody(); if (result.length> 2000 ){ inputStream = new ByteArrayInputStream(result); String filePathPre = "路径" ; if (!filePathPreDir.exists()){ filePathPreDir.mkdirs(); } File file = new File(filePathPre+ "xxx.jpg" ); 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) { } finally { if (inputStream != null ){ try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } if (outputStream != null ){ try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } } |