浙政钉调用强制组件
第一步
获取通讯录权限范围文档地址: 获取通讯录权限范围
第二步
根据组织Code查询详情文档地址: 根据组织Code查询详情
package datadockingjiande.web.controllers;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient;
import com.alibaba.xxpt.gateway.shared.client.http.PostClient;
import datadockingjiande.utils.ZZDUtil;
import lombok.extern.slf4j.Slf4j;
import org.pitaya.comm.MD5Utils;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author wcy
* @Date 2024/3/12 11:09 上午
* @Description: 浙政钉强制组件调用
*/
@Slf4j
@RestController
@RequestMapping("api/zzd/")
@Component
public class ZZDController {
private static final String DOMAINNAME = "openplatform-pro.ding.zj.gov.cn";
private static final String OWNERAPPKEY = "***";
private static final String OWNERSECREKEY = "***";
/**
* 第一步获取通讯录权限范围
* @return
*/
@RequestMapping("getScopes")
private JSONObject getScopes() {
ExecutableClient executableClient = ZZDUtil.getInstance(OWNERAPPKEY, OWNERSECREKEY, DOMAINNAME);
String api = "/auth/scopesV2";
PostClient postClient = executableClient.newPostClient(api);
postClient.addParameter("tenantId", "196729");
String apiResult = postClient.post();
log.info("第一步查询强制组件<获取通讯录权限范围>详情:{}", apiResult);
return JSONObject.parseObject(apiResult);
}
/**
* 第二步获取通讯录部门信息
* @param code 第一步返回的deptVisibleScopes
* @return
*/
@RequestMapping("getOrganizationByCode")
private JSONObject getOrganizationByCode(@RequestParam String code) {
ExecutableClient executableClient = ZZDUtil.getInstance(OWNERAPPKEY, OWNERSECREKEY, DOMAINNAME);
String api = "/mozi/organization/getOrganizationByCode";
PostClient postClient = executableClient.newPostClient(api);
postClient.addParameter("pageNo", "1");
postClient.addParameter("pageSize", "100");
postClient.addParameter("organizationCode", code);
postClient.addParameter("tenantId", "196729");
String apiResult = postClient.post();
log.info("第二步查询强制组件<获取通讯录部门信息>详情:{}", apiResult);
return JSONObject.parseObject(apiResult);
}
}
public class ZZDUtil {
private static ExecutableClient executableClient = null;
public static ExecutableClient getInstance(String appkey, String secrekey, String domainame) {
if (executableClient != null) {
return executableClient;
}
executableClient = ExecutableClient.getInstance();
executableClient.setAccessKey(appkey);
executableClient.setSecretKey(secrekey);
executableClient.setDomainName(domainame);
executableClient.setProtocal("https");
executableClient.init();
return executableClient;
}
}