Skip to content

Commit 0ae7a75

Browse files
committed
issue #109 企业号几个方法添加agentId参数
1 parent b648c55 commit 0ae7a75

File tree

2 files changed

+101
-4
lines changed

2 files changed

+101
-4
lines changed

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,34 +155,87 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
155155
* <pre>
156156
* 自定义菜单创建接口
157157
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口
158+
*
159+
* 注意: 这个方法使用WxCpConfigStorage里的agentId
158160
* </pre>
161+
* @see #menuCreate(String, me.chanjar.weixin.common.bean.WxMenu)
159162
*
160163
* @param menu
161164
* @throws WxErrorException
162165
*/
163166
void menuCreate(WxMenu menu) throws WxErrorException;
164167

168+
/**
169+
* <pre>
170+
* 自定义菜单创建接口
171+
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口
172+
*
173+
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
174+
* </pre>
175+
* @see #menuCreate(me.chanjar.weixin.common.bean.WxMenu)
176+
*
177+
* @param agentId 企业号应用的id
178+
* @param menu
179+
* @throws WxErrorException
180+
*/
181+
void menuCreate(String agentId, WxMenu menu) throws WxErrorException;
182+
165183
/**
166184
* <pre>
167185
* 自定义菜单删除接口
168186
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口
187+
*
188+
* 注意: 这个方法使用WxCpConfigStorage里的agentId
169189
* </pre>
190+
* @see #menuDelete(String)
170191
*
171192
* @throws WxErrorException
172193
*/
173194
void menuDelete() throws WxErrorException;
174195

196+
/**
197+
* <pre>
198+
* 自定义菜单删除接口
199+
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口
200+
*
201+
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
202+
* </pre>
203+
* @see #menuDelete()
204+
*
205+
* @param agentId 企业号应用的id
206+
* @throws WxErrorException
207+
*/
208+
void menuDelete(String agentId) throws WxErrorException;
209+
175210
/**
176211
* <pre>
177212
* 自定义菜单查询接口
178213
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单查询接口
214+
*
215+
* 注意: 这个方法使用WxCpConfigStorage里的agentId
179216
* </pre>
217+
* @see #menuGet(String)
180218
*
181219
* @return
182220
* @throws WxErrorException
183221
*/
184222
WxMenu menuGet() throws WxErrorException;
185223

224+
/**
225+
* <pre>
226+
* 自定义菜单查询接口
227+
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单查询接口
228+
*
229+
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
230+
* </pre>
231+
* @see #menuGet()
232+
*
233+
* @param agentId 企业号应用的id
234+
* @return
235+
* @throws WxErrorException
236+
*/
237+
WxMenu menuGet(String agentId) throws WxErrorException;
238+
186239
/**
187240
* <pre>
188241
* 部门管理接口 - 创建部门
@@ -364,12 +417,33 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
364417
* 用oauth2获取用户信息
365418
* http://qydev.weixin.qq.com/wiki/index.php?title=根据code获取成员信息
366419
* 因为企业号oauth2.0必须在应用设置里设置通过ICP备案的可信域名,所以无法测试,因此这个方法很可能是坏的。
420+
*
421+
* 注意: 这个方法使用WxCpConfigStorage里的agentId
367422
* </pre>
423+
* @see #oauth2getUserInfo(String, String)
424+
*
368425
* @param code
369426
* @return [userid, deviceid]
370427
*/
371428
String[] oauth2getUserInfo(String code) throws WxErrorException;
372429

430+
/**
431+
* <pre>
432+
* 用oauth2获取用户信息
433+
* http://qydev.weixin.qq.com/wiki/index.php?title=根据code获取成员信息
434+
* 因为企业号oauth2.0必须在应用设置里设置通过ICP备案的可信域名,所以无法测试,因此这个方法很可能是坏的。
435+
*
436+
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
437+
* </pre>
438+
* @see #oauth2getUserInfo(String)
439+
*
440+
* @param agentId 企业号应用的id
441+
* @param code
442+
* @return [userid, deviceid]
443+
*/
444+
String[] oauth2getUserInfo(String agentId, String code) throws WxErrorException;
445+
446+
373447
/**
374448
* 移除标签成员
375449
*

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,36 @@ public void messageSend(WxCpMessage message) throws WxErrorException {
180180
post(url, message.toJson());
181181
}
182182

183+
@Override
183184
public void menuCreate(WxMenu menu) throws WxErrorException {
185+
menuCreate(wxCpConfigStorage.getAgentId(), menu);
186+
}
187+
188+
@Override
189+
public void menuCreate(String agentId, WxMenu menu) throws WxErrorException {
184190
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid=" + wxCpConfigStorage.getAgentId();
185191
post(url, menu.toJson());
186192
}
187193

194+
@Override
188195
public void menuDelete() throws WxErrorException {
189-
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/delete?agentid=" + wxCpConfigStorage.getAgentId();
196+
menuDelete(wxCpConfigStorage.getAgentId());
197+
}
198+
199+
@Override
200+
public void menuDelete(String agentId) throws WxErrorException {
201+
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/delete?agentid=" + agentId;
190202
get(url, null);
191203
}
192204

205+
@Override
193206
public WxMenu menuGet() throws WxErrorException {
194-
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?agentid=" + wxCpConfigStorage.getAgentId();
207+
return menuGet(wxCpConfigStorage.getAgentId());
208+
}
209+
210+
@Override
211+
public WxMenu menuGet(String agentId) throws WxErrorException {
212+
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?agentid=" + agentId;
195213
try {
196214
String resultContent = get(url, null);
197215
return WxMenu.fromJson(resultContent);
@@ -427,9 +445,14 @@ public String oauth2buildAuthorizationUrl(String redirectUri, String state) {
427445

428446
@Override
429447
public String[] oauth2getUserInfo(String code) throws WxErrorException {
448+
return oauth2getUserInfo(code, wxCpConfigStorage.getAgentId());
449+
}
450+
451+
@Override
452+
public String[] oauth2getUserInfo(String agentId, String code) throws WxErrorException {
430453
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?"
431-
+ "code=" + code
432-
+ "&agendid=" + wxCpConfigStorage.getAgentId();
454+
+ "code=" + code
455+
+ "&agendid=" + agentId;
433456
String responseText = get(url, null);
434457
JsonElement je = Streams.parse(new JsonReader(new StringReader(responseText)));
435458
JsonObject jo = je.getAsJsonObject();

0 commit comments

Comments
 (0)