企业微信批量获取审批工单

采用定时任务,企业微信限制是每分钟不超过600次,因此我们可以设置定时任务,每分钟获取一次

HttpsClient http = new HttpsClient();
        HashMap<String, Object> json = new HashMap<>();
        HashMap<String, String> headers = new HashMap<>(3);
        String abc=http.sendGet("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=“+企业微信id+”&corpsecret="+corpsecret);//获取方法查看企业微信api
        HashMap hashMap1 = JSON.parseObject(abc, HashMap.class);
        String access_token = (String) hashMap1.get("access_token");
        String url1="https://qyapi.weixin.qq.com/cgi-bin/oa/getapprovalinfo?access_token="+access_token;
        long timestamp1 = (System.currentTimeMillis() / 1000)-60;
        long timestamp2 = System.currentTimeMillis() / 1000;
        json.put("starttime", timestamp1);
        json.put("endtime", timestamp2);
        json.put("cursor", 0);
        json.put("size", 100);
        JSONObject json1 = new JSONObject(json);
        String s = json1.toString();
        headers.put("content-type", "application/json");
        String def = http.sendPostWithJson(url1, s, headers);
        HashMap hashMap2 = JSON.parseObject(def, HashMap.class);
        List<String> result = (List<String>) hashMap2.get("sp_no_list");
        //循环从单号获取信息
        for(int i=0;i<result.size();i++) {
            HashMap<String, Object> json2 = new HashMap<>();
            json2.put("sp_no",result.get(i));
            JSONObject json3 = new JSONObject(json2);
            String s2=json3.toString();
            String url2="https://qyapi.weixin.qq.com/cgi-bin/oa/getapprovaldetail?access_token="+access_token;
            String temp = http.sendPostWithJson(url2, s2, headers);
            HashMap temp1 = JSON.parseObject(temp, HashMap.class);
            String id =(String) (((Map) ((List) ((Map) ((Map) ((Map) ((List) ((Map) ((Map) temp1.get("info")).get("apply_data")).get("contents")).get(0)).get("value")).get("selector")).get("options")).get(0)).get("key"));
            
//获取图片
            List fileId = (List) ((Map) ((Map) ((List) ((Map) ((Map) temp1.get("info")).get("apply_data")).get("contents")).get(4)).get("value")).get("files");
            for(int j=0;j<fileId.size();j++) {
                 CloseableHttpClient httpclient = HttpClients.createDefault(); 
                try {
                    String purl="https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token="+access_token+"&media_id="+((Map) fileId.get(j)).get("file_id");
                    HttpGet httpGet = new HttpGet(purl);
                    CloseableHttpResponse response = httpclient.execute(httpGet);
                    try {
                        HttpEntity entity = response.getEntity();
                        InputStream inStream = entity.getContent();
                        long name = System.currentTimeMillis() / 1000; 
                        String tt=文件夹路径;
                        FileOutputStream fw = new FileOutputStream(tt, false);             
                        int b = inStream.read();
                        while (b != -1) {
                            fw.write(b);
                            b = inStream.read();
                        }
                        fw.close();
                        EntityUtils.consume(entity);
                    } finally {
                        response.close();
                    }
                }finally {
                    httpclient.close();
                }
            }
        }
        
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值