Skip to content

Commit 4b3d596

Browse files
authored
🆕 #2719 【企业微信】增加家校沟通-基础接口
1 parent a12fa55 commit 4b3d596

File tree

7 files changed

+547
-0
lines changed

7 files changed

+547
-0
lines changed

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,70 @@ public interface WxCpSchoolUserService {
135135
*/
136136
WxCpBaseResp deleteDepartment(Integer id) throws WxErrorException;
137137

138+
/**
139+
* 设置关注「学校通知」的模式
140+
* 可通过此接口修改家长关注「学校通知」的模式:“可扫码填写资料加入”或“禁止扫码填写资料加入”
141+
* <p>
142+
* 请求方式:POST(HTTPS)
143+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/set_subscribe_mode?access_token=ACCESS_TOKEN
144+
*
145+
* @param subscribeMode 关注模式, 1:可扫码填写资料加入, 2:禁止扫码填写资料加入
146+
* @return
147+
* @throws WxErrorException
148+
*/
149+
WxCpBaseResp setSubscribeMode(@NonNull Integer subscribeMode) throws WxErrorException;
150+
151+
/**
152+
* 获取关注「学校通知」的模式
153+
* 可通过此接口获取家长关注「学校通知」的模式:“可扫码填写资料加入”或“禁止扫码填写资料加入”
154+
* <p>
155+
* 请求方式:GET(HTTPS)
156+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_subscribe_mode?access_token=ACCESS_TOKEN
157+
*
158+
* @return
159+
* @throws WxErrorException
160+
*/
161+
Integer getSubscribeMode() throws WxErrorException;
162+
163+
/**
164+
* 获取外部联系人详情
165+
* 学校可通过此接口,根据外部联系人的userid(如何获取?),拉取外部联系人详情。
166+
* <p>
167+
* 请求方式:GET(HTTPS)
168+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get?access_token=ACCESS_TOKEN&external_userid=EXTERNAL_USERID
169+
*
170+
* @param externalUserId 外部联系人的userid,注意不是学校成员的帐号
171+
* @return
172+
* @throws WxErrorException
173+
*/
174+
WxCpExternalContact getExternalContact(@NonNull String externalUserId) throws WxErrorException;
175+
176+
/**
177+
* 获取可使用的家长范围
178+
* 获取可在微信「学校通知-学校应用」使用该应用的家长范围,以学生或部门列表的形式返回。应用只能给该列表下的家长发送「学校通知」。注意该范围只能由学校的系统管理员在「管理端-家校沟通-配置」配置。
179+
* <p>
180+
* 请求方式:GET(HTTPS)
181+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/agent/get_allow_scope?access_token=ACCESS_TOKEN&agentid=AGENTID
182+
*
183+
* @param agentId
184+
* @return
185+
* @throws WxErrorException
186+
*/
187+
WxCpAllowScope getAllowScope(@NonNull Integer agentId) throws WxErrorException;
188+
189+
/**
190+
* 外部联系人openid转换
191+
* 企业和服务商可通过此接口,将微信外部联系人的userid(如何获取?)转为微信openid,用于调用支付相关接口。暂不支持企业微信外部联系人(ExternalUserid为wo开头)的userid转openid。
192+
* <p>
193+
* 请求方式:POST(HTTPS)
194+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/convert_to_openid?access_token=ACCESS_TOKEN
195+
*
196+
* @param externalUserId
197+
* @return
198+
* @throws WxErrorException
199+
*/
200+
String convertToOpenId(@NonNull String externalUserId) throws WxErrorException;
201+
138202
/**
139203
* 获取部门列表
140204
* 请求方式:GET(HTTPS)
@@ -146,6 +210,17 @@ public interface WxCpSchoolUserService {
146210
*/
147211
WxCpDepartmentList listDepartment(Integer id) throws WxErrorException;
148212

213+
/**
214+
* 获取「学校通知」二维码
215+
* 学校可通过此接口获取「学校通知」二维码,家长可通过扫描此二维码关注「学校通知」并接收学校推送的消息。
216+
* 请求方式:GET(HTTPS)
217+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_subscribe_qr_code?access_token=ACCESS_TOKEN
218+
*
219+
* @return
220+
* @throws WxErrorException
221+
*/
222+
WxCpSubscribeQrCode getSubscribeQrCode() throws WxErrorException;
223+
149224
/**
150225
* 修改自动升年级的配置
151226
* 请求方式: POST(HTTPS)

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import lombok.RequiredArgsConstructor;
88
import lombok.extern.slf4j.Slf4j;
99
import me.chanjar.weixin.common.error.WxErrorException;
10+
import me.chanjar.weixin.common.util.json.GsonParser;
1011
import me.chanjar.weixin.cp.api.WxCpSchoolUserService;
1112
import me.chanjar.weixin.cp.api.WxCpService;
1213
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
@@ -15,6 +16,7 @@
1516

1617
import java.util.List;
1718

19+
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.ExternalContact.*;
1820
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.School.*;
1921

2022
/**
@@ -125,13 +127,55 @@ public WxCpBaseResp deleteDepartment(Integer id) throws WxErrorException {
125127
return WxCpBaseResp.fromJson(responseContent);
126128
}
127129

130+
@Override
131+
public WxCpBaseResp setSubscribeMode(@NonNull Integer subscribeMode) throws WxErrorException {
132+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SET_SUBSCRIBE_MODE);
133+
JsonObject jsonObject = new JsonObject();
134+
jsonObject.addProperty("subscribe_mode", subscribeMode);
135+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
136+
return WxCpBaseResp.fromJson(responseContent);
137+
}
138+
139+
@Override
140+
public Integer getSubscribeMode() throws WxErrorException {
141+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_SUBSCRIBE_MODE);
142+
String responseContent = this.cpService.get(apiUrl, null);
143+
return GsonParser.parse(responseContent).get("subscribe_mode").getAsInt();
144+
}
145+
146+
@Override
147+
public WxCpExternalContact getExternalContact(@NonNull String externalUserId) throws WxErrorException {
148+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(EXTERNAL_CONTACT_GET) + externalUserId;
149+
String responseContent = this.cpService.get(apiUrl, null);
150+
return WxCpExternalContact.fromJson(responseContent);
151+
}
152+
153+
@Override
154+
public WxCpAllowScope getAllowScope(@NonNull Integer agentId) throws WxErrorException {
155+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_ALLOW_SCOPE) + agentId;
156+
String responseContent = this.cpService.get(apiUrl, null);
157+
return WxCpAllowScope.fromJson(responseContent);
158+
}
159+
160+
@Override
161+
public String convertToOpenId(@NonNull String externalUserId) throws WxErrorException {
162+
return cpService.getExternalContactService().convertToOpenid(externalUserId);
163+
}
164+
128165
@Override
129166
public WxCpDepartmentList listDepartment(Integer id) throws WxErrorException {
130167
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_LIST) + id;
131168
String responseContent = this.cpService.get(apiUrl, null);
132169
return WxCpDepartmentList.fromJson(responseContent);
133170
}
134171

172+
@Override
173+
public WxCpSubscribeQrCode getSubscribeQrCode() throws WxErrorException {
174+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_SUBSCRIBE_QR_CODE);
175+
String responseContent = this.cpService.get(apiUrl, null);
176+
return WxCpSubscribeQrCode.fromJson(responseContent);
177+
}
178+
135179
@Override
136180
public WxCpSetUpgradeInfo setUpgradeInfo(Long upgradeTime, Integer upgradeSwitch) throws WxErrorException {
137181
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SET_UPGRADE_INFO);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package me.chanjar.weixin.cp.bean.school.user;
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.bean.WxCpBaseResp;
8+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
9+
10+
import java.io.Serializable;
11+
import java.util.List;
12+
13+
/**
14+
* 获取可使用的家长范围 返回结果.
15+
*
16+
* @author Wang_Wong
17+
*/
18+
@Data
19+
public class WxCpAllowScope extends WxCpBaseResp implements Serializable {
20+
private static final long serialVersionUID = -5028321625140879571L;
21+
22+
@SerializedName("allow_scope")
23+
private AllowScope allowScope;
24+
25+
@Setter
26+
@Getter
27+
public static class AllowScope implements Serializable {
28+
29+
@SerializedName("students")
30+
private List<Student> students;
31+
32+
@SerializedName("departments")
33+
private List<Integer> departments;
34+
35+
public static AllowScope fromJson(String json) {
36+
return WxCpGsonBuilder.create().fromJson(json, AllowScope.class);
37+
}
38+
39+
public String toJson() {
40+
return WxCpGsonBuilder.create().toJson(this);
41+
}
42+
43+
}
44+
45+
@Setter
46+
@Getter
47+
public static class Student implements Serializable {
48+
49+
@SerializedName("userid")
50+
private String userId;
51+
52+
}
53+
54+
public static WxCpAllowScope fromJson(String json) {
55+
return WxCpGsonBuilder.create().fromJson(json, WxCpAllowScope.class);
56+
}
57+
58+
public String toJson() {
59+
return WxCpGsonBuilder.create().toJson(this);
60+
}
61+
62+
}

0 commit comments

Comments
 (0)