2020-06-24-2

        道翰天琼未来机器人接口API简介介绍             找到一款比较智能的机器人,道翰天琼未来机器人。他们的机器人很智能。需要注册之后才能接入。每天的免费量绝对够使用。大概每天可以免费3000次左右。相对还是比较划算。无论个人用还是商用,都能满足。接口申请官网地址:www.weilaitec.com  接口地址(例子): http://a239p06512.zicp.vip/Web/BuAppJava.bujqrex?apikey="+apikey+"&msg="+msg+"&ip="+ip 用户端消息内容。 String msg ="你在干嘛呀?";   apikey参数。这个apikey就是网站上申请的APIKEY apikey ="";   //客户端ip,最终用户端的唯一标识(可以是用户端的IP,或者手机设备号,或者微信号或者,qq号码等能证明身份的唯一标识就可以)   String ip ="";   //这里一定要encode转换编码。转成GBK。 msg = URLEncoder.encode(msg, "GBK"); 三个参数全部小写 msg参数就是传输过去的对话内容。 msg参数要编码成gbk,不然会乱码。 接口具体代码: package ai.nlp.jiekou.test; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import ai.nlp.util.changliang.ChangLiangZi; public class ApiTest { /** * Get请求,获得返回数据 * @param urlStr * @return */ private static String opUrl(String urlStr) { URL url = null; HttpURLConnection conn = null; InputStream is = null; ByteArrayOutputStream baos = null; try { url = new URL(urlStr); conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(5 * 10000); conn.setConnectTimeout(5 * 10000); conn.setRequestMethod("POST"); if (conn.getResponseCode() == 200) { is = conn.getInputStream(); baos = new ByteArrayOutputStream(); int len = -1; byte[] buf = new byte[128]; while ((len = is.read(buf)) != -1) { baos.write(buf, 0, len); } baos.flush(); String result = baos.toString(); return result; } else { throw new Exception("服务器连接错误!"); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (is != null) is.close(); } catch (IOException e) { e.printStackTrace(); } try { if (baos != null) baos.close(); } catch (IOException e) { e.printStackTrace(); } conn.disconnect(); } return ChangLiangZi.WU; } public static void main(String args []){ //三个参数全部小写 //msg参数就是传输过去的对话内容。 //msg参数要编码成gbk,不然会乱码。 String msg ="你在干嘛呀?"; //apikey参数。 String apikey ="UTNJK34THXK010T566ZI39VES50BLRBE8R66H5R3FOAO84J3BV"; //客户端ip,最终用户端的唯一标识(可以是用户端的IP,或者手机设备号,或者微信号或者,qq号码等能证明身份的唯一标识就可以) String ip ="127.0.0.1"; //这里一定要encode转换编码。转成GBK。 try { msg = URLEncoder.encode(msg, "GBK"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } System.out.println(opUrl("http://a239p06512.zicp.vip/Web/BuAppJava.bujqrex?apikey="+apikey+"&msg="+msg+"&ip="+ip)); } ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200624202506567.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ3ODkxNjQx,size_16,color_FFFFFF,t_70)

你可能感兴趣的:(笔记)