uot;钉钉用户的手机号:"+mobile);
//通过手机号获取该用户
SysUser sysUser = 。。。。。;
if(sysUser == null){
//不存在该用户
return WebResponse.resFail("您无权限访问", null);
}
。。。。。。
//钉钉发送免登成功消息给用户
sendMessage(accessToken, userId, userInfo.get("name").asText());
return WebResponse.resSuccess("免登成功", loginUserInfo);
}
//钉钉发送消息给用户
private void sendMessage(String token, String userId, String userName){
String messageUrl = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token="+token;
Map<String, Object> map = new HashMap<>();
map.put("agent_id", agentId.longValue());
map.put("userid_list", userId);
map.put("to_all_user", false);
String content = "用户"+userName+"在"+ DateUtil.formatDateToString(new Date(), "yyyy-MM-dd HH:mm:ss")+"时成功登录xxH5端,并进入到xxx页面";
String msg = "{\"msgtype\":\"text\",\"text\":{\"content\":"+"\""+content+"\""+"}}";
JSONObject jsonObj = JSONObject.parseObject(msg);
map.put("msg",jsonObj);
HttpUtil.doPost(messageUrl, map, "UTF-8", 20000, null);
}
}
(哈哈,那个。。。。。处的代码是实现系统认证成功后的具体操作,故这里省略)
到此钉钉免登就实现了,然后免登成功后给用户发送消息
5.工作通知消息
POST请求,请求路径:https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=ACCESS_TOKEN
请求体{agent_id、userid_list、dept_id_list、to_all_user、msg}
注意:
给同一个用户发送相同的内容,一天只能发一次;发送不同的内容,一天可以500次,
故这里我在发送的消息中添加了当前时间。
(哈哈,一些细节的东西我都写在代码的注释里了,最后发现这个小功能好像就一点点代码量)