| 
					
				 | 
			
			
				@ -0,0 +1,156 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.care.util; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.xxpt.gateway.shared.client.http.GetClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.xxpt.gateway.shared.client.http.PostClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.utils.ByteToInputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.annotation.PostConstruct; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * 阿里巴巴钉钉工具类 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by yeshijie on 2022/3/23. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Component 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class DingdingUtil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final Logger logger = LoggerFactory.getLogger(DingdingUtil.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //测试 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String AppKey = "ceshiyzh-jtP6zf3cfZEqs8UmmYNra"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String AppSecret = "NbbH9viHPDNTPTuQPz2Y0Y06F88krYWTTPLv0h01"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //正式 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    private static final String AppKey = "zhyzh-r085NCVALJYmgcDc7oBVFRZj"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    private static final String AppSecret = "fH8ZVDGAmJaeF7ujwAZgCi40w0U3im9J801vBaSF"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String DomainName = "openplatform.dg-work.cn"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String tenantId = "50495309"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String gettokenApi = "/gettoken.json"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String dingtalk_app_user = "/rpc/oauth2/dingtalk_app_user.json"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String get_by_mobiles = "/mozi/employee/get_by_mobiles"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String getuserinfo_bycode = "/rpc/oauth2/getuserinfo_bycode.json"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //executableClient要单例,并且使用前要初始化,只需要初始化一次 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static ExecutableClient executableClient = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @PostConstruct 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void clientInit(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(executableClient == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            synchronized(ExecutableClient.class){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(executableClient == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    executableClient = ExecutableClient.getInstance(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    executableClient.setAccessKey(AppKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    executableClient.setSecretKey(AppSecret); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    executableClient.setDomainName(DomainName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    executableClient.setProtocal("https"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    executableClient.init(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取AccessToken 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String getAccessToken(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        GetClient getClient = executableClient.newGetClient(gettokenApi); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设置参数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        getClient.addParameter("appkey", AppKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        getClient.addParameter("appsecret", AppSecret); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //调用API 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String apiResult = getClient.get(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logger.info(apiResult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //{"success":true,"content":{"data":{"expiresIn":7200,"accessToken":"app_4197121c698246cea9ec660902324edd"},"success":true,"requestId":"276077ca16480212814976877e76c6","responseMessage":"OK","responseCode":"0","bizErrorCode":"0"},"bizErrorCode":"0"} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = JSON.parseObject(apiResult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(jsonObject.getBoolean("success")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject content = jsonObject.getJSONObject("content"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(content.getBoolean("success")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return content.getJSONObject("data").getString("accessToken"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取用户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject dingtalk_app_user(String authCode){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //调用API 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        PostClient postClient = executableClient.newPostClient(dingtalk_app_user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设置参数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        postClient.addParameter("access_token", getAccessToken()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        postClient.addParameter("auth_code", "11"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //Call API 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String apiResult = postClient.post(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logger.info(apiResult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //{"success":true,"content":{"success":false,"responseMessage":"code失效或不存在","responseCode":"240111","bizErrorCode":"MBS-B001-02-16-240111"}} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return JSON.parseObject(apiResult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 根据手机号获取员工账户id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param mobiles 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public static JSONArray get_by_mobiles(String mobiles){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //调用API 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        PostClient postClient = executableClient.newPostClient(get_by_mobiles); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设置参数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        postClient.addParameter("areaCode", "86"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //手机号码列表,逗号分隔,最多50个 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        postClient.addParameter("mobiles", mobiles); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        postClient.addParameter("tenantId", tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        postClient.addParameter("namespace", "local"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //Call API 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String apiResult = postClient.post(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logger.info(apiResult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //{"success":true,"content":{"data":[{"accountId":821685,"mobile":"15859634562","employeeCode":"GE_f27a7231e19f4b31b8f11d2859d1be07","status":0},{"accountId":821606,"mobile":"13559485270","employeeCode":"GE_10933a0f8bc949149143163cba5bb81f","status":0}],"success":true,"requestId":"2760828316480239373806874ed97b","responseMessage":"OK","responseCode":"0","bizErrorCode":"0"},"bizErrorCode":"0"} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = JSON.parseObject(apiResult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(jsonObject.getBoolean("success")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject content = jsonObject.getJSONObject("content"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(content.getBoolean("success")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return content.getJSONArray("data"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String getuserinfo_bycode(String code){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //调用API 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        PostClient postClient = executableClient.newPostClient(getuserinfo_bycode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设置参数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        postClient.addParameter("access_token", getAccessToken()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        postClient.addParameter("code", code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //Call API 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String apiResult = postClient.post(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logger.info(apiResult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        JSONObject jsonObject = JSON.parseObject(apiResult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        if(jsonObject.getBoolean("success")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            JSONObject content = jsonObject.getJSONObject("content"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            if(content.getBoolean("success")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                return content.getJSONObject("data").getString("accessToken"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    public static void main(String[] args) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        String mobiles = "13559485270,15859634562"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        System.out.println(get_by_mobiles(mobiles)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        getuserinfo_bycode("f826c1a762a54ce6abb01c74dcc3ec000c89b501"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        dingtalk_app_user("f826c1a762a54ce6abb01c74dcc3ec000c89b501"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |