4.2)用户相关API
包括如下接口:
- createUserGroup - 创建用户分组
- queryAllUserGroup - 查询所有用户分组
- queryGroupIdByOpenId - 查询某用户在哪个分组
- updateUserGroupName - 更新用户分组名字
- movingUserToNewGroup - 移动某用户到某分组
- batchMovingUserToNewGroup - 批量移动用户到某分组
- deleteUserGroup - 删除用户分组
- updateUserRemark - 更新用户备注
- getUserInfoByOpenId - 获取用户信息基本信息
- batchGetUserInfo - 批量查询用户信息
- batchGetUserOpenId - 批量查询关注者openid
- oauth2buildAuthorizationUrl - Oauth2.0 认证
- oauth2ToGetAccessToken- Oauth2.0 认证
- oauth2ToGetUserInfo- Oauth2.0 认证
1. createUserGroup 创建用户分组
try {
WxUserGroupResult result = iService.createUserGroup("组名");
System.out.println(result.getGroup().getId());
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
2. queryAllUserGroup 查询用户分组
try {
WxUserGroupResult result = iService.queryAllUserGroup();
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
3. queryGroupIdByOpenId 查询用户在哪个分组
try {
int groupId = iService.queryGroupIdByOpenId("openid");
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
4. updateUserGroupName 修改分组名
try {
//组ID,新组名
iService.updateUserGroupName(1, "new group name");
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
5. movingUserToNewGroup 移动用户在某组
try {
WxError result = iService.movingUserToNewGroup("openid", 1);
System.out.println(result.getErrcode());
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
6. batchMovingUserToNewGroup 批量移动用户在某组
List<String> openidList = new ArrayList<>();
openidList.add("openid1");
openidList.add("openid2");
try {
iService.batchMovingUserToNewGroup(openidList, 2);
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
7. deleteUserGroup 删除用户分组
try {
iService.deleteUserGroup(2);
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
8. updateUserRemark 修改用户备注
try {
iService.updateUserRemark("openid", "备注名");
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
9. getUserInfoByOpenId 获取用户基本信息
try {
WxUser user = iService.getUserInfoByOpenId(new WxUserGet("openid", WxConsts.LANG_CHINA));
System.out.println(user.toString());
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
10. batchGetUserInfo 批量获取用户信息
List<WxUserGet> list = new ArrayList<>();
WxUserGet userGet1 = new WxUserGet("openid", WxConsts.LANG_CHINA);
WxUserGet userGet2 = new WxUserGet("openid", WxConsts.LANG_CHINA);
list.add(userGet1);
list.add(userGet2);
try {
WxUserList userList = iService.batchGetUserInfo(list);
System.out.println(userList.toString());
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
11. batchGetUserOpenId 批量获取关注者openid
try {
//第一个openid之后拉取
WxUserListResult result = iService.batchGetUserOpenId("next openid");
System.out.println(result.getNext_openid());
System.out.println(result.getData());
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
12. oauth2buildAuthorizationUrl Oauth2.0 认证获取用户信息--第一步:构造URL获取Code
try {
String oauthUrl = iService.oauth2buildAuthorizationUrl("回调URL",WxConsts.OAUTH2_SCOPE_USER_INFO, "自定义携带参数");
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
13. oauth2ToGetAccessToken Oauth2.0 认证获取用户信息--第二步:拿code换token和openid
try {
WxOAuth2AccessTokenResult result = iService.oauth2ToGetAccessToken("code");
System.out.println(result.getAccess_token());
System.out.println(result.getOpenid());
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
14. oauth2ToGetUserInfo Oauth2.0 认证获取用户信息--第三步:拿token换用户信息
try {
WxUser user = iService.oauth2ToGetUserInfo("token", new WxUserGet("openid", WxConsts.LANG_CHINA));
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}