# -*- coding: utf-8 -*- import dingtalk.api import json from Utils.AccessToken import access_token def userid(accesstoken): req = dingtalk.api.OapiSmartworkHrmEmployeeQueryonjobRequest( "https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/queryonjob") req.status_list = "2,3,5,-1" req.offset = 0 req.size = 50 userid_list = [] try: resp= req.getResponse(accesstoken) data_list = resp["result"]["data_list"] userid_list.extend(data_list) if resp["result"]["next_cursor"] is not None: while True: resp = req.getResponse(accesstoken) data_list = resp["result"]["data_list"] userid_list.extend(data_list) if "next_cursor" in resp["result"]: req.offset = resp["result"]["next_cursor"] else: break except Exception as e: print(e) print("钉钉用户%s个"%len(userid_list)) return userid_list if __name__ == '__main__': with open("../config.json") as f: data = json.load(f) appkey = data["appkey"] appsecret = data["appsecret"] client_id = data["client_id"] client_secret = data["client_secret"] groupId = data["groupId"] sleeptime = data["sleeptime"] userid(access_token(appkey,appsecret))