微信聊天机器人开发 java
图灵机器人提供免费接口,并且支持java语言开发,同时提供开发说明:
图灵机器人开发说明连接:
http://www.tuling123.com/openapi/cloud/access_api.jsp
实例:
/** 调用图灵机器人平台接口 */ public static void main(String[] args) throws IOException { String APIKEY = "开发者注册帐号,激活之后即可获得"; String INFO = URLEncoder.encode("北京今日天气", "utf-8"); String getURL = "http://www.tuling123.com/openapi/api?key=" + APIKEY + "&info=" + INFO; URL getUrl = new URL(getURL); HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection(); connection.connect(); // 取得输入流,并使用Reader读取 BufferedReader reader = new BufferedReader(new InputStreamReader( connection.getInputStream(), "utf-8")); StringBuffer sb = new StringBuffer(); String line = ""; while ((line = reader.readLine()) != null) { sb.append(line); } reader.close(); // 断开连接 connection.disconnect(); System.out.println(sb); }
时间: 2024-10-16 10:37:13