ZTO-Express / zopsdk-java

中通开放平台SDK(JAVA)
Apache License 2.0
16 stars 6 forks source link

zto.open.getRouteInfo接口返回S210,但是应用已经上线并且拥有该API调用权限 #8

Closed developdsdsa closed 3 years ago

chocotan commented 3 years ago

请在开放平台官网底部查看支持QQ群号,进群咨询

developdsdsa commented 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(); }

developdsdsa commented 3 years ago

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(); } }

developdsdsa commented 3 years ago

原来返回S210是因为URL用了测试环境所导致