解决了吗
新增永久素材,报40113错误?为啥社区没有这个错误啊?申请测试公众号利用测试公重号发布消息,报{"errcode":40113,"errmsg":"unsupported file type hint: [xxa009498677] rid: 6285f41d-0d4c84df-20472d8c"}不支持文件类型,新增永久封面图不支持?thumb //代码如下 public String testUpload(String path, String type) { File file = new File(path); //地址 //String url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"; url = url.replace("ACCESS_TOKEN", token).replace("TYPE", type); try { URL urlObj = new URL(url); HttpsURLConnection urlConnection = (HttpsURLConnection) urlObj.openConnection(); //设置属性,设置链接的信息 urlConnection.setDoInput(true); urlConnection.setDoOutput(true); urlConnection.setUseCaches(false); //设置请求头信息 urlConnection.setRequestProperty("Connection", "Keep-Alive"); urlConnection.setRequestProperty("Charset", "utf8"); //数据的边界,什么都可以,相对而言设置成随机的 String boundary = "-----" + System.nanoTime(); urlConnection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary); //获取输出流 out = urlConnection.getOutputStream(); //创建文件的输入流 InputStream inputStream = new FileInputStream(file); //第一部分,头部信息 //准备头部信息 StringBuilder sb = new StringBuilder(); sb.append("--");//post表单要求 sb.append(boundary); sb.append("\r\n"); sb.append("Content-Disposition:form-data;name=\"media\";filename=\"" + file.getName() +"\"\r\n"); sb.append("Content-Type:application/octet-stream\r\n\r\n"); System.out.println("stringBuilder is: "+ sb); out.write(sb.toString().getBytes()); //第二部分,文件内容 byte[] b= new byte[1024]; int len; while ((len = inputStream.read(b)) != -1){ out.write(b,0,len); } //第三部分,尾部信息 String foot = "\r\n--"+boundary + "--\r\n"; out.write(foot.getBytes()); //整个写完 out.flush(); out.close(); StringBuilder res = new StringBuilder(); //读取信息 InputStream ins = urlConnection.getInputStream(); while ((len = ins.read(b)) != -1){ res.append(new String(b,0,len)); } return res.toString(); } catch (Exception e) { e.printStackTrace(); } return "no"; } /** * 测试上传临时素材 */ @Test public void testUploadTmpFile(){ String path = "C:\\Users\\34743\\Desktop\\ma.jpg"; String res = testUpload(path, "thumb"); System.out.println(res); }
2022-08-31我的是花生壳https + springboot,接口方法返回值设为void,echostr用HttpServletResponse进行返回 c参考:public void checkSignature(@RequestParam String signature, @RequestParam String timestamp, @RequestParam String nonce, @RequestParam String echostr, HttpServletResponse response)
使用ngrok本地做微信公众号的服务器 在进行服务器配置时一直报错token验证失败?[图片] 而我用APIfox 取调这两个接口的时候都能得到返回 [图片] [图片] [图片]
2022-08-09