Skip to content

Commit b43a62c

Browse files
committed
issue #82 增加邀请成员关注接口
1 parent b921490 commit b43a62c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,18 @@ public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputS
315315
*/
316316
public void tagRemoveUsers(String tagId, List<String> userIds) throws WxErrorException;
317317

318+
/**
319+
* <pre>
320+
* 邀请成员关注
321+
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E9.82.80.E8.AF.B7.E6.88.90.E5.91.98.E5.85.B3.E6.B3.A8
322+
* </pre>
323+
* @param userId 用户的userid
324+
* @param inviteTips 推送到微信上的提示语(只有认证号可以使用)。当使用微信推送时,该字段默认为“请关注XXX企业号”,邮件邀请时,该字段无效。
325+
* @return 1:微信邀请 2.邮件邀请
326+
* @throws WxErrorException
327+
*/
328+
public int invite(String userId, String inviteTips) throws WxErrorException;
329+
318330
/**
319331
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求
320332
* @param url

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,18 @@ public String[] oauth2getUserInfo(String code) throws WxErrorException {
357357
}
358358
}
359359

360+
@Override
361+
public int invite(String userId, String inviteTips) throws WxErrorException {
362+
String url = "https://qyapi.weixin.qq.com/cgi-bin/invite/send";
363+
JsonObject jsonObject = new JsonObject();
364+
jsonObject.addProperty("userid", userId);
365+
if (StringUtils.isNotEmpty(inviteTips)) {
366+
jsonObject.addProperty("invite_tips", inviteTips);
367+
}
368+
String responseContent = execute(new SimplePostRequestExecutor(), url, jsonObject.toString());
369+
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
370+
return tmpJsonElement.getAsJsonObject().get("type").getAsInt();
371+
}
360372

361373
public String get(String url, String queryParam) throws WxErrorException {
362374
return execute(new SimpleGetRequestExecutor(), url, queryParam);

0 commit comments

Comments
 (0)