CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-github-binarywang--weixin-java-mp

Comprehensive Java SDK for WeChat Official Account development with complete API coverage for user management, messaging, materials, menus, and WeChat platform features.

Pending
Overview
Eval results
Files

user-management.mddocs/

User Management

Comprehensive user information management, tagging, and blacklist operations for WeChat Official Account users.

User Information Service

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;
}

User Tag Service

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;
}

User Blacklist Service

interface WxMpUserBlacklistService {
  // Blacklist management
  WxMpUserBlacklistGetResult getBlacklist(String nextOpenid) throws WxErrorException;
  void pushToBlacklist(List<String> openidList) throws WxErrorException;
  void pullFromBlacklist(List<String> openidList) throws WxErrorException;
}

Data Models

User Information

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);
}

User List

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);
}

User Tags

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);
}

Blacklist Results

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);
}

User Query Support

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);
}

OpenID Change Result

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);
  }
}

Usage Examples

Get User Information

// 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());
}

User List Pagination

// 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 Remarks

// Update user remark
wxService.getUserService().userUpdateRemark("openid123", "VIP Customer");

Tag Management

// 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);

User-Tag Operations

// 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");

Blacklist Management

// 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());

Batch User Processing

// 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());

Language Support

The user info APIs support language parameters:

  • zh_CN: Simplified Chinese (default)
  • zh_TW: Traditional Chinese
  • en: English
// Get user info in English
WxMpUser user = wxService.getUserService().userInfo("openid123", "en");

User Sex Constants

User sex field values:

  • 0: Unknown
  • 1: Male
  • 2: Female

Subscribe Scene Values

Common subscribe scene values:

  • ADD_SCENE_SEARCH: Search
  • ADD_SCENE_ACCOUNT_MIGRATION: Account migration
  • ADD_SCENE_PROFILE_CARD: Profile card
  • ADD_SCENE_QR_CODE: QR code
  • ADD_SCENE_PROFILE_LINK: Profile link
  • ADD_SCENE_PROFILE_ITEM: Profile item
  • ADD_SCENE_PAID: Paid
  • ADD_SCENE_WECHAT_ADVERTISEMENT: WeChat advertisement
  • ADD_SCENE_OTHERS: Others

Error Handling

Common error scenarios:

  • Invalid openid: Error code 40003
  • User not subscribed: Subscribe field will be false
  • Rate limiting: Error code 45009
  • Invalid tag operations: Various error codes for tag-related failures
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

docs

advanced-services.md

index.md

material-management.md

menu-management.md

message-handling.md

service-management.md

shopping-guide.md

template-messaging.md

user-management.md

tile.json