Closed developdsdsa closed 3 years ago
问题已解决。在开放平台官网底部没有发现QQ群号。SDK源码中使用的1.6的版本,在HttpUtil类的postJson方法中使用 try(){} 时返回签名错误。使用原来的即可。
try (DataOutputStream out = new DataOutputStream(con.getOutputStream()); InputStreamReader inputStreamReader = new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(inputStreamReader)) { out.write(json.getBytes(StandardCharsets.UTF_8)); out.flush(); String inputLine; StringBuilder content = new StringBuilder(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } return content.toString(); }
public static String postJson(String interfaceUrl, Map<String, String> headers, String json) throws IOException { URL url = new URL(interfaceUrl); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/json; charset=utf-8"); con.setDoOutput(true); con.setConnectTimeout(DEFAULT_TIMEOUT); con.setReadTimeout(DEFAULT_TIMEOUT); for (Map.Entry<String, String> e : headers.entrySet()) { con.setRequestProperty(e.getKey(), e.getValue()); } try (DataOutputStream out = new DataOutputStream(con.getOutputStream()); InputStreamReader inputStreamReader = new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(inputStreamReader)) { out.write(json.getBytes(StandardCharsets.UTF_8)); out.flush(); String inputLine; StringBuilder content = new StringBuilder(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } return content.toString(); } }
原来返回S210是因为URL用了测试环境所导致
请在开放平台官网底部查看支持QQ群号,进群咨询