diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaAgentService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaAgentService.java new file mode 100644 index 0000000000000000000000000000000000000000..6f4fae85de97257bdc0261c5909593b5c89d2eca --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaAgentService.java @@ -0,0 +1,29 @@ +package me.chanjar.weixin.cp.api; + +import lombok.NonNull; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.cp.bean.oa.selfagent.WxCpOpenApprovalData; + +/** + * 企业微信自建应用接口. + * https://developer.work.weixin.qq.com/document/path/90269 + * + * @author Wang_Wong + * @date 2022-04-06 + */ +public interface WxCpOaAgentService { + + /** + * 查询第三方应用审批申请当前状态 + * 开发者也可主动查询审批单的当前审批状态。 + * + * 请求方式: POST(HTTPS) + * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/corp/getopenapprovaldata?access_token=ACCESS_TOKEN + * + * @param thirdNo + * @return + * @throws WxErrorException + */ + WxCpOpenApprovalData getOpenApprovalData(@NonNull String thirdNo) throws WxErrorException; + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java index 473fb3dfcbc4e1ba775fe2de853085099541aecd..529e6f06e05ded578bf2d01a6026ea2d0f28fed2 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java @@ -399,6 +399,13 @@ public interface WxCpService extends WxService { */ WxCpLivingService getLivingService(); + /** + * 获取OA 自建应用相关接口的服务类对象 + * + * @return + */ + WxCpOaAgentService getOaAgentService(); + /** * 获取会话存档相关接口的服务类对象 * diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java index cccbe8648de5f7c136713afe2252b15f988b81c1..55ddcf9e238f4de5fbff8c5f92e92e3eb188c800 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java @@ -50,6 +50,7 @@ public abstract class BaseWxCpServiceImpl implements WxCpService, RequestH private WxCpAgentService agentService = new WxCpAgentServiceImpl(this); private WxCpOaService oaService = new WxCpOaServiceImpl(this); private WxCpLivingService livingService = new WxCpLivingServiceImpl(this); + private WxCpOaAgentService oaAgentService = new WxCpOaAgentServiceImpl(this); private WxCpMsgAuditService msgAuditService = new WxCpMsgAuditServiceImpl(this); private WxCpTaskCardService taskCardService = new WxCpTaskCardServiceImpl(this); private WxCpExternalContactService externalContactService = new WxCpExternalContactServiceImpl(this); @@ -485,6 +486,11 @@ public abstract class BaseWxCpServiceImpl implements WxCpService, RequestH return livingService; } + @Override + public WxCpOaAgentService getOaAgentService() { + return oaAgentService; + } + @Override public WxCpMsgAuditService getMsgAuditService() { return msgAuditService; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaAgentServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaAgentServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..9f3d3f1676b10e2b906f956db0bc4e4f4f27939a --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaAgentServiceImpl.java @@ -0,0 +1,43 @@ +package me.chanjar.weixin.cp.api.impl; + +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.json.GsonParser; +import me.chanjar.weixin.cp.api.WxCpOaAgentService; +import me.chanjar.weixin.cp.api.WxCpService; +import me.chanjar.weixin.cp.bean.living.WxCpLivingInfo; +import me.chanjar.weixin.cp.bean.oa.selfagent.WxCpOpenApprovalData; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Living.GET_USER_ALL_LIVINGID; +import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.GET_OPEN_APPROVAL_DATA; + +/** + * 企业微信自建应用接口实现类. + * + * @author Wang_Wong + * @date 2022-04-06 + */ +@Slf4j +@RequiredArgsConstructor +public class WxCpOaAgentServiceImpl implements WxCpOaAgentService { + private final WxCpService cpService; + + @Override + public WxCpOpenApprovalData getOpenApprovalData(@NonNull String thirdNo) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("thirdNo", thirdNo); + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_OPEN_APPROVAL_DATA); + String responseContent = this.cpService.post(apiUrl, jsonObject.toString()); + return WxCpGsonBuilder.create() + .fromJson(GsonParser.parse(responseContent).get("data"), + new TypeToken() { + }.getType() + ); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/selfagent/WxCpOpenApprovalData.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/selfagent/WxCpOpenApprovalData.java new file mode 100644 index 0000000000000000000000000000000000000000..261a0f8de1cb2807e2e8fecdce88e9733fdff24f --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/selfagent/WxCpOpenApprovalData.java @@ -0,0 +1,161 @@ +package me.chanjar.weixin.cp.bean.oa.selfagent; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * 审批申请当前状态信息. + * + * @author Wang_Wong + */ +@Data +public class WxCpOpenApprovalData implements Serializable { + private static final long serialVersionUID = -5028321625140879591L; + + @SerializedName("ThirdNo") + private String thirdNo; + + @SerializedName("OpenTemplateId") + private String openTemplateId; + + @SerializedName("OpenSpName") + private String openSpName; + + @SerializedName("OpenSpstatus") + private Integer openSpstatus; + + @SerializedName("ApplyTime") + private Long applyTime; + + @SerializedName("ApplyUsername") + private String applyUserName; + + @SerializedName("ApplyUserParty") + private String applyUserParty; + + @SerializedName("ApplyUserImage") + private String applyUserImage; + + @SerializedName("ApplyUserId") + private String applyUserId; + + @SerializedName("ApprovalNodes") + private ApprovalNodes approvalNodes; + + @SerializedName("NotifyNodes") + private NotifyNodes notifyNodes; + + @SerializedName("ApproverStep") + private Integer approverStep; + + @Getter + @Setter + public static class ApprovalNodes implements Serializable { + private static final long serialVersionUID = -5696099236344075582L; + + @SerializedName("ApprovalNode") + private List approvalNode; + + } + + @Getter + @Setter + public static class ApprovalNode implements Serializable { + private static final long serialVersionUID = -5696099236344075582L; + + @SerializedName("NodeStatus") + private Integer nodeStatus; + + @SerializedName("NodeAttr") + private Integer nodeAttr; + + @SerializedName("NodeType") + private Integer nodeType; + + @SerializedName("Items") + private Items items; + + } + + @Getter + @Setter + public static class NotifyNodes implements Serializable { + private static final long serialVersionUID = -5696099236344075582L; + + @SerializedName("NotifyNode") + private List notifyNode; + + } + + @Getter + @Setter + public static class NotifyNode implements Serializable { + private static final long serialVersionUID = -5696099236344075582L; + + @SerializedName("ItemName") + private String itemName; + + @SerializedName("ItemParty") + private String itemParty; + + @SerializedName("ItemImage") + private String itemImage; + + @SerializedName("ItemUserId") + private String itemUserId; + + } + + @Getter + @Setter + public static class Items implements Serializable { + private static final long serialVersionUID = -5696099236344075582L; + + @SerializedName("Item") + private List item; + + } + + @Getter + @Setter + public static class Item implements Serializable { + private static final long serialVersionUID = -5696099236344075582L; + + @SerializedName("ItemName") + private String itemName; + + @SerializedName("ItemParty") + private String itemParty; + + @SerializedName("ItemImage") + private String itemImage; + + @SerializedName("ItemUserId") + private String itemUserId; + + @SerializedName("ItemSpeech") + private String itemSpeech; + + @SerializedName("ItemStatus") + private Integer itemStatus; + + @SerializedName("ItemOpTime") + private Long itemOpTime; + + } + + public static WxCpOpenApprovalData fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpOpenApprovalData.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index 2155b4c611bcee09190d3a55ccca7115027f732e..e80a93263eff3250fb1357014f263c7bcbdbedec 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -91,6 +91,10 @@ public interface WxCpApiPathConsts { } interface Oa { + /** + * 打卡 + * https://developer.work.weixin.qq.com/document/path/94204 + */ String GET_CORP_CHECKIN_OPTION = "/cgi-bin/checkin/getcorpcheckinoption"; String GET_CHECKIN_DATA = "/cgi-bin/checkin/getcheckindata"; String GET_CHECKIN_OPTION = "/cgi-bin/checkin/getcheckinoption"; @@ -98,12 +102,27 @@ public interface WxCpApiPathConsts { String GET_CHECKIN_MONTH_DATA = "/cgi-bin/checkin/getcheckin_monthdata"; String GET_CHECKIN_SCHEDULE_DATA = "/cgi-bin/checkin/getcheckinschedulist"; String SET_CHECKIN_SCHEDULE_DATA = "/cgi-bin/checkin/setcheckinschedulist"; + + /** + * 审批 + * https://developer.work.weixin.qq.com/document/path/91956 + */ + String COPY_TEMPLATE = "/cgi-bin/oa/approval/copytemplate"; + String GET_TEMPLATE_DETAIL = "/cgi-bin/oa/gettemplatedetail"; + String APPLY_EVENT = "/cgi-bin/oa/applyevent"; String GET_APPROVAL_INFO = "/cgi-bin/oa/getapprovalinfo"; String GET_APPROVAL_DETAIL = "/cgi-bin/oa/getapprovaldetail"; + + /** + * 公费电话 + * https://developer.work.weixin.qq.com/document/path/93662 + */ String GET_DIAL_RECORD = "/cgi-bin/dial/get_dial_record"; - String GET_TEMPLATE_DETAIL = "/cgi-bin/oa/gettemplatedetail"; - String APPLY_EVENT = "/cgi-bin/oa/applyevent"; + /** + * 日程 + * https://developer.work.weixin.qq.com/document/path/93624 + */ String CALENDAR_ADD = "/cgi-bin/oa/calendar/add"; String CALENDAR_UPDATE = "/cgi-bin/oa/calendar/update"; String CALENDAR_GET = "/cgi-bin/oa/calendar/get"; @@ -115,7 +134,11 @@ public interface WxCpApiPathConsts { String SCHEDULE_DEL = "/cgi-bin/oa/schedule/del"; String SCHEDULE_LIST = "/cgi-bin/oa/schedule/get_by_calendar"; - String COPY_TEMPLATE = "/cgi-bin/oa/approval/copytemplate"; + /** + * 审批流程引擎 + * https://developer.work.weixin.qq.com/document/path/90269 + */ + String GET_OPEN_APPROVAL_DATA = "/cgi-bin/corp/getopenapprovaldata"; } interface Living { diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpOaAgentTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpOaAgentTest.java new file mode 100644 index 0000000000000000000000000000000000000000..88d990e4f7696dda17177be689f154e37937a557 --- /dev/null +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpOaAgentTest.java @@ -0,0 +1,59 @@ +package me.chanjar.weixin.cp.api; + +import com.google.gson.reflect.TypeToken; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.json.GsonParser; +import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl; +import me.chanjar.weixin.cp.bean.oa.selfagent.WxCpOpenApprovalData; +import me.chanjar.weixin.cp.config.WxCpConfigStorage; +import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; +import org.testng.annotations.Test; + +import java.io.InputStream; + +/** + * 企业微信自建应用接口测试类. + * https://developer.work.weixin.qq.com/document/path/90269 + * + * @author Wang_Wong + * @date 2022-04-06 + */ +@Slf4j +public class WxCpOaAgentTest { + + // extends WxCpBaseResp + private static WxCpConfigStorage wxCpConfigStorage; + private static WxCpService cpService; + + @Test + public void test() throws WxErrorException { + + InputStream inputStream = ClassLoader.getSystemResourceAsStream("test-config.xml"); + WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage.fromXml(inputStream); + + wxCpConfigStorage = config; + cpService = new WxCpServiceImpl(); + cpService.setWxCpConfigStorage(config); + + /** + * Test + */ + String test = "{\"errcode\":0,\"errmsg\":\"ok\",\"data\":{\"ThirdNo\":\"thirdNoxxx\",\"OpenTemplateId\":\"1234567111\",\"OpenSpName\":\"付款\",\"OpenSpstatus\":1,\"ApplyTime\":1527837645,\"ApplyUsername\":\"jackiejjwu\",\"ApplyUserParty\":\"产品部\",\"ApplyUserImage\":\"http://www.qq.com/xxx.png\",\"ApplyUserId\":\"WuJunJie\",\"ApprovalNodes\":{\"ApprovalNode\":[{\"NodeStatus\":1,\"NodeAttr\":1,\"NodeType\":1,\"Items\":{\"Item\":[{\"ItemName\":\"chauvetxiao\",\"ItemParty\":\"产品部\",\"ItemImage\":\"http://www.qq.com/xxx.png\",\"ItemUserId\":\"XiaoWen\",\"ItemStatus\":1,\"ItemSpeech\":\"\",\"ItemOpTime\":0}]}}]},\"NotifyNodes\":{\"NotifyNode\":[{\"ItemName\":\"jinhuiguo\",\"ItemParty\":\"行政部\",\"ItemImage\":\"http://www.qq.com/xxx.png\",\"ItemUserId\":\"GuoJinHui\"}]},\"ApproverStep\":0}}"; + + final WxCpOpenApprovalData data = WxCpGsonBuilder.create() + .fromJson(GsonParser.parse(test).get("data"), + new TypeToken() { + }.getType() + ); + + log.info(data.toJson()); + + + WxCpOpenApprovalData openApprovalData = cpService.getOaAgentService().getOpenApprovalData("943225459735269376"); + log.info(openApprovalData.toJson()); + + } + +}