Skip to content

Commit 56e5d6f

Browse files
0katekate0binarywang
authored andcommitted
🆕 #2579【企业微信】增加企业微信OA自建应用-审批流程引擎相关接口
1 parent 4f2360c commit 56e5d6f

File tree

7 files changed

+331
-3
lines changed

7 files changed

+331
-3
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package me.chanjar.weixin.cp.api;
2+
3+
import lombok.NonNull;
4+
import me.chanjar.weixin.common.error.WxErrorException;
5+
import me.chanjar.weixin.cp.bean.oa.selfagent.WxCpOpenApprovalData;
6+
7+
/**
8+
* 企业微信自建应用接口.
9+
* https://developer.work.weixin.qq.com/document/path/90269
10+
*
11+
* @author <a href="https://gitee.com/Wang_Wong/">Wang_Wong</a>
12+
* @date 2022-04-06
13+
*/
14+
public interface WxCpOaAgentService {
15+
16+
/**
17+
* 查询第三方应用审批申请当前状态
18+
* 开发者也可主动查询审批单的当前审批状态。
19+
*
20+
* 请求方式: POST(HTTPS)
21+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/corp/getopenapprovaldata?access_token=ACCESS_TOKEN
22+
*
23+
* @param thirdNo
24+
* @return
25+
* @throws WxErrorException
26+
*/
27+
WxCpOpenApprovalData getOpenApprovalData(@NonNull String thirdNo) throws WxErrorException;
28+
29+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,13 @@ public interface WxCpService extends WxService {
399399
*/
400400
WxCpLivingService getLivingService();
401401

402+
/**
403+
* 获取OA 自建应用相关接口的服务类对象
404+
*
405+
* @return
406+
*/
407+
WxCpOaAgentService getOaAgentService();
408+
402409
/**
403410
* 获取会话存档相关接口的服务类对象
404411
*

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
5050
private WxCpAgentService agentService = new WxCpAgentServiceImpl(this);
5151
private WxCpOaService oaService = new WxCpOaServiceImpl(this);
5252
private WxCpLivingService livingService = new WxCpLivingServiceImpl(this);
53+
private WxCpOaAgentService oaAgentService = new WxCpOaAgentServiceImpl(this);
5354
private WxCpMsgAuditService msgAuditService = new WxCpMsgAuditServiceImpl(this);
5455
private WxCpTaskCardService taskCardService = new WxCpTaskCardServiceImpl(this);
5556
private WxCpExternalContactService externalContactService = new WxCpExternalContactServiceImpl(this);
@@ -485,6 +486,11 @@ public WxCpLivingService getLivingService() {
485486
return livingService;
486487
}
487488

489+
@Override
490+
public WxCpOaAgentService getOaAgentService() {
491+
return oaAgentService;
492+
}
493+
488494
@Override
489495
public WxCpMsgAuditService getMsgAuditService() {
490496
return msgAuditService;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package me.chanjar.weixin.cp.api.impl;
2+
3+
import com.google.gson.JsonObject;
4+
import com.google.gson.reflect.TypeToken;
5+
import lombok.NonNull;
6+
import lombok.RequiredArgsConstructor;
7+
import lombok.extern.slf4j.Slf4j;
8+
import me.chanjar.weixin.common.error.WxErrorException;
9+
import me.chanjar.weixin.common.util.json.GsonParser;
10+
import me.chanjar.weixin.cp.api.WxCpOaAgentService;
11+
import me.chanjar.weixin.cp.api.WxCpService;
12+
import me.chanjar.weixin.cp.bean.living.WxCpLivingInfo;
13+
import me.chanjar.weixin.cp.bean.oa.selfagent.WxCpOpenApprovalData;
14+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
15+
16+
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Living.GET_USER_ALL_LIVINGID;
17+
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.GET_OPEN_APPROVAL_DATA;
18+
19+
/**
20+
* 企业微信自建应用接口实现类.
21+
*
22+
* @author <a href="https://gitee.com/Wang_Wong/">Wang_Wong</a>
23+
* @date 2022-04-06
24+
*/
25+
@Slf4j
26+
@RequiredArgsConstructor
27+
public class WxCpOaAgentServiceImpl implements WxCpOaAgentService {
28+
private final WxCpService cpService;
29+
30+
@Override
31+
public WxCpOpenApprovalData getOpenApprovalData(@NonNull String thirdNo) throws WxErrorException {
32+
JsonObject jsonObject = new JsonObject();
33+
jsonObject.addProperty("thirdNo", thirdNo);
34+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_OPEN_APPROVAL_DATA);
35+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
36+
return WxCpGsonBuilder.create()
37+
.fromJson(GsonParser.parse(responseContent).get("data"),
38+
new TypeToken<WxCpOpenApprovalData>() {
39+
}.getType()
40+
);
41+
}
42+
43+
}
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
package me.chanjar.weixin.cp.bean.oa.selfagent;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
8+
9+
import java.io.Serializable;
10+
import java.util.List;
11+
12+
/**
13+
* 审批申请当前状态信息.
14+
*
15+
* @author Wang_Wong
16+
*/
17+
@Data
18+
public class WxCpOpenApprovalData implements Serializable {
19+
private static final long serialVersionUID = -5028321625140879591L;
20+
21+
@SerializedName("ThirdNo")
22+
private String thirdNo;
23+
24+
@SerializedName("OpenTemplateId")
25+
private String openTemplateId;
26+
27+
@SerializedName("OpenSpName")
28+
private String openSpName;
29+
30+
@SerializedName("OpenSpstatus")
31+
private Integer openSpstatus;
32+
33+
@SerializedName("ApplyTime")
34+
private Long applyTime;
35+
36+
@SerializedName("ApplyUsername")
37+
private String applyUserName;
38+
39+
@SerializedName("ApplyUserParty")
40+
private String applyUserParty;
41+
42+
@SerializedName("ApplyUserImage")
43+
private String applyUserImage;
44+
45+
@SerializedName("ApplyUserId")
46+
private String applyUserId;
47+
48+
@SerializedName("ApprovalNodes")
49+
private ApprovalNodes approvalNodes;
50+
51+
@SerializedName("NotifyNodes")
52+
private NotifyNodes notifyNodes;
53+
54+
@SerializedName("ApproverStep")
55+
private Integer approverStep;
56+
57+
@Getter
58+
@Setter
59+
public static class ApprovalNodes implements Serializable {
60+
private static final long serialVersionUID = -5696099236344075582L;
61+
62+
@SerializedName("ApprovalNode")
63+
private List<ApprovalNode> approvalNode;
64+
65+
}
66+
67+
@Getter
68+
@Setter
69+
public static class ApprovalNode implements Serializable {
70+
private static final long serialVersionUID = -5696099236344075582L;
71+
72+
@SerializedName("NodeStatus")
73+
private Integer nodeStatus;
74+
75+
@SerializedName("NodeAttr")
76+
private Integer nodeAttr;
77+
78+
@SerializedName("NodeType")
79+
private Integer nodeType;
80+
81+
@SerializedName("Items")
82+
private Items items;
83+
84+
}
85+
86+
@Getter
87+
@Setter
88+
public static class NotifyNodes implements Serializable {
89+
private static final long serialVersionUID = -5696099236344075582L;
90+
91+
@SerializedName("NotifyNode")
92+
private List<NotifyNode> notifyNode;
93+
94+
}
95+
96+
@Getter
97+
@Setter
98+
public static class NotifyNode implements Serializable {
99+
private static final long serialVersionUID = -5696099236344075582L;
100+
101+
@SerializedName("ItemName")
102+
private String itemName;
103+
104+
@SerializedName("ItemParty")
105+
private String itemParty;
106+
107+
@SerializedName("ItemImage")
108+
private String itemImage;
109+
110+
@SerializedName("ItemUserId")
111+
private String itemUserId;
112+
113+
}
114+
115+
@Getter
116+
@Setter
117+
public static class Items implements Serializable {
118+
private static final long serialVersionUID = -5696099236344075582L;
119+
120+
@SerializedName("Item")
121+
private List<Item> item;
122+
123+
}
124+
125+
@Getter
126+
@Setter
127+
public static class Item implements Serializable {
128+
private static final long serialVersionUID = -5696099236344075582L;
129+
130+
@SerializedName("ItemName")
131+
private String itemName;
132+
133+
@SerializedName("ItemParty")
134+
private String itemParty;
135+
136+
@SerializedName("ItemImage")
137+
private String itemImage;
138+
139+
@SerializedName("ItemUserId")
140+
private String itemUserId;
141+
142+
@SerializedName("ItemSpeech")
143+
private String itemSpeech;
144+
145+
@SerializedName("ItemStatus")
146+
private Integer itemStatus;
147+
148+
@SerializedName("ItemOpTime")
149+
private Long itemOpTime;
150+
151+
}
152+
153+
public static WxCpOpenApprovalData fromJson(String json) {
154+
return WxCpGsonBuilder.create().fromJson(json, WxCpOpenApprovalData.class);
155+
}
156+
157+
public String toJson() {
158+
return WxCpGsonBuilder.create().toJson(this);
159+
}
160+
161+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,38 @@ interface Menu {
9191
}
9292

9393
interface Oa {
94+
/**
95+
* 打卡
96+
* https://developer.work.weixin.qq.com/document/path/94204
97+
*/
9498
String GET_CORP_CHECKIN_OPTION = "/cgi-bin/checkin/getcorpcheckinoption";
9599
String GET_CHECKIN_DATA = "/cgi-bin/checkin/getcheckindata";
96100
String GET_CHECKIN_OPTION = "/cgi-bin/checkin/getcheckinoption";
97101
String GET_CHECKIN_DAY_DATA = "/cgi-bin/checkin/getcheckin_daydata";
98102
String GET_CHECKIN_MONTH_DATA = "/cgi-bin/checkin/getcheckin_monthdata";
99103
String GET_CHECKIN_SCHEDULE_DATA = "/cgi-bin/checkin/getcheckinschedulist";
100104
String SET_CHECKIN_SCHEDULE_DATA = "/cgi-bin/checkin/setcheckinschedulist";
105+
106+
/**
107+
* 审批
108+
* https://developer.work.weixin.qq.com/document/path/91956
109+
*/
110+
String COPY_TEMPLATE = "/cgi-bin/oa/approval/copytemplate";
111+
String GET_TEMPLATE_DETAIL = "/cgi-bin/oa/gettemplatedetail";
112+
String APPLY_EVENT = "/cgi-bin/oa/applyevent";
101113
String GET_APPROVAL_INFO = "/cgi-bin/oa/getapprovalinfo";
102114
String GET_APPROVAL_DETAIL = "/cgi-bin/oa/getapprovaldetail";
115+
116+
/**
117+
* 公费电话
118+
* https://developer.work.weixin.qq.com/document/path/93662
119+
*/
103120
String GET_DIAL_RECORD = "/cgi-bin/dial/get_dial_record";
104-
String GET_TEMPLATE_DETAIL = "/cgi-bin/oa/gettemplatedetail";
105-
String APPLY_EVENT = "/cgi-bin/oa/applyevent";
106121

122+
/**
123+
* 日程
124+
* https://developer.work.weixin.qq.com/document/path/93624
125+
*/
107126
String CALENDAR_ADD = "/cgi-bin/oa/calendar/add";
108127
String CALENDAR_UPDATE = "/cgi-bin/oa/calendar/update";
109128
String CALENDAR_GET = "/cgi-bin/oa/calendar/get";
@@ -115,7 +134,11 @@ interface Oa {
115134
String SCHEDULE_DEL = "/cgi-bin/oa/schedule/del";
116135
String SCHEDULE_LIST = "/cgi-bin/oa/schedule/get_by_calendar";
117136

118-
String COPY_TEMPLATE = "/cgi-bin/oa/approval/copytemplate";
137+
/**
138+
* 审批流程引擎
139+
* https://developer.work.weixin.qq.com/document/path/90269
140+
*/
141+
String GET_OPEN_APPROVAL_DATA = "/cgi-bin/corp/getopenapprovaldata";
119142
}
120143

121144
interface Living {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package me.chanjar.weixin.cp.api;
2+
3+
import com.google.gson.reflect.TypeToken;
4+
import lombok.extern.slf4j.Slf4j;
5+
import me.chanjar.weixin.common.error.WxErrorException;
6+
import me.chanjar.weixin.common.util.json.GsonParser;
7+
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
8+
import me.chanjar.weixin.cp.bean.oa.selfagent.WxCpOpenApprovalData;
9+
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
10+
import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage;
11+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
12+
import org.testng.annotations.Test;
13+
14+
import java.io.InputStream;
15+
16+
/**
17+
* 企业微信自建应用接口测试类.
18+
* https://developer.work.weixin.qq.com/document/path/90269
19+
*
20+
* @author <a href="https://gitee.com/Wang_Wong/">Wang_Wong</a>
21+
* @date 2022-04-06
22+
*/
23+
@Slf4j
24+
public class WxCpOaAgentTest {
25+
26+
// extends WxCpBaseResp
27+
private static WxCpConfigStorage wxCpConfigStorage;
28+
private static WxCpService cpService;
29+
30+
@Test
31+
public void test() throws WxErrorException {
32+
33+
InputStream inputStream = ClassLoader.getSystemResourceAsStream("test-config.xml");
34+
WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage.fromXml(inputStream);
35+
36+
wxCpConfigStorage = config;
37+
cpService = new WxCpServiceImpl();
38+
cpService.setWxCpConfigStorage(config);
39+
40+
/**
41+
* Test
42+
*/
43+
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}}";
44+
45+
final WxCpOpenApprovalData data = WxCpGsonBuilder.create()
46+
.fromJson(GsonParser.parse(test).get("data"),
47+
new TypeToken<WxCpOpenApprovalData>() {
48+
}.getType()
49+
);
50+
51+
log.info(data.toJson());
52+
53+
54+
WxCpOpenApprovalData openApprovalData = cpService.getOaAgentService().getOpenApprovalData("943225459735269376");
55+
log.info(openApprovalData.toJson());
56+
57+
}
58+
59+
}

0 commit comments

Comments
 (0)