我使用的是JAVA语言,请求代码如下
@RequestMapping(value = "/dingding/send.json")
public void send(HttpServletRequest request, HttpServletResponse response, Model model) {
String accessToken = request.getParameter("access_token");
String agentid = request.getParameter("agentid");
try {
URL url = new URL("https://oapi.dingtalk.com/message/send?access_token=" + accessToken);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("Content-Type", "application/json");
connection.connect();
// POST请求
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
JSONObject obj = new JSONObject();
obj.put("agentid", agentid);
obj.put("toparty", "33461803");
obj.put("touser", "manager7432");
obj.put("msgtype", "text");
obj.put("text", new Text("测试消息"));
out.writeBytes(obj.toJSONString());
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 (Exception e) {
} finally {
}
}
参数如下:
{"agentid":"89452256","msgtype":"text","text":{"content":"测试消息"},"toparty":"33461803","touser":"manager7432"}
控制台返回参数如下:
{"errmsg":"系统繁忙","errcode":-1}
调用visible_scopes接口时传agentid时可以成功返回微应用相关信息
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。