Comprehensive Java SDK for WeChat Official Account development with complete API coverage for user management, messaging, materials, menus, and WeChat platform features.
—
Comprehensive user information management, tagging, and blacklist operations for WeChat Official Account users.
interface WxMpUserService {
// Basic user information
WxMpUser userInfo(String openid) throws WxErrorException;
WxMpUser userInfo(String openid, String lang) throws WxErrorException;
List<WxMpUser> userInfoList(List<String> openids) throws WxErrorException;
List<WxMpUser> userInfoList(List<String> openids, String lang) throws WxErrorException;
// User list management
WxMpUserList userList(String nextOpenid) throws WxErrorException;
// User remark management
void userUpdateRemark(String openid, String remark) throws WxErrorException;
// OpenID migration for account changes
WxMpChangeOpenidResult changeOpenid(String fromAppid, List<String> openidList) throws WxErrorException;
}interface WxMpUserTagService {
// Tag management
WxUserTag tagCreate(String name) throws WxErrorException;
List<WxUserTag> tagGet() throws WxErrorException;
Boolean tagUpdate(Long id, String name) throws WxErrorException;
Boolean tagDelete(Long id) throws WxErrorException;
// User-tag relationships
WxTagListUser tagListUser(Long tagid, String nextOpenid) throws WxErrorException;
Boolean batchTagging(Long tagid, String[] openidList) throws WxErrorException;
Boolean batchUntagging(Long tagid, String[] openidList) throws WxErrorException;
List<Long> userTagList(String openid) throws WxErrorException;
}interface WxMpUserBlacklistService {
// Blacklist management
WxMpUserBlacklistGetResult getBlacklist(String nextOpenid) throws WxErrorException;
void pushToBlacklist(List<String> openidList) throws WxErrorException;
void pullFromBlacklist(List<String> openidList) throws WxErrorException;
}class WxMpUser implements Serializable {
private Boolean subscribe;
private String openId;
@Deprecated // WeChat stopped returning user profile info as of 2021-12-27
private String nickname;
private Integer sex;
private String language;
private String city;
private String province;
private String country;
@Deprecated // WeChat stopped returning user profile info as of 2021-12-27
private String headImgUrl;
private Long subscribeTime;
private String unionId;
private String remark;
private Long groupId;
private Long[] tagIdList;
private String subscribeScene;
private Long qrScene;
private String qrSceneStr;
// Getters and setters
public Boolean getSubscribe();
public void setSubscribe(Boolean subscribe);
public String getOpenId();
public void setOpenId(String openId);
@Deprecated // WeChat stopped returning user profile info as of 2021-12-27
public String getNickname();
@Deprecated // WeChat stopped returning user profile info as of 2021-12-27
public void setNickname(String nickname);
public Integer getSex();
public void setSex(Integer sex);
public String getLanguage();
public void setLanguage(String language);
public String getCity();
public void setCity(String city);
public String getProvince();
public void setProvince(String province);
public String getCountry();
public void setCountry(String country);
@Deprecated // WeChat stopped returning user profile info as of 2021-12-27
public String getHeadImgUrl();
@Deprecated // WeChat stopped returning user profile info as of 2021-12-27
public void setHeadImgUrl(String headImgUrl);
public Long getSubscribeTime();
public void setSubscribeTime(Long subscribeTime);
public String getUnionId();
public void setUnionId(String unionId);
public String getRemark();
public void setRemark(String remark);
public Long getGroupId();
public void setGroupId(Long groupId);
public Long[] getTagIdList();
public void setTagIdList(Long[] tagIdList);
public String getSubscribeScene();
public void setSubscribeScene(String subscribeScene);
public Long getQrScene();
public void setQrScene(Long qrScene);
public String getQrSceneStr();
public void setQrSceneStr(String qrSceneStr);
}class WxMpUserList implements Serializable {
private Long total;
private Integer count;
private WxMpOpenIdList data;
private String nextOpenid;
public Long getTotal();
public void setTotal(Long total);
public Integer getCount();
public void setCount(Integer count);
public WxMpOpenIdList getData();
public void setData(WxMpOpenIdList data);
public String getNextOpenid();
public void setNextOpenid(String nextOpenid);
}
class WxMpOpenIdList implements Serializable {
private List<String> openid;
public List<String> getOpenid();
public void setOpenid(List<String> openid);
}class WxUserTag implements Serializable {
private Long id;
private String name;
private Integer count;
public Long getId();
public void setId(Long id);
public String getName();
public void setName(String name);
public Integer getCount();
public void setCount(Integer count);
}
class WxTagListUser implements Serializable {
private Integer count;
private WxMpOpenIdList data;
private String nextOpenid;
public Integer getCount();
public void setCount(Integer count);
public WxMpOpenIdList getData();
public void setData(WxMpOpenIdList data);
public String getNextOpenid();
public void setNextOpenid(String nextOpenid);
}class WxMpUserBlacklistGetResult implements Serializable {
private Integer total;
private Integer count;
private WxMpOpenIdList data;
private String nextOpenid;
public Integer getTotal();
public void setTotal(Integer total);
public Integer getCount();
public void setCount(Integer count);
public WxMpOpenIdList getData();
public void setData(WxMpOpenIdList data);
public String getNextOpenid();
public void setNextOpenid(String nextOpenid);
}class WxMpUserQuery implements Serializable {
private String nextOpenid;
private String lang;
public WxMpUserQuery();
public WxMpUserQuery(String nextOpenid);
public WxMpUserQuery(String nextOpenid, String lang);
public String getNextOpenid();
public void setNextOpenid(String nextOpenid);
public String getLang();
public void setLang(String lang);
}class WxMpChangeOpenidResult implements Serializable {
private List<WxMpChangeOpenidItem> resultList;
public List<WxMpChangeOpenidItem> getResultList();
public void setResultList(List<WxMpChangeOpenidItem> resultList);
public static class WxMpChangeOpenidItem implements Serializable {
private String oriOpenid;
private String newOpenid;
private Integer errcode;
private String errmsg;
public String getOriOpenid();
public void setOriOpenid(String oriOpenid);
public String getNewOpenid();
public void setNewOpenid(String newOpenid);
public Integer getErrcode();
public void setErrcode(Integer errcode);
public String getErrmsg();
public void setErrmsg(String errmsg);
}
}// Get single user info
WxMpUser user = wxService.getUserService().userInfo("openid123", "zh_CN");
System.out.println("User nickname: " + user.getNickname());
System.out.println("Subscribe time: " + user.getSubscribeTime());
// Get multiple users info
List<String> openids = Arrays.asList("openid1", "openid2", "openid3");
List<WxMpUser> users = wxService.getUserService().userInfoList(openids, "zh_CN");
for (WxMpUser u : users) {
System.out.println("User: " + u.getOpenId() + " - " + u.getNickname());
}// Get first page of users
WxMpUserList userList = wxService.getUserService().userList(null);
System.out.println("Total users: " + userList.getTotal());
// Get next page if available
String nextOpenid = userList.getNextOpenid();
if (nextOpenid != null && !nextOpenid.isEmpty()) {
WxMpUserList nextPage = wxService.getUserService().userList(nextOpenid);
// Process next page
}
// Get all users with pagination
List<String> allOpenids = new ArrayList<>();
String currentOpenid = null;
do {
WxMpUserList page = wxService.getUserService().userList(currentOpenid);
if (page.getData() != null && page.getData().getOpenid() != null) {
allOpenids.addAll(page.getData().getOpenid());
}
currentOpenid = page.getNextOpenid();
} while (currentOpenid != null && !currentOpenid.isEmpty());// Update user remark
wxService.getUserService().userUpdateRemark("openid123", "VIP Customer");// Create a new tag
WxUserTag newTag = wxService.getUserTagService().tagCreate("VIP Users");
Long tagId = newTag.getId();
// Get all tags
List<WxUserTag> tags = wxService.getUserTagService().tagGet();
for (WxUserTag tag : tags) {
System.out.println("Tag: " + tag.getName() + " (ID: " + tag.getId() + ")");
}
// Update tag name
wxService.getUserTagService().tagUpdate(tagId, "Premium VIP Users");
// Delete tag
wxService.getUserTagService().tagDelete(tagId);// Tag users
String[] openids = {"openid1", "openid2", "openid3"};
wxService.getUserTagService().batchTagging(tagId, openids);
// Untag users
wxService.getUserTagService().batchUntagging(tagId, openids);
// Get users with specific tag
WxTagListUser taggedUsers = wxService.getUserTagService().tagListUser(tagId, null);
System.out.println("Users with tag: " + taggedUsers.getCount());
// Get tags for a specific user
List<Long> userTags = wxService.getUserTagService().userTagList("openid123");
System.out.println("User has " + userTags.size() + " tags");// Get blacklist
WxMpUserBlacklistGetResult blacklist = wxService.getBlackListService().getBlacklist(null);
System.out.println("Blacklisted users: " + blacklist.getTotal());
// Add users to blacklist
List<String> usersToBlock = Arrays.asList("openid1", "openid2");
wxService.getBlackListService().pushToBlacklist(usersToBlock);
// Remove users from blacklist
List<String> usersToUnblock = Arrays.asList("openid1");
wxService.getBlackListService().pullFromBlacklist(usersToUnblock);
// Get all blacklisted users with pagination
List<String> allBlacklisted = new ArrayList<>();
String nextOpenid = null;
do {
WxMpUserBlacklistGetResult page = wxService.getBlackListService().getBlacklist(nextOpenid);
if (page.getData() != null && page.getData().getOpenid() != null) {
allBlacklisted.addAll(page.getData().getOpenid());
}
nextOpenid = page.getNextOpenid();
} while (nextOpenid != null && !nextOpenid.isEmpty());// Process all users in batches
String nextOpenid = null;
do {
WxMpUserList userList = wxService.getUserService().userList(nextOpenid);
if (userList.getData() != null && userList.getData().getOpenid() != null) {
List<String> openids = userList.getData().getOpenid();
// Process in smaller batches for user info
for (int i = 0; i < openids.size(); i += 100) {
int endIndex = Math.min(i + 100, openids.size());
List<String> batch = openids.subList(i, endIndex);
List<WxMpUser> users = wxService.getUserService().userInfoList(batch, "zh_CN");
// Process user information
for (WxMpUser user : users) {
if (user.getSubscribe()) {
// Process subscribed users
System.out.println("Active user: " + user.getNickname());
}
}
}
}
nextOpenid = userList.getNextOpenid();
} while (nextOpenid != null && !nextOpenid.isEmpty());The user info APIs support language parameters:
zh_CN: Simplified Chinese (default)zh_TW: Traditional Chineseen: English// Get user info in English
WxMpUser user = wxService.getUserService().userInfo("openid123", "en");User sex field values:
0: Unknown1: Male2: FemaleCommon subscribe scene values:
ADD_SCENE_SEARCH: SearchADD_SCENE_ACCOUNT_MIGRATION: Account migrationADD_SCENE_PROFILE_CARD: Profile cardADD_SCENE_QR_CODE: QR codeADD_SCENE_PROFILE_LINK: Profile linkADD_SCENE_PROFILE_ITEM: Profile itemADD_SCENE_PAID: PaidADD_SCENE_WECHAT_ADVERTISEMENT: WeChat advertisementADD_SCENE_OTHERS: OthersCommon error scenarios:
try {
WxMpUser user = wxService.getUserService().userInfo("invalid-openid");
} catch (WxErrorException e) {
if (e.getError().getErrorCode() == 40003) {
System.out.println("Invalid openid");
}
}Install with Tessl CLI
npx tessl i tessl/maven-com-github-binarywang--weixin-java-mp