首页 > 其他分享 >万户OA域控集成企业微信-删除离职用户

万户OA域控集成企业微信-删除离职用户

时间:2023-10-15 21:33:02浏览次数:30  
标签:Count string 微信 OA access var token 域控 new

OA与域控集成后,在域控中禁用/删除用户后,OA同步禁用,但是对接的企业微信并未删除用户。

Quartz计划任务

class DeleteWeiXinUserJob : IJob
    {
        public static string corpid = ConfigurationManager.AppSettings["corpid"];
        public static string secrect = ConfigurationManager.AppSettings["secrect"];
        public static Common.Logging.ILog logObj = Common.Logging.LogManager.GetLogger<DeleteWeiXinUserJob>();
        public async Task Execute(IJobExecutionContext context)
        {
            //string secrect = "YLCwIe_sxxxxxxxx5-KSI99eeeeeeeeeqU";
            string access_token = "";
            //string[] userids;
            List<DepAndUser> depanduserList = new List<DepAndUser>();
            List<Dep> depList = new List<Dep>();

            using (var client = new HttpClient())
            {
                var responseString = client.GetStringAsync(string.Format("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={0}&corpsecret={1}", corpid, secrect));
                responseString.Wait();
                var resultObj = JsonConvert.DeserializeObject<TokenResult>(responseString.Result);
                if (resultObj != null && resultObj.errcode == 0)
                {
                    access_token = resultObj.access_token;
                    var depanduserTask = client.GetStringAsync(string.Format("https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={0}&department_id={1}&fetch_child={2}", access_token, 1, 1));
                    depanduserTask.Wait();
                    var depanduserObj = JsonConvert.DeserializeObject<DepAndUserResult>(depanduserTask.Result);
                    if (depanduserObj != null && depanduserObj.errcode == 0)
                    {
                        depanduserList = depanduserObj.userlist;
                    }
                    //var depsTask = client.GetStringAsync(string.Format("https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={0}", access_token)); //getalldep(access_token);
                    //var depListResult = JsonConvert.DeserializeObject<DepResult>(depsTask.Result);
                    //if (depListResult != null && depListResult.department.Count() > 0)
                    //{
                    //    depList.AddRange(depListResult.department);
                    //}
                }
            }
            List<string> needDeleteUserList = new List<string>();
            var oauserlist = getoauser();
            //Console.WriteLine("OA Active User Number :" + oauserlist.Count);
            logObj.Debug("OA Active User Number :" + oauserlist.Count);
            if(oauserlist == null || oauserlist.Count == 0)
            {
                logObj.Debug("No OA User Return.");
                return;
            }
            foreach (var user in depanduserList)
            {
                if (false == oauserlist.Contains(user.userid))
                {
                    needDeleteUserList.Add(user.userid);
                }
            }
            //userids = needDeleteUserList.ToArray();
            var deleteArray = new List<string>();
            logObj.Debug("WeiXin need Delete User Number :" + needDeleteUserList.Count);
            int count = 0;
            for (int i = 0; i < needDeleteUserList.Count; i++)
            {
                deleteArray.Add(needDeleteUserList[i]);
                if ((i + 1) % 20 == 0)
                {
                    count += deleteArray.Count;
                    deleteWeixinUser(deleteArray.ToArray(), access_token);
                    deleteArray.Clear();
                }
            }
            //收尾
            if (deleteArray.Count > 0)
            {
                count += deleteArray.Count;
                deleteWeixinUser(deleteArray.ToArray(), access_token);
                deleteArray.Clear();
            }
            logObj.Debug("WeiXin Delete User Number :" + count);
            //Console.ReadLine();
        }
//查询OA中活动用户
        private static List<string> getoauser()
        {
            List<string> oauseridList = new List<string>();
            string sql = @"select a.emp_id, a.empname,c.orgname from org_employee a 
LEFT JOIN org_organization_user b on a.emp_id = b.emp_id 
left join org_organization c on b.org_id = c.org_id
where a.userisactive = 1 and a.userisdeleted = 0 and a.oa_enterprise_number = 1";

            sql = "select a.emp_id from org_employee a where a.userisactive = 1 and a.userisdeleted = 0 and a.oa_enterprise_number = 1";
            DbHelperOra oracleHelper = new DbHelperOra("OA");
            DataSet ds = oracleHelper.Query(sql);
            if(ds != null || ds.Tables.Count > 0)
            {
                DataTable dt = ds.Tables[0];

                foreach (DataRow row in dt.Rows)
                {
                    oauseridList.Add(row["EMP_ID"].ToString());
                }
            }
            
            return oauseridList;
        }
//删除企业微信中的用户
        private static void deleteWeixinUser(string[] userids, string access_token)
        {
            using (var client = new HttpClient())
            {
                DeleteUserList list = new DeleteUserList();
                list.useridlist = userids;
                string body = JsonConvert.SerializeObject(list);
                HttpContent content = new StringContent(body);
                var deleteResultTask = client.PostAsync(string.Format("https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete?access_token={0}", access_token), content);
                deleteResultTask.Wait();

                string deleteResultString = deleteResultTask.Result.Content.ReadAsStringAsync().Result;

                var deleteResult = JsonConvert.DeserializeObject<DeleteResult>(deleteResultString);
                logObj.Debug("Delete WeiXin User: errcode:" + deleteResult.errcode + " errmsg:" + deleteResult.errmsg);
            }
        }

标签:Count,string,微信,OA,access,var,token,域控,new
From: https://blog.51cto.com/kenji/7873425

相关文章

  • Landsat 8 Collection 2 Tier 1 calibrated top-of-atmosphere (TOA) reflectance
    Landsat8Collection2Tier1calibratedtop-of-atmosphere(TOA)reflectance.Calibrationcoefficientsareextractedfromtheimagemetadata.See Chanderetal.(2009) fordetailsontheTOAcomputation.Landsatsceneswiththehighestavailabledataqual......
  • CSS小技巧之单标签loader
    本文翻译自HowtocreateaCSS-onlyloaderwithoneelement,作者:TemaniAfif,略有删改。loader组件是网站的重要组成部分。它可以用在许多地方,我们需要显示的内容正在加载中。这样的组件需要尽可能简单,在这篇文章中我们将学习如何使用优化的代码创建不同的CSS加载器。所有......
  • 【移动开发学习】 Android Studio 编写一个简单的微信界面
    AndroidStudio简单还原微信ui目标实现3-4个tab的切换效果技术需求activity,xdm,fragment,recyclerview成果展示其中联系人界面通过recyclerview实现了可以滑动列表      仓库地址https://github.com/SmileEX/wecaht.git实现过程主要ui第......
  • 微信小程序开发1
    index.wxml文件中:根据我们前面说的官方文档学习可以大概知道,这个文件里主要涉及到的是前端代码,所以这里就比较简单了,写上你要展示的前端代码就行:在微信页面中的视图容器<view>标签来写,这个标签相当于html页面中的<div>标签,我们看看官方文档介绍主要还是负责一些位置控制啥的,理解起......
  • Nginx Load
    1.180号端口监听跳转listen80;server_namelocalhost;rewrite^(.*)$https://$host$1permanent;##跳转1.2ssl配置listen443;server_namelocalhost;sslon;ssl_session_timeout5m;ssl_protocolsTLSv1TLSv1.1TLSv1.2;ssl_ciphersALL......
  • 【科研02】【代码复现】【代码分享】TransUnet-RoadExtract 道路提取【数据预处理-ras
    目录1.数据处理dataprocess1.1.类型转换RastertoPng1.2.边缘填充Resize1.2.1.填充Resizeimage1.2.1.填充Resizelabel1.3.批量裁剪Clip1.4.波段缩减3bandsto1band1.5.筛选图像Choose1.6.转换格式Transformtonpz1.7.读取列表ReadFilesToList1.数......
  • TypeScript function overload All In One
    TypeScriptfunctionoverloadAllInOneTypeScript函数重载errors//Thisoverloadsignatureisnotcompatiblewithitsimplementationsignature.(2394)functionmyFunction(fn:(a:string)=>void,value:string):void;functionmyFunction(fn:(a:num......
  • 金蝶EAS myUploadFile任意文件上传漏洞
    漏洞简介金蝶EAS及EASCloud是金蝶软件公司推出的一套企业级应用软件套件,旨在帮助企业实现全面的管理和业务流程优化。金蝶EAS及EAScloud存在任意文件上传漏洞影响版本金蝶EAS8.0,8.1,8.2,8.5金蝶EASCloud8.6私有云,8.6公有云,8.6.1,8.8漏洞复现fofa语法:app="Kingdee-EA......
  • 关于Cortex-M3报错解决方法总结:Flash Download failed错误
    事情原因:在一次使用ST-LINKv2下载程序时,突然出现Error:FlashDownloadFailed-"Cortex-M3”这个错误,显示没有错误,没有警告。芯片型号接线都没有问题。当时就很摸不着头脑,然后上网查看了一下。原来是因为STM32F103C8T6有64kFlash和20kRAM,tm他们不属于高容量的Flash。所以我改了......
  • 万户OA SendFileCheckTemplateEdit-SQL注入
    漏洞简介万户OA存在SendFileCheckTemplateEdit-SQL注入,该漏洞为前台漏洞漏洞复现fofa语法:app="万户ezOFFICE协同管理平台"登录页面如下:POC:/defaultroot/public/iWebOfficeSign/Template/SendFileCheckTemplateEdit.jsp?RecordID=1'%20UNION%20ALL%20SELECT%20sys.fn_sqlvar......