开发者社区 问答 正文

关于钉钉最近推出的自定义机器人功能

我在群里添加了个自定义机器人,但向机器人的webhook接口发消息,总是返回
{"errmsg":"系统繁忙","errcode":-1}


我发送的测试内容就是来自钉钉机器人开发说明页面的示例Demo
String postdemo = "{\n" +
                "\"msgtype\": \"text\", \n" +
                "\"text\": {\n" +
                "    \"content\": \"我就是我, 是不一样的烟火\"\n" +
                "}, \n" +
                "\"at\": {\n" +
                "    \"atMobiles\": [\n" +
                "        \"131484XXXXX\", \n" +
                "        \"135880XXXXX\"\n" +
                "    ], \n" +
                "    \"isAtAll\": false\n" +
                "}\n" +
                "}";
        
        doPost(url, postdemo);
发送的方法:
public static void doPost(String urlstr, String postString) {

        try {
            //创建连接
            URL url = new URL(urlstr);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type","application/json");
            connection.connect();

            //POST请求
            DataOutputStream out = new DataOutputStream(connection.getOutputStream());
            out.writeBytes(postString);
            out.flush();
            out.close();

            //读取响应
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String lines;
            StringBuffer sb = new StringBuffer("");
            while ((lines = reader.readLine()) != null) {
                lines = new String(lines.getBytes(), "utf-8");
                sb.append(lines);
            }
            System.out.println(sb);
            reader.close();
            // 断开连接
            connection.disconnect();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

[font="]curl工具测试,也是收到同样的返回。


到底什么地方有问题?



展开
收起
老年程序猿 2017-03-02 10:29:45 3444 分享 版权
0 条回答
写回答
取消 提交回答