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a-person-to-person-conversation" url: "https://open.dingtalk.com/document/orgapp/the-robot-sends-ordinary-messages-in-a-person-to-person-conversation" 截止2024年6月只给企业用,第三方个人应用不支持。 机器人上架 获取鉴权token 注册机器人回调函数 OpenDingTalkStreamClientBuilder .custom() .credencial(...) .registerCallbackListener("/v1.0/im/bot/messages/get",robotMsgListener) .build() .start(); 接收消息 Stream 模式是钉钉开放平台推荐使用的事件订阅方式,使用 Stream 模式开发者无需提供公网回调地址和注册加解密密钥,使用 SDK 接入服务端Stream模式,开发者应用程序即可接收到事件内容推送。 处理消息 调用GPT MyResponse request(){ HttpURLConnection con = (HttpURLConnection)new URL("url").openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Accept","*/*"); con.setRequestProperty("Content-Type","application/json"); con.setDoOutput(true); try(BufferedWriter writer = new BufferedWriter(new BufferedWriter(con.getOutputStream(), StandardCharsets.UTF_8))){ writer.write("postUrlParams"); } int responseCode = con.getResponseCode(); if(responseCode == HttpURLConnection.HTTP_OK){ try(BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))){ String inputLine; StringBuilder response = new StringBuilder(); while((inputLine = in.readLine()) != null){ response.append(inputLine); } return JSON.parseObject(response.toString(),MyResponse.class); } } return MyResponse.error(); } 发送消息 class RobotMsgListener implements OpenDingTalkCallbackListener<JSONObject,JSONObject>{ @Override public JSONObejct execute(JSONObject req){ // 获取gpt answer // 发送消息 } }