查询用户API搜索不到用户

qingtian 1天前 54

这是请求

IMResult<PojoSearchUserRes> pojoSearchUserResIMResult = MeshAdmin.searchUser("AA", ProtoConstants.SearchUserType.SearchUserType_Name, ProtoConstants.UserType.UserType_Normal, 1);

这是返回值

http request response content: {"code":0,"msg":"success","result":{"userInfos":[],"keyword":"AA"}}

另外有这几种搜索类型

public interface SearchUserType {
        int SearchUserType_General = 0;
        int SearchUserType_Name_Mobile = 1;
        int SearchUserType_Name = 2;
        int SearchUserType_Mobile = 3;
        int SearchUserType_UserId = 4;
        int SearchUserType_Name_Mobile_UserId = 5;
        int SearchUserType_Name_Mobile_DisplayName = 100;
    }

如果我设置了某些用户的_name字段统一前缀或者_dispaly_name字段统一前缀

我现在想查出统一前缀的用户应该怎么查

最新回复 (6)
  • wfclaw 1天前
    引用 2
    你使用的搜索类型是 SearchUserType_Name (值为2),这个类型是精确匹配用户名称。

    从返回结果看,code=0 表示接口调用成功,只是没搜到匹配的用户。

    可能的原因:
    1. 没有用户的名称为精确的 AA
    2. 如果你想模糊搜索,应该使用 SearchUserType_General (值为0),这个类型会同时搜索用户名、手机号等字段

    建议尝试:


    另外确认:
    1. 你的 admin 账号有权限搜索用户
    2. 数据库中确实存在匹配的用户数据
  • qingtian 1天前
    引用 3
    IMResult<PojoSearchUserRes> pojoSearchUserResIMResult = MeshAdmin.searchUser("18220043884", ProtoConstants.SearchUserType.SearchUserType_Mobile, ProtoConstants.UserType.UserType_Normal, 1);
    这样也搜不到
    http request response content: {"code":0,"msg":"success","result":{"userInfos":[],"keyword":"18220043884"}}
  • qingtian 1天前
    引用 4
    ## 禁止搜索用户
    friend.disable_search false

    ## 禁止按照昵称搜索用户。
    friend.disable_nick_name_search false

    ## 禁止按照用户id搜索用户,默认为false。
    friend.disable_user_id_search false

    ## 禁止发送好友邀请,通过server api添加好友不受此限制(force参数需要为true)
    friend.disable_friend_request false
    从配置看 我搜索都是开启的
  • qingtian 1天前
    引用 5
    找到问题了 page是从0开始   另外测试发现只有display_name支持模糊匹配
  • wfclaw 23小时前
    引用 6
    关于searchUser搜索不到统一前缀用户的问题,这是正常的API行为限制。<br><br>searchUser API的搜索逻辑是:<br>1. SearchUserType_Name (值为2) 只搜索用户的name字段<br>2. 搜索是模糊匹配,但不是前缀匹配模式<br><br>如果你想查询统一前缀的用户,建议方案:<br><br><b>方案1:使用数据库直接查询</b><br>直接在im-server数据库查询:<br>SELECT * FROM t_user WHERE _name LIKE '前缀%'<br><br><b>方案2:维护业务层映射</b><br>在创建用户时,将前缀信息记录到你们自己的业务系统,通过业务系统查询后再调用Admin API获取用户详情。<br><br><b>方案3:使用extra字段</b><br>创建用户时,将前缀信息存入extra字段,然后使用SearchUserType_General (值为0) 进行搜索。<br><br>文档参考:https://docs.wildfirechat.cn/server/admin_api/user_api.html
  • HeavyRain 11小时前
    引用 7
    不要用meshAdmin接口,这个是给服务组网用的。现在没有查询接口,可以直接连IM服务数据库查,或者给我们提个issue等我们来加
返回