参考:官方文档
企业可通过打卡应用Secret调用本接口,获取指定员工指定时间段内的打卡记录数据。
第三方应用可获取应用可见范围内指定员工指定日期的打卡记录数据。
请求方式:POST(HTTPS
请求地址:https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata?access_token=ACCESS_TOKEN

JAVA程序

  1. /**
  2. * opencheckindatatype 是 打卡类型。1:上下班打卡;2:外出打卡;3:全部打卡
  3. * starttime 是 获取打卡记录的开始时间。Unix时间戳
  4. * endtime 是 获取打卡记录的结束时间。Unix时间戳
  5. * useridlist 是 需要获取打卡记录的用户列表
  6. *
  7. * @return
  8. */
  9. @Override
  10. public Integer countsUpadte() {
  11. int n = 0;
  12. // 1.查询出所有用户
  13. List<WxUserlist> userlists = wxUserlistService.list(null);
  14. //请求体数据,使用hashmap封装
  15. HashMap<String, Object> hashMap = MapUtils.newHashMap();
  16. //参数:开始时间戳(秒)//7天前0:0:0的时间戳(秒)
  17. Long starttime = TjDateUtils.chooseDay(TjDateUtils.getTodayBegin(), -7).getTime() / 1000;
  18. //参数:结束时间戳,当前时间的时间戳(秒)
  19. Long endtime = System.currentTimeMillis() / 1000;
  20. // 2. 用户列表不超过100个。若用户超过100个,请分批获取
  21. for (int i = 0; i < userlists.size(); i += 100) {
  22. hashMap.clear(); //清空缓存,是用来复用的。
  23. hashMap.put("opencheckindatatype", 3);
  24. hashMap.put("starttime", starttime);
  25. hashMap.put("endtime", endtime);
  26. ArrayList<String> useridlist = ListUtils.newArrayList();
  27. //循环获取用户的id,加入list中
  28. for (int j = 0; j < 100; j++) {
  29. if (j + i < userlists.size()) {
  30. useridlist.add(userlists.get(j + i).getUserid());
  31. }
  32. }
  33. hashMap.put("useridlist", useridlist);
  34. log.info("{}:结果:{}", i, hashMap);
  35. String token = baseNumvarService.getAccessTokenBySecret(baseNumvarService.getSecretCheckin());
  36. String url = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata?access_token=" + token;
  37. //执行请求
  38. Map map = restTemplate.postForObject(url, hashMap, Map.class);
  39. if (0 == (Integer) map.get("errcode")) {
  40. //map数据结构转为java对象结构
  41. List<WxCheckin> wxCheckinList = JSON.parseArray(JSON.toJSONString(map.get("checkindata")), WxCheckin.class);
  42. log.info("返回的数据信息:*****************{}", wxCheckinList);
  43. if (wxCheckinList != null && wxCheckinList.size() > 0) {
  44. //更新打卡的数据信息
  45. for (WxCheckin wxCheckin : wxCheckinList) {
  46. wxCheckin.setId_time(wxCheckin.getUserid() + wxCheckin.getCheckin_time());
  47. saveOrUpdate(wxCheckin);
  48. n++;//记录更新了多少个记录
  49. }
  50. }
  51. }
  52. }
  53. log.info("一共更新了多少条记录:{}", n);
  54. return n;
  55. }