实现对接企业微信打卡记录
Sen
• 发表于:2022-07-27 18:12:32 • 更新于:2024-03-29 04:39:18
1687

需求:

对接企业微信的打卡记录到系统中;

前期准备:

先实现企业微信成员id的绑定,才能实现对应上打卡记录对应的是哪个白码账号,参考:白码账号绑定企业微信成员id,本文使用的接口请参考:https://work.weixin.qq.com/api/doc/90000/90135/90262


实现步骤:

1. 登录企业微信管理后台,在应用管理找到打卡应用,点击“API”,获取一下Secret(需要到企业微信客户端查看);

 http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621483767712_%E5%9B%BE%E7%89%871.png

 http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621483775771_2.png

2. 再到我的企业页面,复制下面的企业ID;

http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621483781706_3.png 

3. 回到白码工作台,创建一个数据表,用于存储打卡记录,字段如下,分别对应接口的多个参数;

http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621483790136_4.png 

http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621483798259_5.png 

4. 新建一个API,使用企业微信(内部应用)的模板,选择基础,填写上刚才复制的企业id和secret;

http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621483808755_6.png 

然后配置好输入输出参数,如下图所示;

http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621483812943_7.png 

5. 编写API代码,代码如下;

 

代码如下:         复制代码

async function run($input, $output, $modules = modules) {  
    const wxworkApi = $modules.wxworkApi;  
       let userlist = $input.userlist;  
       let useridlist = userlist.map(v=>v["608a51b617f01720c7525723"]);//用户表企业微信成员id字段field  
       let data = {  
        "opencheckindatatype": 3,  
        "starttime": new Date($input.start_date).getTime() / 1000,  
        "endtime": new Date($input.end_date).getTime() / 1000,  
        "useridlist": useridlist.join(',')  
       };  
       //$output.data = data;  
    let res = await wxworkApi.request({  
        method: "post",  
        url: "checkin/getcheckindata",  
           data  
       });  
    $output.checkindata = res.checkindata;  
   }

6. 新建一个功能,用于获取打卡记录并录入到系统中;

①第一步使用获取集合的步骤,获取用户列表,不需要设置筛选条件,即可获取到全部用户;

 http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621494215128_8.png

②第二步使用API的步骤,调用前面做好的API,获取打卡记录;

 http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621483846862_9.png

http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621483860077_10.png 

http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621483865587_11.png http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621492219038_12.png

 

③第三步使用编程,用于处理APi返回的打卡记录数据;

http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621492379808_13.png 

http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621492389811_14.png 

代码如下:         复制代码

async function runProcess($model = model, $plugin = plugin, $params) {  
       let list = $params.list;  
       await $model.log(list.length);  
       for (let i = 0; i < list.length; i++) {  
        let userid = list[i]["userid"];//成员id  
        let checkin_time = list[i]["checkin_time"];//打卡时间戳  
        let date = new Date(checkin_time*1000);  
        let YY = date.getFullYear();  
        let MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);  
        let DD = (date.getDate() + 1 <= 10 ? '0' + date.getDate() : date.getDate());  
        let hh = (date.getHours() + 1 <= 10 ? '0' + date.getHours() : date.getHours());  
        let mm = date.getMinutes() + 1 <= 10 ? '0' + date.getMinutes() : date.getMinutes();  
        let datestr = YY + "-" + MM + DD;//打卡日期  
        let time = hh + ":" + mm;//打卡时间  
        let user = await $plugin.data.queryData("5eb9416bb75b4176eca49a19",{  
            "608a51b617f01720c7525723":userid  
           });//找到成员id对应的用户  
        user = user.length > 0 ? user[0]._id : "";  
        await $plugin.data.saveData("608a540fdec57120cee5bb17",{  
            "608a545fdec57120cee5bb21":list[i]["exception_type"],//异常类型  
            "608a54886d8eaf20d45d65cb":list[i]["location_title"],//打卡地点title  
            "608a548019c20e20c8dc5756":datestr,  
            "608a54c06d8eaf20d45d65d1":time,  
            "608a541f17f01720c752574f":user,  
            "608a545717f01720c7525756":list[i]["checkin_type"]//打卡类型  
           });  
       }  
   }

7. 最后将该功能发布到线上,再创建一个定时任务来调用这个功能,周期设定如下图;

http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621494031091_15.png 

实现效果:

http://pan.bnocode.com/project/5ebb991f975bfe569224be3e/attachment/20210520/1621494043522_16.png 


本文是否对您有帮助?
有帮助
没帮助
您是否遇到了以下问题?
内容过期或不准确
缺少场景、事例
链接有误
太简单,步骤待完善
其他
提交反馈
如需获取即时帮助,请联系
小助理
微信扫码添加小助理
让你的想法快速变成软件吧~
联系我们
售前咨询电话
020-88520693
意见箱 · 建议反馈
您的宝贵建议,使白码更完美!
微信扫码添加白码小助理
返回顶部