openimsdk / open-im-sdk-uniapp

即时通讯
https://openim.io
Apache License 2.0
64 stars 71 forks source link

[BUG] GetSelfUserInfo get error 10005: error *errors.withStack not implement CodeError: not load resource: 10004 ResourceLoadNotCompleteError #21

Closed PineSongCN closed 1 month ago

PineSongCN commented 2 months ago

OpenIM Server Version

3.5.2

Operating System and CPU Architecture

macOS (ARM)

Deployment Method

Source Code Deployment

Bug Description and Steps to Reproduce

UniAPP,Android12, Api GetSelfUserInfo get error 10005:

{ "errMsg": "error *errors.withStack not implement CodeError: not load resource: 10004 ResourceLoadNotCompleteError", "errCode": 10005, "data": "" }

登录后获取用户信息报错10005.

Code:

import { getImTokenService } from "@/api/im";
import { useUserStore } from "@/store/modules/user";
import IMSDK, { IMMethods } from "openim-uniapp-polyfill";
import { getImConfig } from "../env";

const config = getImConfig();
export const initIMSDK = async () => {
  // #ifdef H5 || MP-WEIXIN
  const IMToken = uni.getStorageSync("IMToken");
  const IMUserID = uni.getStorageSync("IMUserID");
  if (IMToken && IMUserID) {
    await IMSDK.asyncApi(IMSDK.IMMethods.Login, IMSDK.uuid(), {
      userID: IMUserID,
      token: IMToken,
      platformID: config.platformID,
      wsAddr: config.wsUrl,
      apiAddr: config.apiUrl,
    });
  }
  // #endif

  // #ifdef APP-PLUS
  const path = await getDbDir();

  const flag = await IMSDK.asyncApi(IMMethods.InitSDK, IMSDK.uuid(), {
    platformID: config.platformID,
    apiAddr: config.apiUrl,
    wsAddr: config.wsUrl,
    dataDir: path, // 数据存储路径
    logLevel: 6,
    logFilePath: path,
    isLogStandardOutput: true,
    isExternalExtensions: false,
  });
  /**
   * @returns 
   * true
   */
  if (!flag) {
    // 初始化IMSDK失败!
    plus.navigator.closeSplashscreen();
    return;
  }
  // #endif

  IMSDK.subscribe(IMSDK.IMEvents.OnRecvNewMessages, (data) => {
    // 消息
    console.log("OnRecvNewMessages", data);
  });

  loginIMSDK();
};

export const loginIMSDK = async () => {
  const userStore = useUserStore();
  const userID: any = userStore.userInfo?.id;

  const token = await getImTokenService({
    platform: 5,
  });
  const loginParams = {
    userID,
    token,
    // #ifdef H5 || MP-WEIXIN
    platformID: config.platformID,
    apiAddr: config.apiUrl,
    wsAddr: config.wsUrl,
    // #endif
  };
  const loginRes = await IMSDK.asyncApi(
    IMSDK.IMMethods.Login,
    IMSDK.uuid(),
    loginParams
  );
  /**
   * @returns
   * {
          "errMsg": "",
          "errCode": 0,
          "data": ""
      }
   */
  const GetSelfUserInfo = await IMSDK.asyncApi(
    IMSDK.IMMethods.GetSelfUserInfo,
    IMSDK.uuid()
  );
  /**
   * @error
   * {
          "errMsg": "error *errors.withStack not implement CodeError: not load resource: 10004 ResourceLoadNotCompleteError",
          "errCode": 10005,
          "data": ""
      }
   */

  return loginRes;
};

export function getDbDir() {
  return new Promise((resolve, reject) => {
    plus.io.requestFileSystem(plus.io.PRIVATE_DOC, (fs) => {
      fs!.root!.getDirectory(
        "user",
        {
          create: true,
        },
        (entry) => {
          resolve(entry.fullPath);
        },
        (error) => {
          reject(error);
        }
      );
    });
  });
}

Screenshots Link

No response

lgz5689 commented 1 month ago

你是运行到安卓app吗,注意原生插件的版本,默认下载的是最新版本的,sdk版本需要和服务的版本对应